How to pull a remote computer’s serial number using PowerShell

In your first six months on the job, you’ll lose a lot of time researching how to do basic tasks. I want to make your life a little easier by giving you scripts that make these tasks faster.

I tried to talk to Midnight about PowerShell, but he only wanted to talk about squirrels. But since pictures of PowerShell are pretty boring, I’m using this picture for this post instead.

This is probably going to be the least sexy blog post ever written, but being able to access serial numbers for computers on your network is fairly important, so here I go!

Let’s address your unspoken question first: why should you care about serial numbers?

Serial numbers are assigned by the maker of your computer and are useful for asset management, mainly. The two main use cases, specifically, are for asset tracking and for warranty information. This post is getting unsexier by the minute, so let’s just jump right in with a real-world example.

Let’s say that you have a user, John Smith, who’s been with the company for four years. During that time, he’s had the same laptop. Today, he comes to you with an issue: his laptop is not able to connect to the network when he hard-wires in (which is another way of saying he plugs in an ethernet cable to connect.) After spending some time diagnosing the issue, you eliminate all possible software and firmware causes. The cause is definitely a physical problem with the NIC (Network Interface Card) which will need to be replaced. Unfortunately, since this is a laptop and the NIC is soldered on, that means you’ll need to replace the whole motherboard.

At this point, you might be asking yourself two questions: is this laptop under warranty, and what level of support can I get for it? The laptop is labeled “JSMITH”, but the maker of the laptop (let’s say Dell in this case) is not going to identify the laptop the same way – you can’t call them up and tell them it’s John’s laptop and expect them to know which laptop you’re talking about.

Enter the serial number.

Each laptop has its own serial number. (If you want to be specific, the motherboard is the part of the laptop that is assigned a serial number.) Armed with the serial number, you can go to Dell’s site and pull warranty information. Put in your serial number and you’ll find out when your warranty expires and what level of support you can expect. For example, you may see that you have next-day pro support. If that’s the case, rejoice! You’ll have a tech from Dell show up the next business day to replace your motherboard!

So, how do you find out a computer’s serial?

If you’re physically in front of the computer, you can restart it and load the BIOS. (This is a different process depending on the computer make and model, but it usually involves pressing delete, F11, or another key at the right time.) This is both time-consuming and annoying to the user. They’ll inevitably have to spend five minutes saving their work and closing out of their applications so you can restart. It’s also a very manual process which doesn’t scale well when you have to do the same thing for 100 computers.

Another way to do this is to open a PowerShell prompt (by pressing start, typing “PowerShell”, and pressing enter) and typing:

Get-WmiObject -Class win32_bios

That’s a lot quicker than the first method! But… it’s still manual, and you may not always be able to get physical access to a computer when you want it.

Let’s now take a look at a very simple PowerShell script that can get you the serial number of a computer somewhere on your network:

$CompName = read-host -prompt “Please enter the machine name “

get-wmiobject -computername $CompName -class win32_bios

To use this, launch “PowerShell ISE” (as opposed to “PowerShell.”) I personally recommend you always use ISE for your PowerShell needs. ISE is essentially PowerShell but with a space for you to write out as many commands as you want. This is not so important when you want to write a quick one-liner, but when your script requires twenty lines, you don’t want to be writing them out each time! ISE allows you to save your scripts and reuse them.

Let’s start by doing that. Open PowerShell ISE, paste the above two lines into the white space, and press the save button. Now, you can run this script whenever you need it from the comfort of your desk.

At this point, let me mention my usual PowerShell warning: get in the habit of never running a script from the Internet without understanding what it does. PowerShell can be very unforgiving, and you can wreck your environment pretty easily!

So what does this script do? Let’s read it out in plain English. (The below is called pseudo code, fyi.)

“Ask for the name of the computer.

Find that computer and run the command to get the serial number on it.”

Read-host is PowerShell’s way to read input right from the command line. (PowerShell calls this the “host.”) The prompt is the question the host will ask. You can write whatever you want here.

The get-wmiobject command (technically called a commandlet, so let’s start using that term) is out of scope for this post. Entire books have been written on the subject, so for now let’s just accept that using WMI and specifying “win_32bios” will get you the serial information you’re looking for.

PowerShell commandlets can have parameters passed to them to make them more useful. In this case, we’re telling it that we’re going to pass a computer name to it. We pass the $CompName variable as the parameter, which is the computer name we collected in the first line.

That’s it! Now that you’ve saved this script, you can open it at any time, press “F5”, and PowerShell will prompt you for the computer name. This will work as long as the computer is connected to the same network as you.

I highly recommend you dedicate time to becoming familiar with PowerShell early on in your career. I recommend reading this book and once you’ve done that and have solid fundamentals, I really enjoy the Scripting Guy blog.

By the way, I should mention that there are a lot of enterprise grade tools that will track serial numbers for you, so find out if you’re using any of them in your workplace, but this is a nifty and quick way of getting the info that you need. As you grow your knowledge of PowerShell, you’ll be able to create more and more complex scripts that can rival any store-bought tool!

With each post, I cover a new topic to help you get your start (or keep progressing) in your IT career. If it’s your first time visiting this blog, start here. Or, see all my posts about interview questions you should be able to answer.