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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.