Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to test my Exchange 2010 service from a remote untrusted domain, in an automated script. That means I need to create client credentials and save them, and I can't follow traditional commands to get the creds interactively.

How would I script the following commands to test connectivity using specified credentials?

share|improve this question

Here's a function I wrote to generate a new credential object:

function New-Credential {
        [string]$user = 'domain\user'
    process {
        New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $password

You can get the password as a System.SecureString in a number of ways (here's one way), or you can just use the function like this:

$cred = New-Credential -user somedomain\someuser -password ('somepassword' | ConvertTo-SecureString -AsPlainText -force)

Run 'Help ConvertTo-SecureString -Full' for more details on why you need the -asplaintext and -force parameters).

I hope this is what you're looking for.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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