By default, AD cmdlets use your current credentials. This is great and handy (I can just run Get-QADUser
as the new command and it will work) but quite often you might want to specify another username/password. For example, when what you are planning to do requires a privileged account and the default account with which you logged in is just a Domain User.
Well, as usual, Connect-QADService
is here to help. There are two ways you can specify the credentials. As a username/password pair:
$pw = read-host "Enter password" -AsSecureString
connect-QADService -service 'server.company.com'-ConnectionAccount 'company\administrator'-ConnectionPassword $pw
Or use the Get-Credential
cmdlets which will display the familiar dialog box:
Connect-QADService -service 'server.company.com' -Credential ( Get-Credential )
Once you’ve run any of those all your subsequent AD cmdlets run under this new account until you run Disconnect-QADService which removes the connection and brings you back to the defaults:
Connect-QADService -service 'server.company.com' -Credential ( Get-Credential )
# now we are using the specified credentials
Get-QADUser
Disconnect-QADService
# now we are back to the current account
Tags: oneliner, AD cmdlets, cmdlets, one-liner, PowerShell, AD, Active Directory, Examples
Like this:
Like Loading...