PowerShell WMI – Querying System Informations

Hi Guys,

Here is a small function I wrote to gather the System basic informations.
[ps]Function Get-SystemInfo {
<#
.SYNOPSIS
Query WMI of the system to provide basic system information.

.PARAMETER ComputerName
The computer name or IP of targeted computer.

.NOTES
Author: Thomas Prud’homme (Twitter: @prudhommewtf).

.LINK
https://blog.prudhomme.wtf/powershell-wmi-querying-system-informations
#>
[CmdletBinding()]
Param(
[String]$ComputerName = $env:COMPUTERNAME
)
Begin {
# Win32_ComputerSystem: http://msdn.microsoft.com/en-us/library/aa394102(VS.85).aspx
$Win32_ComputerSystem = Get-WmiObject -Namespace root\CIMV2 -Class Win32_ComputerSystem -Property Domain, DomainRole, Name, NumberOfProcessors, TotalPhysicalMemory -ComputerName $ComputerName
}
Process {
Write-Verbose -Message ‘System gathered information:’
$Output = @()
$Win32_ComputerSystem | ForEach-Object {
switch ($_.DomainRole) {
0 {
$ComputerRole = ‘Standalone Workstation’
$DomainType = ‘workgroup’
}
1 {
$ComputerRole = ‘Member Workstation’
$DomainType = ‘domain’
}
2 {
$ComputerRole = ‘Standalone Server’
$DomainType = ‘workgroup’
}
3 {
$ComputerRole = ‘Member Server’
$DomainType = ‘domain’
}
4 {
$ComputerRole = ‘Domain Controller’
$DomainType = ‘domain’
}
5 {
$ComputerRole = ‘Domain Controller (PDC Emulator)’
$DomainType = ‘domain’
}
default {
$ComputerRole = ‘Unknown’
$DomainType = ‘unknown’
}
}

$SystemInformation = New-Object -TypeName PSObject -Property @{
Domain = $_.Domain
DomainRole = $_.DomainRole
Name = $_.Name
FullyQualifiedDomainName = if ($DomainType -ieq ‘domain’) {
[String]::Join(‘.’,@($_.Name, $_.Domain))
} else {
$_.Name
}
NumberOfProcessors = $_.NumberOfProcessors
TotalPhysicalMemoryBytes = $_.TotalPhysicalMemory
ComputerRole = $ComputerRole
DomainType = $DomainType
}

$SystemInformation.psobject.Properties | ForEach-Object {
Write-Verbose -Message "`t$($_.Name): $($_.Value)"
}

$Output += $SystemInformation
}
}
End {
Write-Output -InputObject $Output
}
}[/ps]

See you,