Recently I noticed that Kaseya (our system management system) does not always update the operating system name when a computer has been upgraded. It can take a while for a computer to report back in and provide accurate information. Since we finished up our Windows 10 upgrades, we wanted to be 100% sure that we upgraded all our machines. So to verify this information I wrote a script to find out every machine’s operating system in our network.

First we had to query the information that we wanted. In this case, we just needed the computer name and operating system that was running:

$computername = $env:COMPUTERNAME
$os = Get-WmiObject -Class Win32_OperatingSystem | foreach { $_.caption }

Now we wanted to specify the name of the CSV and where we wanted to export the file that will contain all the information:

$directory = "c:\audit"
$file = "os-information.csv"

Then I had to create a custom table that will display the information:

$table=  New-Object –TypeName PSObject -Property @{
            'ComputerName'= $computername
            'Operating System' = $os
} | Select computername, 'Operating System'

Finally we get to put everything together and run the script:

$table | Export-Csv -NoTypeInformation -Path "$directory\$file" -append

Below is the full script:

$computername = $env:COMPUTERNAME
$os = Get-WmiObject -Class Win32_OperatingSystem | foreach { $_.caption }

$directory = "c:\audit"
$file = "os-information.csv"

$table=  New-Object –TypeName PSObject -Property @{
            'ComputerName'= $computername
            'Operating System' = $os
} | Select computername, 'Operating System'


$table | Export-Csv -NoTypeInformation -Path "$directory\$file" -append