mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-24 17:03:45 +01:00
77 lines
2.2 KiB
Markdown
77 lines
2.2 KiB
Markdown
The *check-os.ps1* Script
|
|
===========================
|
|
|
|
This PowerShell script queries the operating system status and prints it.
|
|
|
|
Parameters
|
|
----------
|
|
```powershell
|
|
/home/markus/Repos/PowerShell/scripts/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 since 6/22/2021 (v10.0.19045, 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 since 6/22/2021 (v10.0.19045, 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 since $($InstallDate.ToShortDateString()) (v$Version, S/N $Serial, P/K $ProductKey)"
|
|
}
|
|
exit 0 # success
|
|
} catch {
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
exit 1
|
|
}
|
|
```
|
|
|
|
*(generated by convert-ps2md.ps1 as of 11/20/2024 11:51:51)*
|