Get Computer Workstations Manufacturer and Model Remotely using a PowerShell Script

In this post we are going investigate the use of PowerShell scripting to remotely mass gather all desktops \ laptops make and model details within an environment.

Asset management is a big part of the general management of business IT. Having useful little scripts to gather information quickly with minimal effort has proved very beneficial for me, especially in environments where asset management has been neglected.

Getting a list of workstations –

If you don’t already have list of your workstations, run the PowerShell command below making sure to change the -searchbase switch to match your environment.

Get-ADComputer -filter * -SearchBase ‘OU=Workstations,DC=plebs,DC=local’ -Properties * | select Name, Description | export-csv -Path C:\temp\Workstations.csv

Creating a notepad containing workstations –

Next you will need to copy the workstations into a txt document. In my case I saved it to a temp folder on my C Drive. Your script will pull from this document.

Workstations notepad

Loop script utilizing Get-WmiObject –

Make sure to point the script to the right locations, so Get-Content needs target the location of your txt file.

$computernames = Get-Content ‘C:\temp\Computers.txt’ #Gets list of workstations from txt document
$Workstations= @() #Stops loop clearing array
foreach ($computername in $computernames)
{
$WmiObject = Get-WmiObject -computername $computername Win32_ComputerSystem | select Manufacturer, Model, Name
$Workstations += $WmiObject
}
$Workstations | export-csv -Path C:\temp\WorkstationDetails.csv

Exported CSV Results –

Go to the location of your exported CSV and you should get similar results to the image below.

Excel csv

Errors: The RPC server is unavailable –

get-wmiobject

This error is nothing to worry about, it simply means the desktop/laptop is currently not on the network or powered on. The script will just exclude that workstation from the list.

Want to include failed connections?

If you want to include failed connections in the final export, try using this script. It utilizes the Test-Connection command to test the connection to the workstations and as a result the addition of the failed desktops in the csv. However instead of showing the Make and Model it changes the manufacturer and model column to “Failed connection” whilst also adding the desktop name.

$computernames = Get-Content ‘C:\temp\Computers.txt’ #Gets list of workstations from txt document
$Workstations = @() #Stops loop clearing array

foreach ($computername in $computernames)
{
$status = Test-Connection $computername -count 1 -quiet #Tests connection
#If connection successful
If ($status -eq ‘true’){
$WmiObject = Get-WmiObject -computername $computername Win32_ComputerSystem | select Manufacturer, Model, Name
$Workstations += $WmiObject
}
#Else if connection fails
Else {
#Create object
$object = “” | Select “Name”,“Manufacturer”,“Model”
# Fill the object
$object.Name = $computername
$object.Manufacturer = “Failed Connection”
$object.Model = “Failed Connection”
# Add the object to the workstations array
$Workstations += $object
# Wipe the object
$object = $null }
}
$Workstations | export-csv -Path C:\temp\WorkstationDetails.csv

Failed connection csv

Want your script to gather more workstation information? –

WMI has a number of different classes that can be utilized to extract more information about the workstations in your environment.

https://ss64.com/ps/get-wmiobject.html – Includes a lot of the available classes you can check out.

Also user ‘vinaypamnani‘ on Github has published a really impressive WMI explorer application.  – https://archive.codeplex.com/?p=wmiehttps://github.com/vinaypamnani/wmie2/releases

 


Thanks for reading – feel free to follow and stay updated 🙂 View sysadminguides’s profile on Facebook View GuidesSysadmin’s profile on Twitter View 115372466162675927272’s profile on Google+

One thought on “Get Computer Workstations Manufacturer and Model Remotely using a PowerShell Script

  1. Thanks for this handy tip!
    Did you know that you can export directly to Excel with the Import-Excel module in PS? 😀 Install-Module ImportExcel
    So instead of:
    export-csv -Path C:\temp\Workstations.csv
    You could write:
    Export-Excel “$env:USERPROFILE\Desktop\Workstations.xlsx” -FreezeTopRow -AutoSize -AutoFilter -BoldTopRow -Show
    and BAM! it’s right there in your Excel

    Like

Leave a comment