2024-11-08 12:38:20 +01:00
|
|
|
The *check-os.ps1* Script
|
|
|
|
===========================
|
2022-12-04 10:40:18 +01:00
|
|
|
|
2023-05-26 12:20:18 +02:00
|
|
|
This PowerShell script queries the operating system status and prints it.
|
2022-12-04 10:40:18 +01:00
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
2022-12-04 10:40:18 +01:00
|
|
|
```powershell
|
2024-11-08 12:35:11 +01:00
|
|
|
/home/markus/Repos/PowerShell/scripts/check-os.ps1 [<CommonParameters>]
|
2022-12-04 10:40:18 +01:00
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Example
|
|
|
|
-------
|
2022-12-04 10:40:18 +01:00
|
|
|
```powershell
|
2023-08-06 21:36:33 +02:00
|
|
|
PS> ./check-os.ps1
|
2024-11-08 12:35:11 +01:00
|
|
|
✅ Windows 10 Pro 64-bit since 6/22/2021 (v10.0.19045, S/N 00123-45678-15135-AAOEM, P/K AB123-CD456-EF789-GH000-WFR6P)
|
2022-12-04 10:40:18 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Notes
|
|
|
|
-----
|
2022-12-04 10:40:18 +01:00
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Related Links
|
|
|
|
-------------
|
2022-12-04 10:40:18 +01:00
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Script Content
|
|
|
|
--------------
|
2022-12-04 10:40:18 +01:00
|
|
|
```powershell
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
2023-05-26 12:20:18 +02:00
|
|
|
Checks the OS status
|
2022-12-04 10:40:18 +01:00
|
|
|
.DESCRIPTION
|
2023-05-26 12:20:18 +02:00
|
|
|
This PowerShell script queries the operating system status and prints it.
|
2022-12-04 10:40:18 +01:00
|
|
|
.EXAMPLE
|
2023-08-06 21:36:33 +02:00
|
|
|
PS> ./check-os.ps1
|
2024-11-08 12:35:11 +01:00
|
|
|
✅ Windows 10 Pro 64-bit since 6/22/2021 (v10.0.19045, S/N 00123-45678-15135-AAOEM, P/K AB123-CD456-EF789-GH000-WFR6P)
|
2022-12-04 10:40:18 +01:00
|
|
|
.LINK
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
.NOTES
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
#>
|
|
|
|
|
|
|
|
try {
|
|
|
|
if ($IsLinux) {
|
2023-05-26 12:20:18 +02:00
|
|
|
$Name = $PSVersionTable.OS
|
|
|
|
if ([System.Environment]::Is64BitOperatingSystem) { $Arch = "64-bit" } else { $Arch = "32-bit" }
|
2023-12-07 20:24:45 +01:00
|
|
|
Write-Host "✅ $Name (Linux $Arch)"
|
2022-12-04 10:40:18 +01:00
|
|
|
} else {
|
|
|
|
$OS = Get-WmiObject -class Win32_OperatingSystem
|
2023-05-26 12:20:18 +02:00
|
|
|
$Name = $OS.Caption -Replace "Microsoft Windows","Windows"
|
2022-12-04 10:40:18 +01:00
|
|
|
$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
|
2023-05-26 12:20:18 +02:00
|
|
|
|
|
|
|
$ProductKey = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" -Name BackupProductKeyDefault).BackupProductKeyDefault
|
2024-11-08 12:35:11 +01:00
|
|
|
Write-Host "✅ $Name $Arch since $($InstallDate.ToShortDateString()) (v$Version, S/N $Serial, P/K $ProductKey)"
|
2022-12-04 10:40:18 +01:00
|
|
|
}
|
|
|
|
exit 0 # success
|
|
|
|
} catch {
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2024-11-20 11:52:20 +01:00
|
|
|
*(generated by convert-ps2md.ps1 as of 11/20/2024 11:51:51)*
|