0

I am trying to filter the results of the following command to only return the UninstallString of a specific piece of software on a remote computer. The command runs without an issue, but it returns the UninstallString of all programs installed on the remote computer. If I run the same command on my local machine without the "Invoke-Command -ComputerName $computer -ScriptBlock", it works properly and filters the results as needed. Any help is greatly appreciated!

$computer="Test1"
$softwareName="Solarwinds"
$uninstall32=Invoke-Command -ComputerName $computer -ScriptBlock {Get-ChildItem "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" | Get-ItemProperty | Where-Object {$_.DisplayName -like "*$softwareName*"} | Select UninstallString}
  • The variable inside the scriptblock isn't in the same scope. Either use `$using:softwareName` or pass in through an argumentlist / param block. Note the using scope requires PowerShell 3+ – BenH May 29 '18 at 15:27
  • Awesome, that did it. Thank you very much! – Jason Williams May 29 '18 at 15:42

0 Answers0