Reputation: 61
My $var
variable won't work on remote computers. I use filters like in this link In powershell passing variable to where-object not working. But still my script cant find app from my input.
$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*"}
Upvotes: 2
Views: 488
Reputation: 58981
Depending on your PowerShell version you either have to use the $using:
prefix on your variable or you have to pass the variable using the -ArgumentList
parameter. Here an example:
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*"}
Upvotes: 5