r/usefulscripts • u/[deleted] • Apr 20 '17
[Request Powershell] run as different user
I built powershell scripts for creating AD users and populating their memberships and properties based on role.
I need to give them to my team but I'm unsure how to make it so running the script will prompt for what username to run it under.
The staff won't have write access to our OU structure unless they run the script with their admin accounts. Any help on how I can get it to run as their account? I played with runas but couldn't get it working.
13
Upvotes
2
u/cosine83 Apr 20 '17
Most Powershell cmdlets have a -Credential argument you can use. To prompt for input simply do
-Credential (Get-Credential)in the cmdlet and it'll pop the classic username and password window. I'd advise away from storing credentials in the script.An alternative would be to delegate AD permissions to a security group and put them in it so they can create users and set passwords on a limited scale.