Reputation: 364
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?
Upvotes: 0
Views: 545
Reputation: 364
I got it. Had to use $Using in front of variable
$Cred = Get-Credential
$app = "Google Chrome"
Invoke-Command -ComputerName "server01" -Credential $Cred -ScriptBlock { Get-Package -Name $Using:app}
This worked.
Upvotes: 1