Get-Aduser -Credential passthrough RRS feed

  • Question

  • I am trying to run something similar on one of our servers

    get-aduser -Identity [name] -Server "DC.domain.local" -Credential

    However, the server I am trying to query is on a different domain (there is a trust setup) and I don't want to keep having to type my password in each time every time this query is executed.

    Is there a way I can pass the username and password in that command so its more automated?

    Thursday, September 14, 2017 12:15 PM

All replies

  • You can create a PSCredential object, then pass that to the Credential parameter. Only problem with this, is you now have the username and password in clear text within the script. If someone was able to read the script, you now have an exposed username/password

    $secpasswd = ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force
    $mycreds = New-Object System.Management.Automation.PSCredential ("username", $secpasswd)
    Get-ADUser -Identity [name -Server "DC.domain.local" -Credential $mycreds

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Thursday, September 14, 2017 2:08 PM