PowerShell Remoting $Using variable scope
问题 I have folder c:\test where I have three files: “file1”, “file2”, “file3” Following script: $remoteSession = New-PSSession -ComputerName localhost $folder = "c:\test" $exclude =@("c:\test\file1","c:\test\file2") Invoke-Command -Session $remoteSession -ScriptBlock { #$Using:exclude Get-ChildItem -Path $Using:folder -recurse | Where {$Using:exclude -notcontains $_.FullName} } Remove-PSSession $remoteSession Gives the result: However, if I uncomment “$Using:exclude” I get the result: Suddenly