Simple PowerShell to get a Computer’s Specification

With Black Friday and Christmas fast approaching, I’m getting a lot of requests for people to help with computer upgrades or even whole new PCs.

Normally the first question you need answered is what do they have already, but this can sometimes not be straight-forward to a non-technical person.

Me: “What kind of PC do you have now?”

Them: “Sort of beigey-white? Eggshell maybe?”

We’re mid-pandemic so going round to have a look isn’t an option and my intricate multi-page documents about how to go to get each piece of info (with screenshots!) were still too technical.

So, PowerShell to the rescue.

All this requires if for them to start PowerShell, paste the following into it and press return;

cls
Write-Output ("Processor: {0}" -f  (Get-WmiObject Win32_Processor).Name)
$mb=Get-WmiObject win32_baseboard
Write-Output ("`nMotherboard: {0} {1} {2}" -f $mb.Product, $mb.Manufacturer, $mb.Version) 
Write-Output ("`nRAM (GB): {0:n3}" -f ([string](Get-WmiObject Win32_ComputerSystem).totalphysicalmemory / 1Gb))
Write-Output ("`nGPU(s): {0}`n" -f ((Get-WmiObject win32_VideoController).Name) -join ",")
Get-Disk | % {"Disk: {0}({1:n3} GB)" -f ($_.FriendlyName, ($_.Size /1Gb))}

Result;

Processor: Intel(R) Core(TM) i5-4300M CPU @ 2.60GHz
Motherboard: ASUS BFG 9000
RAM (GB): 7.880
GPU(s): Intel(R) HD Graphics 4600
Disk: WD360GD-00FNA0(37 GB)

Great! Processor, Motherboard, RAM, GPUs and Disks should provide enough enough to be getting on with. They can copy it and paste it back to you and you’re off to the races.

The script itself is pretty simple; lots of WMI calls with some code to format it nicely;

cls
Write-Output ("Processor: {0}" -f  (Get-WmiObject Win32_Processor).Name)

After clearing the screen it gets the Processor name and puts the result into a preformatted string; -f replaces each index in the string ({0}) with the strings after the -f in order they’re listed.

For example;

$mb=Get-WmiObject win32_baseboard
 Write-Output ("`nMotherboard: {0} {1} {2}" -f $mb.Product, $mb.Manufacturer, $mb.Version)

After setting a variable ($mb) with all the motherboard info we replace the {0}, {1} and {2} placeholders with the Product, Manufacturer and Version Number properties respectively.

You can do a bit more fancy stuff with the placeholders too;

Write-Output ("`nRAM (GB): {0:n3}" -f ([string](Get-WmiObject Win32_ComputerSystem).totalphysicalmemory / 1Gb))

In this one the index for replacement also specifies that the number should only have 3 decimal places ({0:n3}). Also the Total Physical Memory is converted from bytes to GB by dividing by /1Gb (a handy shortcut).

Write-Output ("nGPU(s): {0}n" -f ((Get-WmiObject win32_VideoController).Name) -join ",")

In case they have more than one graphics card (for example; a discrete one and one on the motherboard) the above gets ALL the GPU names and joins them into one string, each separated by “,“.

Get-Disk | % {"Disk: {0}({1:n3} GB)" -f ($_.FriendlyName, ($_.Size /1Gb))}

This doesn’t use WMI but instead uses the Get-Disk command. It then iterates through each piped result (using the shortcut for ForEach: “%“), uses $_ (referring to each result in the pipeline) to get the friendly name and the size (in GB) and creates a list.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: