Dead_Eyes
asked on
powershell remote variables
Can anyone tell me why the following command creates the text file but does not populate it with any data?
Invoke-Command -ComputerName server1 -ScriptBlock {Set-Variable -Name wind -Value 'C:\Windows'}
Invoke-Command -ComputerName server1 -ScriptBlock {Get-ChildItem -Path $wind -name} | Out-File -FilePath C:\test\test.txt
but the following works fine and creates the data
Invoke-Command -ComputerName server1 -ScriptBlock {Get-ChildItem -Path C:\Windows -name} | Out-File -FilePath C:\test\test.txt
Invoke-Command -ComputerName server1 -ScriptBlock {Set-Variable -Name wind -Value 'C:\Windows'}
Invoke-Command -ComputerName server1 -ScriptBlock {Get-ChildItem -Path $wind -name} | Out-File -FilePath C:\test\test.txt
but the following works fine and creates the data
Invoke-Command -ComputerName server1 -ScriptBlock {Get-ChildItem -Path C:\Windows -name} | Out-File -FilePath C:\test\test.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER