I'm trying to list user profiles' sizes on remote computers combining Invoke-Command & Get-ChildItem, but there's an issue I can't figure out :
When I launch the command locally :
PS> (gci -recurse -force "C:\Users\user1" -File -ErrorAction SilentlyContinue | Measure -Property Length -Sum
).Sum
1038027666 # THE GOOD ONE
When I launch the command locally with a RunAs :
PS> (Get-ChildItem -Recurse -Force "C:\Users\user1" -File -ErrorAction SilentlyContinue | Measure -Property Length -Sum).Sum
68008251 # REAL SIZE IS WAY BIGGER
When I launch the command remotely :
PS> Invoke-Command -ComputerName SERVER1 -ScriptBlock { (gci -recurse -force "C:\Users\user1" -File -ErrorAction SilentlyContinue | Measure -Property Length -Sum).Sum }
7341685593 # REAL SIZE IS WAY SMALLER
If I get rid of -ErrorAction locally, in both situations I only get some Access Denied (For the good one, I have Access Denied on Local Settings and Application Data, surely that's why it's the good one)
If I get rid of -ErrorAction remotely, it seems that it tries to list LocalSettings and Application Data folders, that are not used with 2016 servers and that became LINKS that are not even accessible nowadays (how would it make SUCH a difference ?), and I get hundreds of these :
While these are exactly the same commands, the values returned are so far away from each other; I don't get it.
Could not find a part of the path 'C:\Users\user1\Local Settings\Application Data\Application Data\Application Data\Application
Data\Application Data\Application Data\Application Data\Application
Data\Microsoft\Windows\...'.
+ CategoryInfo : ReadError: (C:\Users\user1...:String) [Get-ChildItem], DirectoryNotFoundException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
+ PSComputerName : SERVER1
Could someone light me up on that behavior ? How could I get the good number remotely ?
Thanks a lot