Improve check-powershell.ps1

This commit is contained in:
Markus Fleschutz 2023-12-30 10:19:44 +01:00
parent c89673f442
commit e2aed21d87

View File

@ -5,23 +5,33 @@
This PowerShell script queries the PowerShell status and prints it. This PowerShell script queries the PowerShell status and prints it.
.EXAMPLE .EXAMPLE
PS> ./check-powershell.ps1 PS> ./check-powershell.ps1
PowerShell 5.1.19041.2673 Desktop edition (10 modules, 1458 cmdlets, 172 aliases) PowerShell 5.1.19041.2673 Desktop edition (1 profile, 10 modules, 1458 cmdlets, 172 aliases)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
Author: Markus Fleschutz | License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
function GetNumberOfProfiles {
[int]$count = 0
if (Test-Path $PROFILE.AllUsersAllHosts) { $count++ }
if (Test-Path $PROFILE.AllUsersCurrentHost) { $count++ }
if (Test-Path $PROFILE.CurrentUserAllHosts) { $count++ }
if (Test-Path $PROFILE.CurrentUserCurrentHost) { $count++ }
return $count
}
try { try {
$version = $PSVersionTable.PSVersion $version = $PSVersionTable.PSVersion
$edition = $PSVersionTable.PSEdition $edition = $PSVersionTable.PSEdition
$numProfiles = GetNumberOfProfiles
$numModules = (Get-Module).Count $numModules = (Get-Module).Count
$numAliases = (Get-Alias).Count $numAliases = (Get-Alias).Count
if ($IsLinux) { if ($IsLinux) {
"✅ PowerShell $version $edition edition ($numModules modules, $numAliases aliases)" "✅ PowerShell $version $edition edition ($numProfiles profile, $numModules modules, $numAliases aliases)"
} else { } else {
$numCmdlets = (Get-Command -Command-Type cmdlet).Count $numCmdlets = (Get-Command -Command-Type cmdlet).Count
"✅ PowerShell $version $edition edition ($numModules modules, $numCmdlets cmdlets, $numAliases aliases)" "✅ PowerShell $version $edition edition ($numProfiles profile, $numModules modules, $numCmdlets cmdlets, $numAliases aliases)"
} }
exit 0 # success exit 0 # success
} catch { } catch {