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.