Get installed software list quickly using PowerShell (2021)

Get installed software list quickly using PowerShell

Hello, PowerShell enthusiast wishing you all Merry Christmas and a Happy New Year,  today we will understand on creating a PowerShell script to fetch all the installed software details from remote servers. This will be an easy task for us if you are following me through all of my posts.

Don’t get amazed to see a few things which I have used in my old post. As you must be knowing past experience and knowledge is always helpful in your life. So let’s move ahead and dive into our script.

Script Requirements

Before we proceed further we need to understand some of the points which will help us to understand the script clearly.

  • To understand what exactly is New-Object PSObject go through the link to understand more on this.
  •  
  • We will use Get-WmiObject -ClassName Win32_product to fetch the application details from remote servers.

How to get installed application details using Powershell

As mentioned above we need a class Win32_product which will provide us the list of all the applications installed in your or remote servers. Below is one example and the result.

The output will vary as it depends upon the application installed on your system or the system sitting remotely. If the count of applications is high the command will take time to get executed.

				
					Get-WmiObject -ClassName Win32_product

#####Output##########

IdentifyingNumber : {E503B4BF-F7BB-3D5F-8BC8-F694B1CFF942}
Name              : Microsoft Visual C++ 2008 Redistributable - x86 9.0.21022.218 False
Vendor            : Microsoft Corporation
Version           : 9.0.21022.218
Caption           : Microsoft Visual C++ 2008 Redistributable - x86 9.0.21022.218 False
				
			

#Step 1

This is my vintage style to invoke my foreach loop.

				
					$comp= gc "C:\servers.txt"
$infoObject=@()
$results=@()
foreach($co in $comp)
{
$co
				
			

#Step 2

This step is not at all mandatory but if you want the script output to look great use this. The below line will have a CSS code.

				
					$css = @"
<style>
h1, h5, th { text-align: center; font-family: Segoe UI; }
table { margin: auto; font-family: Segoe UI; box-shadow: 10px 10px 5px #888; border: thin ridge grey; }
th { background: #0046c3; color: #fff; max-width: 400px; padding: 5px 10px; }
td { font-size: 11px; padding: 5px 20px; color: #000; }
tr { background: #b8d1f3; }
tr:nth-child(even) { background: #dae5f4; }
tr:nth-child(odd) { background: #b8d1f3; }
</style>
"@
				
			

#Step 3

As discussed earlier we will use New-object PSObject and we will assign it to $infoObject.

$p is assigned with test-connection which gives a boolean output either true or false.

In any case, if the server is not reachable from the host where we are running the script it will return $false. Hence we will run the required script on the servers which are reachable from our source server.

				
					$infoObject = New-Object PSObject
$p=Test-Connection -ComputerName $co -BufferSize 16  -Count 1 -Quiet 
$p
if ($p -eq $true)
{
				
			

#Step 4

$os will fetch the operating system of the remote server.

 $h will fetch the name of the application installed on remote servers.

$infoObject will be provided with the output of $co, $p, $os and $h.

				
					$os = (Get-WMIObject win32_operatingsystem -ComputerName $co ).caption
$os
$product=Get-WmiObject -ClassName Win32_product -Property *|select Name
$h=($product|select @{Name="name" ;expression={$product.name -join ","}} -Last 1).name
$h
$infoObject|Add-Member -MemberType NoteProperty -Name "Hostname"  -value $co
$infoObject|Add-Member -MemberType NoteProperty -Name "Reachable"  -value $p
$infoObject|Add-Member -MemberType NoteProperty -Name "Operating System"  -value $os
$infoObject|Add-Member -MemberType NoteProperty -Name "Product" -Value $h
$results+=$infoObject
}
				
			

#Step 5

In Else, we will provide blank output so that it will not interfere with our original output.

				
					else
{

$infoObject|Add-Member -MemberType NoteProperty -Name "Hostname"  -value $co
$infoObject|Add-Member -MemberType NoteProperty -Name "Reachable"  -value $p
#$infoObject|Add-Member -MemberType NoteProperty -Name "Operating System"  -value $os
#$infoObject|Add-Member -MemberType NoteProperty -Name "Auto Stopped services" -Value $h
$results+=$infoObject

}
}

				
			

#Step 6

Lastly, export the result in CSV file and using Export-CSV and convert the output of the CSV in HTML format using ConvertTo-HTML.

				
					$results|Export-csv "C:\Users\admin\Desktop\result.csv" -NoTypeInformation 
Import-CSV "C:\Users\admin\Desktop\result.csv" | ConvertTo-Html -Head $css  | Out-File "C:\Users\admin\Desktop\installedapp.html" 
				
			

#Results

k 1

Conclusion

I hope you have liked the post Get installed software list quickly using PowerShell and will implement this whenever it is required. Things you should always remember is to try with one more server so that it will be easy for you to make changes. Let me know if you want a blog post on some other script that might amaze you.

We are working continuously to provide you with the better and the best scripts daily. We will publish weekly hence don’t forget to subscribe to our newsletter. 

Leave a Reply

Please disable your adblocker or whitelist this site!