PowerShell/docs/check-os.md

77 lines
2.2 KiB
Markdown
Raw Normal View History

2024-01-25 13:37:12 +01:00
Script: *check-os.ps1*
========================
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
2023-07-29 10:15:44 +02:00
PS> ./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
2023-05-26 12:20:18 +02:00
✅ 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)
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
2023-05-26 12:20:18 +02:00
✅ 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)
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
Write-Host "✅ $Name $Arch (v$Version, since $($InstallDate.ToShortDateString()), 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-03-27 17:36:59 +01:00
*(generated by convert-ps2md.ps1 using the comment-based help of check-os.ps1 as of 03/27/2024 17:36:24)*