Get Model and Serial Number via PowerShell

Photo of author
By Jeff LeBlanc

A simple script to get some basic server info via PowerShell

This script retrieves info from the appropriate WMI class and inserts it into a variable and then outputs it to the host and CompInfo.txt file.

CompInfo

Basic Commands:

Get-WmiObject -ComputerName localhost -Namespace root\cimv2 -Class Win32_ComputerSystem | Select-Object Model

Get-WmiObject -ComputerName localhost -Namespace root\cimv2 -Class Win32_SystemEnclosure | Select-Object SerialNumber

Get-WmiObject -ComputerName $Server -Namespace root\cimv2 -Class Win32_OperatingSystem | Select-Object Caption

$Servers = Get-Content -Path "$PSScriptRoot\Servers.txt"

$ping = New-Object System.Net.NetworkInformation.Ping

forEach ($Server in $Servers) {

    $OS = Get-WmiObject -ComputerName $Server -Namespace root\cimv2 -Class Win32_OperatingSystem | Select-Object Caption
    $IPAddress = ($ping.Send($Server).Address)
    $Model = $(Get-WmiObject -ComputerName $Server -Namespace root\cimv2 -Class Win32_ComputerSystem | Select-Object Model)
    $SerialNum = Get-WmiObject -ComputerName $Server -Namespace root\cimv2 -Class Win32_SystemEnclosure | Select-Object SerialNumber
    
    Write-Host "$Server`t$($OS.Caption)`t$IPAddress`t$($Model.Model)`t$($SerialNum.SerialNumber)"
    "$Server`t$($OS.Caption)`t$IPAddress`t$($Model.Model)`t$($SerialNum.SerialNumber)" | Out-File -FilePath .\CompInfo.txt -Append
}

Leave a Comment