PowerShell/Scripts/check-powershell.ps1

30 lines
833 B
PowerShell
Raw Normal View History

2022-12-01 09:50:58 +01:00
<#
.SYNOPSIS
2023-01-23 14:04:23 +01:00
Check the PowerShell
2022-12-01 09:50:58 +01:00
.DESCRIPTION
2023-01-23 14:04:23 +01:00
This PowerShell script queries PowerShell details and lists it.
2022-12-01 09:50:58 +01:00
.EXAMPLE
PS> ./check-powershell
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
$Version = $PSVersionTable.PSVersion
$Edition = $PSVersionTable.PSEdition
$NumModules = (Get-Module).Count
$NumAliases = (Get-Alias).Count
2022-12-04 10:11:52 +01:00
if ($IsLinux) {
2023-01-23 14:04:23 +01:00
$Reply = "✅ PowerShell $Version ($Edition edition, $NumModules modules, $NumAliases aliases)"
2022-12-04 10:11:52 +01:00
} else {
$NumCmdlets = (Get-Command -Command-Type cmdlet).Count
2023-01-23 14:04:23 +01:00
$Reply = "✅ PowerShell $Version ($Edition edition, $NumModules modules, $NumCmdlets cmdlets, $NumAliases aliases)"
2022-12-04 10:11:52 +01:00
}
2023-01-23 14:04:23 +01:00
Write-Host $Reply
2022-12-01 09:50:58 +01:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
2023-01-01 19:22:35 +01:00
}