2

I have a Function I am working on to pull DisplayName and UninstallStrings from a remote computer's registry. If I only use "$software" parameter, it works fine for my local PC. But, if I add the "$compname" variable and try an invoke-command to get to a remote PC to do the same thing, it breaks. Here is what I have so far:

Function Get-Uninstallers {

  param (
    [parameter(mandatory)]
    [string]$compName,
    
    [parameter(mandatory)]
    [string]$software,

    $soft = ('"' + ("*" + $software + "*") + '"')
  )

  Invoke-Command -ComputerName $compname {
    Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
      Get-ItemProperty | Where-Object {$_.DisplayName -like $soft} |
        Select-Object DisplayName, UninstallString
  }

}

I have tried all kinds of different combinations for the $soft variable, with/without quotes, single quotes, without one of the *s and without both. I know I am doing something wrong, but I cannot figure it out for the life of me. I tried adding quotes to the parameter on the command line and leaving them out.

Here is a sample of the output I am getting when I fill in the variables:

PS C:\> Invoke-Command -ComputerName 61966 {  
  Get-ChildItem -Path HKLM:  \SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall,
 HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
    Get-ItemProperty | Where-Object {$_.DisplayName -like "*calabrio*"} |
      Select-Object DisplayName, UninstallString  
}  
 
 
DisplayName     : Calabrio Screen Player Plug-in version 8.0.2.2004  
UninstallString : "C:\WINDOWS\unins000.exe"  
PSComputerName  : 61966  
RunspaceId      : cfdbbc09-42e6-4c1f-a2ba-0bedc623d73b
 
DisplayName     : Calabrio Analytic Services Client
UninstallString : MsiExec.exe /I{4762419C-C004-46F8-AB0D-DACA7C05258F}
PSComputerName  : 61966
RunspaceId      : cfdbbc09-42e6-4c1f-a2ba-0bedc623d73b
 
DisplayName     : Calabrio Monitoring and Recording Recording
UninstallString : MsiExec.exe /X{5144778B-D71E-4FE5-8AEB-D5A2DAE6DABA}
PSComputerName  : 61966
RunspaceId      : cfdbbc09-42e6-4c1f-a2ba-0bedc623d73b
 
DisplayName     : Calabrio Monitoring and Recording Services Service Release 0 Engineering Special 2
UninstallString : MsiExec.exe /X{FAEDCE7E-1A2B-4CCC-89D8-8DD28F51B05E}
PSComputerName  : 61966

RunspaceId      : cfdbbc09-42e6-4c1f-a2ba-0bedc623d73b

Here is an example of when I run the function specifying the parameters:

PS C:\> Get-Uninstallers -compName 61966 -software calabrio


DisplayName     : 
UninstallString : 
PSComputerName  : 61966
RunspaceId      : 2df812e2-8693-483f-918c-ece84892c5c5

DisplayName     : 
UninstallString : 
PSComputerName  : 61966
RunspaceId      : 2df812e2-8693-483f-918c-ece84892c5c5

DisplayName     : 
UninstallString : 
PSComputerName  : gmcr61966
RunspaceId      : 2df812e2-8693-483f-918c-ece84892c5c5

DisplayName     : 
UninstallString : 
PSComputerName  : 61966
RunspaceId      : 2df812e2-8693-483f-918c-ece84892c5c5

DisplayName     : 
UninstallString : 
PSComputerName  : 61966
RunspaceId      : 2df812e2-8693-483f-918c-ece84892c5c5

DisplayName     : 
UninstallString : 
PSComputerName  : 61966
RunspaceId      : 2df812e2-8693-483f-918c-ece84892c5c5

DisplayName     : 
UninstallString : 
PSComputerName  : 61966
RunspaceId      : 2df812e2-8693-483f-918c-ece84892c5c5

DisplayName     : 
UninstallString : "C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE14\Oarpmany.exe" /removereleaseinpatch "{90140000-0011-0000-0000-0000000FF1CE}" 
                  "{71949C83-C5B4-43D2-9372-E3838A5E82E6}" "1033" "0"
PSComputerName  : 61966
RunspaceId      : 2df812e2-8693-483f-918c-ece84892c5c5

DisplayName     : 
UninstallString : 
PSComputerName  : 61966
RunspaceId      : 2df812e2-8693-483f-918c-ece84892c5c5

DisplayName     : 
UninstallString : 
PSComputerName  : 61966
RunspaceId      : 2df812e2-8693-483f-918c-ece84892c5c5

DisplayName     : 
UninstallString : 
PSComputerName  : 61966
RunspaceId      : 2df812e2-8693-483f-918c-ece84892c5c5

Here is the desired output:

PS C:\> Invoke-Command -ComputerName 61966 {
  $software = "*calabrio*"

  Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
  Get-ItemProperty | Where-Object {$_.DisplayName -like $software} |
    Select-Object DisplayName,UninstallString | FT
}

DisplayName                                                                           UninstallString                                                                     
    -----------                                                                           ---------------                                                                     
    Calabrio Screen Player Plug-in version 8.0.2.2004                                     "C:\WINDOWS\unins000.exe"                                                           
    Calabrio Analytic Services Client                                                     MsiExec.exe /I{4762419C-C004-46F8-AB0D-DACA7C05258F}                                
    Calabrio Monitoring and Recording Recording                                           MsiExec.exe /X{5144778B-D71E-4FE5-8AEB-D5A2DAE6DABA}                                
    Calabrio Monitoring and Recording Services Service Release 0 Engineering Special 2    MsiExec.exe /X{FAEDCE7E-1A2B-4CCC-89D8-8DD28F51B05E}

Any help would be appreciated. Thank you.

1
  • 1
    Are you passing $software to the scriptblock somehow? I don't see scriptblock parameters or using: anywhere. Aug 4, 2015 at 2:10

1 Answer 1

2

I tried your function, and i get an empty result too. The problem is what you do with your software parameter: you do not have to convert it to the variable $soft, you can directly use the $software-Variable with the astersik in the Where-Object clause. Just use:

Get-ItemProperty | Where-Object {$_.DisplayName -like "*$software*"} | Select-Object DisplayName,UninstallString

This works on my system, the wild card is working fine too.

EDIT: Here is the complete function that works on my machine - the line where you converted the variable $software into $soft is just disabled because you don't need it:

Function Get-Uninstallers {

param(
    [parameter(mandatory=$true)][string]$compName,
    [parameter(mandatory=$true)][string]$software
    #$soft = ('"' + ("*" + $software + "*") + '"')
    )

Invoke-Command -ComputerName $compname {
Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | `
Get-ItemProperty | Where-Object {$_.DisplayName -like "*$using:software*"} | Select-Object DisplayName,UninstallString
}
}

When i use the function, e.g.

Get-Uninstallers -compname my-pc -software VMWare

i get a list with all Software where the DisplayName contains "VMware", and nothing else.

7
  • Thank you for the help Tobias, but when I run it the way you suggested, it grabs all installed programs out of the registry instead of the one(s) I am trying to get using Where-Object.
    – Drew
    Aug 4, 2015 at 12:13
  • I just ran a test and If I leave the computer variable and fill in the software name, it works great. It's when the software variable is in there that it pulls all of the installed applications. I wish I knew how you got it to run Tobias!
    – Drew
    Aug 4, 2015 at 12:24
  • Edited my answer and posted the complete function which is working on my machine.
    – Tobias
    Aug 4, 2015 at 13:15
  • I copied and pasted, still getting everything. So weird you aren't. What version of PS are you running? Not that it should make a difference...
    – Drew
    Aug 4, 2015 at 15:11
  • 1
    Change the where-object part to look like this " {$_.DisplayName -like "*$using:software*"} " and it should work as you expect on any recent version of powershell.
    – jbsmith
    Aug 4, 2015 at 18:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .