Powershell Get-Package 未正确过滤
我在使用 Get-Package cmdlet 过滤应用程序时遇到了这个问题
当我使用下面的代码时,
$Cred = Get-Credential
Invoke-Command -ComputerName "server01" -Credential $Cred -ScriptBlock { Get-Package -Name "Google Chrome"}
,它可以正确地从远程计算机中过滤掉 Chrome
。(见下文)
如果我将 Chrome 分配给变量,如下所示
$Cred = Get-Credential
$app = "Google Chrome"
Invoke-Command -ComputerName "server01" -Credential $Cred -ScriptBlock { Get-Package -Name $app}
它显示远程计算机中安装的所有应用程序。
这里似乎有什么问题?这不是分配变量的正确方法吗?
I am having this issue with filtering of application with Get-Package cmdlet
when I use the below code,
$Cred = Get-Credential
Invoke-Command -ComputerName "server01" -Credential $Cred -ScriptBlock { Get-Package -Name "Google Chrome"}
it is properly filtering out Chrome
from the remote machine.(see below)
if I assign Chrome to a variable, like below
$Cred = Get-Credential
$app = "Google Chrome"
Invoke-Command -ComputerName "server01" -Credential $Cred -ScriptBlock { Get-Package -Name $app}
Its showing all the applications installed in the remote machine.
What seems to be the issue here ? Is it not the proper way to assign variable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我得到了它。必须在变量前面使用 $Using
这有效。
I got it. Had to use $Using in front of variable
This worked.