I am new to PowerShell.
I try to list all the folders in all drives except drive C in few servers ,
If I use Invoke-command (for computerName ) , I get folders from my C:\Users\userName folder only
I think the problem is you’re using $drv variable which doesn’t exist on the remote computer, because it’s not defined inside the script block of invoke-command. So when running Get-ChildItem on the remote computer, it defaults to the current path.
To tell powershell to use the $drv variable which exists on the local computer running the script, you can do this:
Get-ChildItem -Path $using:Drv
Another way would be to run all the code in the Invoke-Command script block, therefore the $drv variable would exist on the remote machine. See example: