我有文件夹c:\ test我有三个文件:"file1","file2","file3"
以下脚本:
$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
Run Code Online (Sandbox Code Playgroud)
但是,如果我取消注释"$ Using:exclude",我会得到结果:

突然排除列表开始正常工作