diff options
author | Dag Wieers <dag@wieers.com> | 2017-01-27 23:23:18 +0100 |
---|---|---|
committer | Matt Davis <nitzmahone@users.noreply.github.com> | 2017-01-27 14:23:18 -0800 |
commit | c94c53e8a47b4d84026de35cbd7832572b6b434a (patch) | |
tree | bd8f1bc63988bd29919c8aa04173a72391a207e0 /examples | |
parent | 63b1e0c277fd19f651bd925386f7fcb9d1e89cfb (diff) | |
download | ansible-c94c53e8a47b4d84026de35cbd7832572b6b434a.tar.gz |
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
Diffstat (limited to 'examples')
-rw-r--r-- | examples/scripts/ConfigureRemotingForAnsible.ps1 | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/examples/scripts/ConfigureRemotingForAnsible.ps1 b/examples/scripts/ConfigureRemotingForAnsible.ps1 index 4c609a771c..e9e15bbfe6 100644 --- a/examples/scripts/ConfigureRemotingForAnsible.ps1 +++ b/examples/scripts/ConfigureRemotingForAnsible.ps1 @@ -1,3 +1,5 @@ +#Requires -Version 3.0 + # Configure a Windows host for remote management with Ansible # ----------------------------------------------------------- # @@ -113,6 +115,22 @@ Trap Exit 1 } $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 If (-Not $EventSource) { |