How To Find Dell System Tag Using PowerShell

I administer a lot of computer brands, and support a wide ecosystem.  But I see a lot of Dell Laptops, Desktops, and Servers in my normal day-to-day.  A common task is to rebuild a system, or to update a driver after troubleshooting blue screens.

When it’s time to download drivers, there’s one sequence of events that I don’t want to do anymore:

  1. Turn over laptop
  2. Read the serial number
  3. Tell myself “I got this”
  4. Stare at the serial number
  5. Memorize the serial number
  6. Turn the laptop back over, and enter the serial number onto the support webpage
  7. Forget the stupid serial number halfway through (cause it’s the serial number that’s stupid, not me, right?)
  8. Repeat steps 1-7 again (do step 8 only one time.  If today is Monday and you have not had coffee yet, do step 8 two times)
  9. Fine!  Write down the stupid serial number
  10. Tell myself “No problem – I told you I got this”

Now that I’m more refined in my technique, I can show you my simple way to find the serial number or system tag of a Dell computer by using PowerShell:

get-wmiobject Win32_ComputerSystem | select SerialNumber

That actually returns a PSCustomObject.  Now, you might want to get right at the string value instead.  If you’re putting the computers serial number or system tag through the pipeline, or saving it to a file, then you should use this instead – it will return just the string value stored in WMI.

(gwmi Win32_ComputerSystem).SerialNumber

Here, we invoke the alias for get-wmiObject, gwmi.  It is exactly the same, just fewer keystrokes.  Then, we use the parenthesis to turn it into an object, and put the “.” (dot) there to get access to the properties.

This can also be used to get the system tag for a remote system by using the –computername parameter on the get-wmiobject cmdlet

gwmi Win32_ComputerSystem –computername remotesystem-pc

This is the best way that I’ve found to get the information from a Dell computer.  You can use the Service Tag on their website to get up to date drivers and warranty information.

PowerShell Profile Trick – Change Background Color On Administrative Shell

Here’s a great piece of profile customization: Make your PowerShell session have a dark red background each time it starts a session running as an administrator.

To do this, I look the built in $host variable, which has several properties in it, such as the foreground color and the background color of the shell.  Here’s the difference between a PowerShell session running in normal mode (blue screen) vs. administrator mode (red screen)

Advertisement

Standard PowerShell Session
Blue background on regular session
Administrative Powershell Session
Red background on an administrative session

 

Continue reading “PowerShell Profile Trick – Change Background Color On Administrative Shell”

Holy Profile Trick! Add a Daily Bible Verse to Your PowerShell Console

Excellent profile customization.  I use this one myself, and honestly it’s my favorite one.  Keeps my head in the right place.

This PowerShell profile customization is simple and sweet:  Go grab a webpage source; parse the lines to get to the juice; display a daily bible verse on my PowerShell console.

Continue reading “Holy Profile Trick! Add a Daily Bible Verse to Your PowerShell Console”

How to Identify Uninstaller Information From Registry Keys

If you want a fast way to get information about the uninstallers that are listed in the registry, then check out this simple script to parse out some information for you.


$searchterm = read-host "Enter search term for uninstallers"
$uninstallers = get-childitem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
$founditems = $uninstallers | ? {(Get-ItemProperty -path ("HKLM:\"+$_.name) -name Displayname -erroraction silentlycontinue) -match $searchterm}
write-host "Searched registry for uninstall information on $searchterm"
write-host "------------------------------------------"
if ($founditems -eq $null) {"None found"} else {
write-host "Found "($founditems | measure-object).count" item(s):`n"
$founditems | % {
Write-host "Displayname: "$_.getvalue("Displayname")
Write-host "Displayversion: "$_.getvalue("Displayversion")
Write-host "InstallDate: "$_.getvalue("InstallDate")
Write-host "InstallSource: "$_.getvalue("InstallSource")
Write-host "UninstallString: "$_.getvalue("UninstallString")
Write-host "`n"
}
}

This little baby asks you for a search term, then grabs the pertinent software uninstall information out of the HKey Local Machine registry hive.

It’s simple and effective,  and I put it together in just a couple of minutes.  It could stand to have some polish on it, but it does the job and it does it like now!

Would you improve it?  How?  Comments are open.

Continue reading “How to Identify Uninstaller Information From Registry Keys”

PowerShell Profile Tricks – Random Background Color

The need:  To run multiple PowerShell windows and keep it straight which one is working on what.

Example:

  1. In PowerShell window #1 you’re working with SharePoint
  2. In PowerShell window #2 you’re working with Active Directory users
  3. In PowerShell window #3 you’re goofing off customizing your profile so you can write a blog post

Only problem is, once you’re working with these windows, it’s hard to tell which window was the one you are working on your profile in – because they all look like this:

image image image

Here’s how to alleviate this problem automatically using an awesome PowerShell profile trick

Continue reading “PowerShell Profile Tricks – Random Background Color”

Beginning PowerShell Free Tutorial – Creating Your Profile

Whether you’re new to PowerShell or not, when you find yourself ready to start customizing PowerShell and making it do a few tricks, you’re going to want to setup your profile.

Don’t worry, I will show you how to create your profile, and even show you how to add a few cool things to your profile.  You are about to develop the skills to tame that PowerShell profile!

Advertisement

Continue reading “Beginning PowerShell Free Tutorial – Creating Your Profile”

How To Find Your System Path – Using PowerShell and Environment Variables

Just had a couple techs scratching their heads about finding the path.

Seriously? Yes.

But to be fair, the path can get long and downright hard to read.   And that was the problem for our tech friends.

Now my friends are smart guys, but they had a problem with a path.  I can understand, since my path statement is over 800 characters, and nearly impossible to understand when read the normal way.  They should have learned PowerShell.  I’ll show you why, and it’s a great example of how PowerShell blows away other methods by being super easy and ultra flexible.

Continue reading “How To Find Your System Path – Using PowerShell and Environment Variables”

PowerShell How To Ping a List of Computers

This quick free lesson in PowerShell teaches you how to use the ping class to get a list of offline computers.  It is fast and easy, and the results are much easier to work with than using ping.exe.

Using the .Net Ping Class

PowerShell is built for speed, and it leverages the .Net framework to make this happen. 

To check the computers status, a Ping request is sent to each computer in a list. 

To start pinging, an object of the Ping class is instantiated:

$ping = new-object system.net.networkinformation.ping

Easy, right?

This avoids having to use the sloppy mess of processing through the text returned by ping.exe.

What is the difference?

By using a .Net object for the ping results, we can still use the object that is returned.  We can save the objects themselves and reference them back later.  The beauty of PowerShell.  The Power.  We want (and get) much more information.  The results of

ping 192.168.1.1

is a wall of text (an array of 11 strings, actually,) while the result of

$ping.send(“192.168.1.1”)

Is a .Net object of the "system.net.networkinformation.pingreply” class.  A pingreply has a property (named ‘status’) that tells us if the ping was successful or not; the address of the ping; and the miliseconds that it takes to get the reply.

To get results that are usable, keep your ping replies in a variable of results, like this:

$pingreturns = $ping.send(“192.168.1.1”)

Alright, we’ve got the base now for finding out if the computer is reachable.

Get Your Computer List Ready

The list of computers we want to ping.  You don’t have to limit your list to only computers. If the network device has Internet Control Message Protocol (ICMP) available (most do) and turned on (depends), it will return pings when they are received. You could ping network printers, or routers, for example.

Here are some examples of loading the ping list:

Get Computer List From Textfile

If you have several computers that you want to check frequently, add them to a text file so it’s easy to save, and easy to update the file instead of modifying the script.

“computer1”,”computer2”,”192.168.1.100”,”192.168.1.1” | out-file c:\users\public\documents\pinglist.txt

Now you’ve got a text file.  Quake with fear, bitches!  Note the use of hostnames and IP Addresses.  It’s fine to do that, you can mix and match.  That list is 4 computers, not a collection of 2 computers listed by hostname and IP.

Update the list of computers as needed.

To load the list of computers:

$complist = gc c:\users\public\documents\pinglist.txt

Get Computer List Manually

$complist = “computer1”, “computer2”

Easy, simple, and easy.  To change the list, you’d change it in the script itself. 

Get Computer List From Other Parts Of The Script

$servers = get-qadcomputer –service domain.com *serv*

$complist = $servers | select name

This seems normal, but it’s actually different, because you’re saving a list of objects into $complist, instead of a list of strings.  Here’s the difference

PS C:\ScriptGenius> $stringlist = "Computer1", "Computer2"
PS C:\ScriptGenius> $stringlist[0]
Computer1
PS C:\ScriptGenius> $stringlist[0].gettype()

IsPublic IsSerial Name                                     BaseType
——– ——– —-                                     ——–
True     True     String                                   System.Object

Compare that to the item in the object list

PS C:\ScriptGenius> $objectlist = get-qadcomputer *work* | select name
PS C:\ScriptGenius> $objectlist[0]

Name
—-
SOFTGRIDWORK2

PS C:\ScriptGenius> $objectlist[0].gettype()

IsPublic IsSerial Name                                     BaseType
——– ——– —-                                     ——–
True     False    PSCustomObject                           System.Object

While the two seem at first to be the same:

$ping.send($stringlist[0])

Works.

$ping.send($objectlist[0])

Does not, but it is at least salvageable.  To make that ping work,  the name property of the psCustomObject (the computer account returned by get-qadcomputer) must be referenced.

$ping.send($objectlist[0].name)

Works.

Get Computer List From an IP Range

This will do an IP sweep for a subnet, pinging along the way.

1..254 | % {$ping.send(“192.168.1.$_”) | select address, status}

Putting it All Together

Now that we’ve seen the pieces, here’s how it all works together.

$computers = get-content C:\scriptgenius\computers.txt

$ping = new-object system.net.networkinformation.ping

$pingreturns = @()

foreach ($entry in $computers) {

  $pingreturns += $ping.send($entry)

}

An array is used here to collect multiple ping results.  When completed, this can be used like this.

$pingreturns[4].status

or

$pingreturns | ? {$_.status –ne “success”} | select address

Instead of piping that to “select address” we could just as easily take action on those failed IP addresses.  Like sending the list of offline computers to the administrative team on on-call person via email.