Below PowerShell script should measure folder sizes on remote computers but apparently my $Desktop variable value is somehow ignored by Get-ChildItem and I get 0.00 MB. But when I replace $Desktop with explicit string i.e. "C:\Users\user1\Desktop" it works alright and I get e.g. 10.MB. Am I doing something wrong?
$file1="C:\computers_users.csv"
import-csv $file1 | ForEach-Object{
$Desktop = "C:\Users\$($_.user)\Desktop"
Invoke-Command -ComputerName $_.computer -ScriptBlock {
$FldSize =(Get-ChildItem $Desktop -recurse | Measure-Object -property length -sum)
"{0:N2}" -f ($FldSize.sum / 1MB) + " MB"}
}