1

I have a script that I use to automate AD and Office 365 account provisioning. Everything is working just fine.

The only "problem" is that I have a regular domain account and another account which is a Domain Admin.

Is there any way I can load and execute the AD module as another user? So that I just receive a Credentials prompt, login with my Domain Admin account and the script continues.

Right now I just run the Powershell Console as another user.

Thank you.

1 Answer 1

1

You cannot load a whole module as another user however you can run individual commands.

For example:

# Load ActiveDirectory module
Import-Module ActiveDirectory

# Save creds securely for this session
$admin = Get-Credential

# Run cmdlet as the admin user
New-ADUser -Credential $admin

# Pull user as the admin user
Get-ADUser -Credential $admin

Keep in mind that this will only work if the cmdlet supports the -Credential parameter, if it does not you'll have to run PowerShell in a context where the correct credentials are used.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .