Avatar of hypercube
hypercubeFlag for United States of America

asked on 

Powershelll command to get program install versions by computer

PowerShell command that works and is similar to what I need:
Invoke-Command -cn fredray2  -ScriptBlock {Get-ItemProperty HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | select DisplayName, DisplayVersion } 

Open in new window


So, what I'd like to do is to shorten the list that's generated by pulling out only certain DisplayNames.  There are only two or three so I could list them in the command.  OR, they all include GOLD in them and perhaps a filter on that content?  Then, I'd like to expand it:
from:
" -cn fredray2"
to:
all computers in the domain.
A formatted table output would be nice but perhaps I can do that much if these two things can be dealt with.

I've tried but no solution yet.
PowershellInstallation

Avatar of undefined
Last Comment
hypercube
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Get-ItemProperty -Path HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion | Where-Object displayName -like "*Microsoft*"

Open in new window


Invoke-Command -cn fredray2  -ScriptBlock  { Get-ItemProperty -Path HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion | Where-Object displayName -like "*Gold*" | format-table }

Open in new window


get-adcomputer filter * | select-object dnshostname | Invoke-Command -cn $_.dnshostname  -ScriptBlock  { Get-ItemProperty -Path HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion | Where-Object displayName -like "*Gold*" | format-table }

Open in new window

$computers =get-adcomputer -filter * | Select-Object dnshostname
foreach($computer in $computers) {
$testcomputer = $computer.dnshostname
if(Test-NetConnection -ComputerName $testcomputer -InformationLevel Quiet ) {
write-host ("$testcomputer is Alive")
#
# insert your invoke command here
#
}
else{
write-host ("$testcomputer is not responding" ) -ForegroundColor Yellow -BackgroundColor Black
}
}

Open in new window

Avatar of hypercube
hypercube
Flag of United States of America image

ASKER

David Johnson:  I couldn't have asked for a better answer!!  This is really helpful!  That it pushes me a bit is part of that.
I've been able to experiment quite a bit with it all and the results are very encouraging.

But, I'm seeing a couple of things that puzzle me:
I'm working on just one computer right now so I can inspect the source of CurrentVersion\Uninstall
Invoke-Command -cn $testcomputer  -ScriptBlock {Get-ItemProperty HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | select-Object DisplayName, DisplayVersion | Where-Object displayName -like "*GOLD*" | Sort-Object -Property displayname}

Open in new window

The actual Registry content in the referenced Uninstall list has DisplayName and DisplayVersion appearing in this order:
GOLDTellerCIM     19.2.11.2
CIM GOLD(TM)      19.9.9.1
GOLDEventLetters  19.7.11.1
GOLDTellerCIM     19.2.11.2
GOLDEventLetters  19.7.11.1

If I use -like "*GOLD" (a leading wildcard) then I get nothing.  I don't see why that would be as they all include GOLD.
If I use -like "GOLD" (no wildcard) then I get:nothing.  
If I use -like "GOLD*" (a trailing wildcard) then I get:

DisplayName      DisplayVersion PSComputerName
-----------      -------------- --------------
GOLDEventLetters 19.7.11.1  

If I use -like "*GOLD*" (a leading and a trailing wildcard) then I get:

DisplayName  DisplayVersion PSComputerName
-----------  -------------- --------------
CIM GOLD(TM) 19.9.9.1

And if I don't use Get-Unique at all then all 5 show up sorted:
DisplayName      DisplayVersion PSComputerName
-----------      -------------- --------------
CIM GOLD(TM)     19.9.9.1                    
GOLDEventLetters 19.7.11.1                    
GOLDEventLetters 19.7.11.1                    
GOLDTellerCIM    19.2.11.2                    
GOLDTellerCIM    19.2.11.2  

My objective would be to get:
DisplayName      DisplayVersion PSComputerName
-----------      -------------- --------------
CIM GOLD(TM)      19.9.9.1    fredlb2                    
GOLDEventLetters 19.7.11.1  fredlb2                    
GOLDTellerCIM     19.2.11.2   fredlb2                  

I can certainly work to debug the code but if you see something here that's obvious to you then that could be helpful!
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of hypercube
hypercube
Flag of United States of America image

ASKER

David Johnson:  That did it!
The final code that I'm using productively:
Get-ADComputer -Filter 'operatingsystem -notlike "*server*" -and enabled -eq "true"' `
-Properties Name,Operatingsystem,OperatingSystemVersion,IPv4Address |`
Sort-Object -Property Name |  Sort-Object -Property OperatingsystemVersion | `
Select-Object -Property Name,Operatingsystem,OperatingSystemVersion,IPv4Address | Tee-Object -file "\\NASHVILLE\Exec1\6 IT Docs and Downloads\_Documents\Windows Versions\WindowsVersions.txt"

Open in new window

Thank you very much!!
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo