PowerShell/Docs/check-os.md

71 lines
2.1 KiB
Markdown
Raw Normal View History

2022-12-04 10:40:18 +01:00
## The *check-os.ps1* Script
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
## Parameters
```powershell
2023-05-26 12:20:18 +02:00
/home/mf/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.
```
## Example
```powershell
PS> ./check-os
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
```
## Notes
Author: Markus Fleschutz | License: CC0
## Related Links
https://github.com/fleschutz/PowerShell
## Source Code
```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
PS> ./check-os
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" }
Write-Host "✅ $Name $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
}
```
*Generated by convert-ps2md.ps1 using the comment-based help of check-os.ps1*