PoSH: Connecting to an Remote Domain

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
Advertisements
This entry was posted in Programming and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s