Created
December 3, 2018 16:27
-
-
Save jbaker10/f808a9b03b70d5651ad223700439ed5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Getting currently logged in user" | |
$user = '{0}\{1}' -f $env:USERDOMAIN, $env:USERNAME | |
"Working with user account: " + $user | |
$user_members = Get-LocalGroupMember -Group Administrators | |
if ($user_members.Name -like $user) { | |
$user + " is already a member of the Administrators group" | |
} | |
else { | |
"Promoting user to Administrators group" | |
Add-LocalGroupMember -Group Administrators -Member $user | |
if($?) { | |
"User was added to the Administrators group" | |
} | |
else { | |
"Something went wrong when adding the user to the Admins group." | |
exit 1 | |
} | |
} | |
#Value Description | |
#0 Show OK button. | |
#1 Show OK and Cancel buttons. | |
#2 Show Abort, Retry, and Ignore buttons. | |
#3 Show Yes, No, and Cancel buttons. | |
#4 Show Yes and No buttons. | |
#5 Show Retry and Cancel buttons. | |
#http://msdn.microsoft.com/en-us/library/x83z1d9f(v=vs.84).aspx | |
$prompt = new-object -comobject wscript.shell | |
$answer = $prompt.popup("You have been granted admin rights for the next 15 minutes. Please use it wisely.",60,"Datadog Corp IT",0) #first number is timeout, second is display. | |
Start-Sleep -s 900 | |
$user_members = Get-LocalGroupMember -Group Users | |
if ($user_members.Name -like $user) { | |
$user + " is already a member of the Users group" | |
} | |
else { | |
"Adding user to Users group" | |
Add-LocalGroupMember -Group Users -Member $user | |
if($?) { | |
"User was added to the users group" | |
} | |
else { | |
"Something went wrong when adding the user to the Users group. Will not demote" | |
exit 1 | |
} | |
} | |
"Removing user from Admins group" | |
Remove-LocalGroupMember -Group Administrators -Member $user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment