DISCLAIMER: The following is pretty much the worst way to do this when it comes to security. Putting plain-text passwords into anything is always a bad idea and I highly recommend using the method described by TechNet at this link to secure your scripts. That said, because I have to keep my scripts in a state that makes them as simple as possible for the next guy to come along and use, here is how to use plain text passwords to connect to an Active Directory Domain.
I’ve already posed my script to Inventory Active Directory. One other that I use here is just a variation that includes a snippet to connect to another domain that we inventory.
In order to inventory this second domain, I simply create a PSCredential object and feed it into a Connect-QADService command from the Quest Powertools. Here is the snippet:
#Connect to other domain $ServiceAcct = "DOMAIN\account" $ServicePass = ConvertTo-SecureString "password" -AsPlainText -Force $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $ServiceAcct, $ServicePass Connect-QADService -Service 'DOMAIN' -Credential $cred | Out-Null