mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Ensure that the script is run with elevated privileges (#20669)
* Ensure that the script is run with elevated privileges This fixes #20654 * Implement our own check for elevated privileges
This commit is contained in:
parent
63b1e0c277
commit
c94c53e8a4
1 changed files with 18 additions and 0 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
#Requires -Version 3.0
|
||||||
|
|
||||||
# Configure a Windows host for remote management with Ansible
|
# Configure a Windows host for remote management with Ansible
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
#
|
#
|
||||||
|
@ -113,6 +115,22 @@ Trap
|
||||||
Exit 1
|
Exit 1
|
||||||
}
|
}
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# Get the ID and security principal of the current user account
|
||||||
|
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
|
||||||
|
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
|
||||||
|
|
||||||
|
# Get the security principal for the Administrator role
|
||||||
|
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
|
||||||
|
|
||||||
|
# Check to see if we are currently running "as Administrator"
|
||||||
|
if (-Not $myWindowsPrincipal.IsInRole($adminRole))
|
||||||
|
{
|
||||||
|
Write-Host "ERROR: You need elevated Administrator privileges in order to run this script."
|
||||||
|
Write-Host " Start Windows PowerShell by using the Run as Administrator option."
|
||||||
|
Exit 2
|
||||||
|
}
|
||||||
|
|
||||||
$EventSource = $MyInvocation.MyCommand.Name
|
$EventSource = $MyInvocation.MyCommand.Name
|
||||||
If (-Not $EventSource)
|
If (-Not $EventSource)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue