PowerShell: Check Windows OS Version

Here is a PowerShell script to get the OS details of Windows Machines. The script makes use of CIM cmdlets. The script also provides uptime information.

function Get-cOSInfo
PowerShell script to collect OS information

Get the OS, edition, and build version of Windows Servers

.PARAMETER ComputerName
Accepts a list of computer names or IP addresses

Get-cOSInfo -ComputerName Server1,server2

# A computer name or list of computer names
[string[]]$ComputerName = 'localhost',
$Credential = [System.Management.Automation.PSCredential]::Empty

$outObject = @()
foreach ($computer in $ComputerName)
$tempObject = Get-CimInstance Win32_OperatingSystem -ComputerName $computer -ErrorAction STOP |
Select-Object @{Name='ComputerName';Expression={$_.CSName}},
@{Name='Operating System';Expression={$_.Caption}},
@{Name='Uptime';Expression={"{0:N0} days {1:N0} hours" -f `
($_.LocalDateTime - $_.LastBootUpTime).Days, `
($_.LocalDateTime - $_.LastBootUpTime).Hours}}
$outObject += $tempObject
return $outObject



Popular posts from this blog

Check SQL Server Database Status

PowerShell and Azure Resource Graph

Static Code Analysis: Some Tools