On my target computer in PowerShell I run command
$FolderSize =(Get-ChildItem "C:UsersJDoe" -force -Recurse -ErrorAction SilentlyContinue | Measure-Object length -sum).sum
and I get a value of 0.76 gb, which accurately corresponds to the compressed size of the folder on disk. However, when I try to run the command on a remote computer using
$folderSize = Invoke-Command -ComputerName "computername" {(Get-ChildItem -Path "C:UsersJDoe" -Recurse -force -ErrorAction SilentlyContinue | Measure-Object -Property Length -sum).sum}
I get a different, MUCH larger number, 17 gb.
I tried running the first command in a pssession but still get the 17gb result. I also tried using
psexec \computername powershell "(Get-ChildItem "C:UsersJDoe" -force -Recurse -ErrorAction SilentlyContinue | Measure-Object length -sum).sum"
but still get the larger number.
I don't understand why the results obtained remotely are different than the actual size of the folder when I examine it locally. At least all the remote results are consistent, which tells me they are all measuring the same thing.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…