Thursday, August 11, 2016

Powershell - Create List of Installed Software


Scenario

You want to find out what software is installed on the computers in your organization.  You can use PowerShell to do this.

First open PowerShell ISE and paste the following code in the script portion.

$list = Import-Csv "C:\TEMP\computers.csv"
foreach ($entry in $list)
{

try
    {
$machinename = $entry.pcname
$SrvPath = "\\server\share"
$Date = Get-Date -UFormat %m-%d-%y
$FileName = "$machinename" + "_" + "$Date" + ".csv"
Get-WmiObject Win32_Product -ComputerName $machinename | Select-Object PSComputerName,Name,Vendor,Version | Export-Csv C:\$FileName -NoTypeInformation

    }
    catch [Exception]
    {
    }
}


Next you will need to create a .csv file called "computers.csv".  The script will look to this file to know what computers on your network to run against.  In cell A1 enter "pcname" and then copy and paste the list of computers into Column A of your .csv file.  The script will go through the list and run against that list of computers.  It will create a separate .csv file for each computer and name the file according to the computer name and date.

This will leave you with a lot of .csv files containing information about the software on your computers.  You can merge these files using the following command.

Open an administrative cmd prompt and navigate to the directory with your .csv files.  Then run this command:

C:\Temp\FilesToMerge>for %f in (*.csv) do type "%f" >>MergedFile.csv

Now you should have a file called MergedFile.csv in your folder.  That should contain the merged file.

No comments:

Post a Comment