Sid133
Sid133

Reputation: 364

Powershell Get-Package not filtering properly

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)

enter image description here

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.

enter image description here

What seems to be the issue here ? Is it not the proper way to assign variable?

Upvotes: 0

Views: 545

Answers (1)

Sid133
Sid133

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

Related Questions