solshare.net
Sign in or Join. Username:   Password:   (forgot password?)     Submit

Education

Automating PowerShell scripts that require credentials

A few days ago a customer asked me about automating the CSV_Parser.ps1 script to create and manage mailboxes.  They wanted to run this script against an updating csv file containing student identity information on a scheduled basis.  Followers of this blog will know that when I demo PowerShell, I explicitly run through all of the steps required to get things motoring...manually entering in admin credentials and then whatever comes next.  This is fine... but you may have been wondering what to do if you want to hard-code your admin credentials so that you do not have to enter them manually.

I was interested in knowing how to do this as well... so I asked someone that had a clue, Richard Wakeman, for his input.  He recommended not making modifications to the CSV_Parser script, but instead create a short script to capture the credentials and then call the CSV_Parser script from within that.  An example of what this looks like is below:

# capture the admin LiveID username in a variable

$Username = "admin@yourdomain.edu"

# capture the admin LiveID password in a variable.  Note, that it is stored as a secure string

$Password = ConvertTo-SecureString 'YourPassword' -AsPlainText -Force

# populate the $Livecred PowerShell credential with $Username and $Password

$Livecred = New-Object System.Management.Automation.PSCredential $Username, $Password

# call the CSV_Parser.ps1 file in a new shell, feeding in the usual parameters

./CSV_Parser.PS1 –UsersFile “C:\Source\users.csv” -RemoteURL https://ps.exchangelabs.com/powershell -LiveCredential $Livecred -LogDirectory "C:\Logging\" -LogVerbose $true -ValidateAction $true

# Gracefully remove the runspace so as not to leave any orphaned connections

Get-RunSpace | Remove-RunSpace

So there you have it...happy automating!

Jonny

Published Tuesday, November 18, 2008 4:07 PM by Live@Edu Blog

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 
Submit
SSN Program Home | Terms of Use | Privacy Statement
© Copyright 2008 Microsoft Corporation. All rights reserved.