Melbourne, Australia
To be provided
Use Contact to message

Windows OS and Hardware Information using Powershell

Harmik Batth Tech's Blog

Windows OS and Hardware Information using Powershell

Getting information about Windows OS and it’s hardware is crucial for System Administrator’s today. But main question is how to collect it.

Lot of companies have software like SCCM, SCOM and other tools to obtain this information. When it comes to grabbing information from various servers and analyzing it at same time, nothing beats PowerShell.

Some of the Powershell commands I always use and will be of use for any System Admin out there:

BIOS Information

# Get BIOS information
$strBios = Get-WmiObject Win32_BIOS -computerName localhost

# Get BIOS Install Date
$biosInstallDate = ([WMI]”).ConvertToDateTime((Get-WmiObject Win32_BIOS).ReleaseDate).ToShortDateString()

Memory Information

#Get Memory Information
$strComputer = Hostname
$colSlots = Get-WmiObject -Class “win32_PhysicalMemoryArray” -namespace “root\CIMV2” -computerName $strComputer
$colRAM = Get-WmiObject -Class “win32_PhysicalMemory” -namespace “root\CIMV2” -computerName $strComputer

# Get Total Number of Memory Slots
$colSlots | ForEach {
“Total Number of Memory Slots: ” + $_.MemoryDevices
$NumSlots = $_.MemoryDevices
}

# Get Memory Installed and Size
$colRAM | ForEach {
“Memory Installed: ” + $_.DeviceLocator
“Memory Size: ” + ($_.Capacity / 1GB) + ” GB”
$SlotsFilled = $SlotsFilled + 1
$TotMemPopulated = $TotMemPopulated + ($_.Capacity / 1GB)

# Check if all Memory slots are filled or how many empty slots
If (($NumSlots – $SlotsFilled) -eq 0)
{
write-host “ALL Slots Filled, NO EMPTY SLOTS AVAILABLE!”
}
write-host ($NumSlots – $SlotsFilled) ” of ” $NumSlots ” slots Open/Available (Unpopulated)”
write-host ($SlotsFilled) ” of ” $NumSlots ” slots Used/Filled (Populated).”
write-host “”
write-host “Total Memory Populated = ” $TotMemPopulated “GB”

System Information

# Get CPU Data – system Information
$CPUSystem =  Get-WmiObject -class win32_computersystem

$cpudata = @(Get-WmiObject -class win32_processor | Select Caption, Description, NumberOfCores, NumberOfLogicalProcessors, Name, Manufacturer, SystemCreationClassName, Version)

foreach ($item in $cpudata)
{
$System_Caption = $item.caption
$System_Description = $item.Description
$System_NumberOfCores = $item.NumberOfCores
$System_NumberOfLogicalProcessors = $item.NumberOfLogicalProcessors
$System_Name = $item.Name
$System_Manufacturer = $item.Manufacturer
$System_SystemCreationClassName = $item.SystemCreationClassName
$System_Version = $item.Version
}

#Get information rgarding Server, whether it is dell server or not
write-host $CPUSystem.Manufacturer

# Get Information about Dell Servers
$CPUInfo = get-wmiobject cim_processor -namespace root\cimv2\dell -computer .

foreach ($CPUDetail in $CPUInfo)
{
$System_NumberOfCores = $CPUDetail.CoreCount
$ProcessorCount = $ProcessorCount +1
}

OS Information

# Get OS Information
$WinOS = Gwmi win32_operatingsystem -cn localhost

# Get Windows OS details
$ServerOS = (get-wmiobject win32_operatingsystem -computer localhost | select csname,caption,servicepackmajorversion).caption

# Get Windows Architecture
[System.IntPtr]::Size
if ([System.IntPtr]::Size -eq 4)
{ “32-bit” }
else
{ “64-bit” }

# Get Service Tag
$ServiceTag = (Get-WmiObject Win32_BIOS).SerialNumber

 

IP Information

#Gets IP address of the Computer
$ip= gwmi Win32_NetworkAdapterConfiguration | Where { $_.IPAddress } | Select -Expand IPAddress

# Find all active NICs and IP of the NIC and MAC Address
$computer=hostname
$Networks = gwmi Win32_NetworkAdapterConfiguration -ComputerName $computer | ? {$_.IPEnabled}
foreach ($Network in $Networks) {[string[]]$IPAddress += (“[” + $Network.IpAddress[0] + ” ” + $Network.MACAddress + “]”)}
$ActiveIPs = $IPAddress
$Networks = gwmi -ComputerName $computer win32_networkadapter | where-object { $_.physicaladapter }
foreach ($Network in $Networks)
{
[string[]]$MACinfo += “#” + $Network.DeviceID + “-” + $Network.MACAddress
}

$MACinfo

 

Disk Information

# Get Disk information
$Disks = get-WmiObject win32_logicaldisk

 

 

No Comments

Add your comment