Skip to content

Commit 596ccc3

Browse files
authored
Added help
1 parent b548e13 commit 596ccc3

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

(Code snippets)/Administrative privileges.ps1

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function AmIAdmin {
2+
<#
3+
.SYNOPSIS
4+
Returns $True when the process running this script has administrative privileges
5+
.DESCRIPTION
6+
Starting with PowerShell 4.0, the "Requires -RunAsAdministrator" directive
7+
prevents the execution of the script when administrative privileges are
8+
absent. However, there are still times that you'd like to just check the
9+
privilege (or lack thereof), e.g., to announce it to the user or downgrade
10+
script functionality gracefully.
11+
.NOTES
12+
For the Requires directive, see the "about_Requires" help page.
13+
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_requires?view=powershell-7
14+
#>
15+
$MyId=[System.Security.Principal.WindowsIdentity]::GetCurrent()
16+
$WindowsPrincipal=New-Object System.Security.Principal.WindowsPrincipal( $MyId )
17+
return $WindowsPrincipal.IsInRole( [System.Security.Principal.WindowsBuiltInRole]::Administrator )
18+
}

0 commit comments

Comments
 (0)