mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-21 23:43:25 +01:00
77 lines
2.2 KiB
Markdown
77 lines
2.2 KiB
Markdown
Script: *check-os.ps1*
|
|
========================
|
|
|
|
This PowerShell script queries the operating system status and prints it.
|
|
|
|
Parameters
|
|
----------
|
|
```powershell
|
|
PS> ./check-os.ps1 [<CommonParameters>]
|
|
|
|
[<CommonParameters>]
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
```
|
|
|
|
Example
|
|
-------
|
|
```powershell
|
|
PS> ./check-os.ps1
|
|
✅ Windows 10 Pro 64-bit (v10.0.19045, since 6/22/2021, S/N 00123-45678-15135-AAOEM, P/K AB123-CD456-EF789-GH000-WFR6P)
|
|
|
|
```
|
|
|
|
Notes
|
|
-----
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
Related Links
|
|
-------------
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
Script Content
|
|
--------------
|
|
```powershell
|
|
<#
|
|
.SYNOPSIS
|
|
Checks the OS status
|
|
.DESCRIPTION
|
|
This PowerShell script queries the operating system status and prints it.
|
|
.EXAMPLE
|
|
PS> ./check-os.ps1
|
|
✅ Windows 10 Pro 64-bit (v10.0.19045, since 6/22/2021, S/N 00123-45678-15135-AAOEM, P/K AB123-CD456-EF789-GH000-WFR6P)
|
|
.LINK
|
|
https://github.com/fleschutz/PowerShell
|
|
.NOTES
|
|
Author: Markus Fleschutz | License: CC0
|
|
#>
|
|
|
|
try {
|
|
if ($IsLinux) {
|
|
$Name = $PSVersionTable.OS
|
|
if ([System.Environment]::Is64BitOperatingSystem) { $Arch = "64-bit" } else { $Arch = "32-bit" }
|
|
Write-Host "✅ $Name (Linux $Arch)"
|
|
} else {
|
|
$OS = Get-WmiObject -class Win32_OperatingSystem
|
|
$Name = $OS.Caption -Replace "Microsoft Windows","Windows"
|
|
$Arch = $OS.OSArchitecture
|
|
$Version = $OS.Version
|
|
|
|
[system.threading.thread]::currentthread.currentculture = [system.globalization.cultureinfo]"en-US"
|
|
$OSDetails = Get-CimInstance Win32_OperatingSystem
|
|
$BuildNo = $OSDetails.BuildNumber
|
|
$Serial = $OSDetails.SerialNumber
|
|
$InstallDate = $OSDetails.InstallDate
|
|
|
|
$ProductKey = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" -Name BackupProductKeyDefault).BackupProductKeyDefault
|
|
Write-Host "✅ $Name $Arch (v$Version, since $($InstallDate.ToShortDateString()), S/N $Serial, P/K $ProductKey)"
|
|
}
|
|
exit 0 # success
|
|
} catch {
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
exit 1
|
|
}
|
|
```
|
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of check-os.ps1 as of 05/19/2024 10:25:18)*
|