我的$var变量不适用于远程计算机.我在这个链接中使用过滤器在powershell中将变量传递给where-object不起作用.但我的脚本仍然无法从我的输入中找到应用程序.
$var = "application"
Invoke-command -ComputerName $cpu {
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* ,
HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
Where-Object {$_.DisplayName -like "*$var*"}
Run Code Online (Sandbox Code Playgroud)
根据您的PowerShell版本,您必须$using:在变量上使用前缀,或者必须使用-ArgumentList参数传递变量.这是一个例子:
Invoke-command -ComputerName $cpu {
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* ,
HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
Where-Object {$_.DisplayName -like "*$using:var*"}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
296 次 |
| 最近记录: |