2

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*"}
Community
  • 1
  • 1
cinq2
  • 61
  • 5

1 Answers1

5

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*"}
Martin Brandl
  • 56,134
  • 13
  • 133
  • 172