小编use*_*425的帖子

PowerShell Remoting $使用变量范围

我有文件夹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)

给出结果: 图片1

但是,如果我取消注释"$ Using:exclude",我会得到结果: 在此输入图像描述

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

powershell powershell-remoting powershell-3.0

7
推荐指数
1
解决办法
1万
查看次数