Private/Get-Elevation.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
function Get-Elevation { <# .SYNOPSIS Detects whether Powershell is running as administrator. .DESCRIPTION Leverages the Test-Administrator cmdlet to return whether the current PowerShell console is running as administrator. Elevation is also used in the console title. .EXAMPLE Get-Elevation -Verbose #> [CmdletBinding()] param () if (Test-Administrator) { $script:elevation = "Admin" Write-Verbose "Powershell is running as: $elevation" } else { $script:elevation = "Non-Admin" Write-Verbose "Powershell is running as: $elevation" } } |