How to get a program's installation path using Powershell - powershell

I've tried to use Get-ChildItem to get installed program property information and it does provide some of the information I require but the Installed Location/path is usually blank. Given a program's name/displayname, is there a way reliable way to get the installation path of a Windows Server program (remote to other servers) using Powershell?
Thanks in advance.

Using Registry:
Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |
% { Get-ItemProperty $_.PsPath } | Select DisplayName,InstallLocation
Using WMI:
Get-WmiObject -Class Win32_Product -Filter 'Name like "%Microsoft Office%"' |
Select Caption,InstallLocation
For Remoting, Through registry it's totally different story, with WMI just add the -ComputerName Parameter (and make sure you have permissions)

These 2 cmdlets:
Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | % { Get-ItemProperty $_.PsPath } | Select DisplayName,InstallLocation | Sort-Object Displayname -Descending
Get-ChildItem HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | % { Get-ItemProperty $_.PsPath } | Select DisplayName,InstallLocation | Sort-Object Displayname -Descending
These show different programs and their locations

Related

I need to do a condition in Power Shell

I'm searching a version of some files by Power Shell, example:
Get-ChildItem "C:\*\packetbeat.exe" -Recurse |
Select-Object -ExpandProperty VersionInfo |
Select-Object -ExpandProperty ProductVersion
And it shows me:
7.8.0
But I need to wait for the command finish its function, in this case the command will find in all disk C
I need finish this task when the first match appears.
If you want the search to stop after the first match, you can use this:
Get-ChildItem "C:\*\packetbeat.exe" -Recurse |
Select-Object -First 1 |
Select-Object -ExpandProperty VersionInfo |
Select-Object -ExpandProperty ProductVersion

Get-WmiObject -Class Win32_Product - showing wrong version of program

Get-WmiObject -Class Win32_Product | where-object { $_.name -like "*OfficeScan*" }
Shows me the wrong version number of the TrendMicro OfficeScan Client - the default Version 12.0.1222 when the installed version is 12.0.4430.
I also tried:
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
There it doesnt show up at all. It's weird because in the old systemcontrol if i go to deinstallation it shows the correct version:
So I need to somehow extract the information of the actual version to my powershell. I need it for a auto update feature, it has to be using powershell.
Assuming you're using a 64bit system, you're looking in the wrong place in the registry.
I don't have TrendMicro, so using Adobe Reader as an example:
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |
Where-Object { $_.DisplayName -like "*Adobe Reader*" } |
Select-Object DisplayName, DisplayVersion
If you just want a numerical Version property to use as a comparison, update:
Select-Object -Expand DisplayVersion

Powershell split items into text file into multiple variables

I am trying to run a software script against my servers, to see exactly what software is installed and what version. I have the list of the servers stored in a text file "SystemList.txt" that is formatted like you see below.
SERVER001
SERVER002
SERVER003
SERVER004
I need to pull the server names out of the file and use them in my csv that I need to look like this:
Here is the code:
$computers = Get-Content -path
D:\Users\stephen.lyons.sa\Documents\SystemList\SystemList.txt
Foreach($computer in $computers)
{
$computer
$env:COMPUTERNAME
Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*
|Select-Object Displayname, DisplayVersion, Publisher, InstallDate | Out-
file \\txusocts002\d$\APSO\Steve\Test\$env:COMPUTERNAME.csv
}
Perhaps I am missing something, but would this meet your CSV file need?
Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object -Property DisplayName,DisplayVersion,Publisher,InstallDate |
Export-Csv -Path my.csv

how do i out put from AD or txt

I am trying to run this programme against a a list of remote pc/servers either by AD out TXT and display them in either csv or html if any one can offer some help or advise I would be greatly appreciative.
My only limitation is all my machines run powershell v2 only
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Format-Table –AutoSize
You want to take the output of that command and put it in a file? PowerShell has a lot of tools to do this. However, you need to remove the Format-Table command first.
See, Format-Table is all about making your command output look really good in a PowerShell window, so it's got a lot of hard returns and columns and things defined in it which make sense to the console, but look like garbage when you export it.
For data like this, I think Comma Separated Value is probably the way to go.
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Export-CSV -NoTypeInfo -Path \\server\share\$($env:ComputerName)_Programs.csv
This example will export a CSV, omitting the import-helper info PowerShell normally adds, using the -NoTypeInformation switch. I figured it'd be useful to know the name of the computer which made the file, so that's just what it will do. Edit -Path to point to a server with a share and away you go. You'll end up with files like this:
ComputerA_Programs.Csv
ComputerB_Programs.Csv
ComputerC_Programs.Csv
If you want to pull from all Ad computers
ForEach ($COMPUTER in (Get-ADComputer -Filter * | Select-Object -ExpandProperty Name))
{if(!(Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
{write-host "cannot reach $computer" -f red}
else{Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Export-CSV -NoTypeInfo -Path "\\server\share$\$Computer_Programs.csv" -NoTypeInformation}}
for if you have list of computers in text
Foreach ($computer in ($computers= Get-Content "c:\Computers.txt" ))
{if(!(Test-Connection -cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
{write-host "cannot reach $computer" -f red}
else{
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Export-CSV -NoTypeInfo -Path "\\server\share$\$Computer_Programs.csv" -NoTypeInformation
}}

How to remove extra lines from Get-WMIObject output powershell

I am running the following query to get the video driver version number
Get-WmiObject Win32_videoController | where {$_.Name -like "Nvidia*"} | Format-table -HideTableHeaders DriverVersion
It returns the data I want plus about 4 extra lines. One before the output and 3 after. It doesn't look like it's going to show up properly in the post.
PS F:\>
Get-WmiObject Win32_videoController | where {$_.Name -like "Nvidia*"} | Format-table -HideTableHeaders DriverVersion
9.18.13.3250
PS F:\>
If you want to determine the driver version, forget about Format-Table. Simply do this:
Get-WmiObject Win32_VideoController -Filter "Name LIKE 'Nvidia%'" |
Select-Object -Expand DriverVersion
Note: You can also use the aliases gwmi for Get-WmiObject and select for Select-Object. Beware, though, that aliases may not be present during script execution depending on your environment. They're basically a means to reduce the amount of typing required in an interactive console.
Not sure exactly if this is what you want but give this a try.
This will only display the "Unique" driver versions. This will get rid of the dupe entrys
Get-WmiObject Win32_videoController | Where {$_.Name -like "Nvidia*"} | Select-Object DriverVersion -Unique | Format-Table -HideTableHeaders