Hello,
Why is it when I run this from my pc on a remote server i get one result (user profile sizes)
Invoke-Command -ComputerName $Server -ScriptBlock {
Write-Host " User Profiles in MB" -ForegroundColor black -BackgroundColor Yellow
$sum = 0
gci -force 'C:\Users'-ErrorAction SilentlyContinue | ? { $_ -is [io.directoryinfo] } | % {
$len = 0
gci -recurse -force $_.fullname -ErrorAction SilentlyContinue | % { $len += $_.length }
$_.fullname, '{0:N2} GB' -f ($len / 1Gb)
$sum = $sum + $len
}
"Total size of profiles",'{0:N2} GB' -f ($sum / 1Gb)
}
When I run it on the server itself
Write-Host " User Profiles in MB" -ForegroundColor black -BackgroundColor Yellow
$sum = 0
gci -force 'C:\Users'-ErrorAction SilentlyContinue | ? { $ -is [io.directoryinfo] } | % {
$len = 0
gci -recurse -force $.fullname -ErrorAction SilentlyContinue | % { $len += $.length }
$.fullname, '{0:N2} GB' -f ($len / 1Gb)
$sum = $sum + $len
}
"Total size of profiles",'{0:N2} GB' -f ($sum / 1Gb)
I get the correct result. Why is that ?