Reset a password using PowerShell

A couple of customers have asked me about this one in the last few hours.  A currently undocumented ability with Remote PowerShell and Exchange Labs/LiveID is the ability to reset a password.
 
The command is simply:
set-mailbox -identity user@example.edu -password pass1234
 
In context of everything you need to do to get this running for all you PowerShell newbies out there:

:Connect to Exchange Labs Runspace
1. $LiveCred = Get-Credential
2. $rs = New-Runspace -Shell Microsoft.Exchange -ConnectionUri
https://ps.exchangelabs.com/powershell/ -Credential $LiveCred  -Authentication Basic
3. push-runspace $rs

:Reset the password
4. set-mailbox -identity user@example.edu -password pass1234 

:Gracefully exit runspace
5. pop-runspace
6. Remove-Runspace $rs

You will get a message : "WARNING: The command completed successfully but no settings of ‘user@example.edu’ have been modified."  This can be ignored however.

Happy scripting!

Jonny

Advertisements

4 Responses to Reset a password using PowerShell

  1. Hseu says:

    How does this work with mashed life? Particularly the open-sourced password tools at:
     
    http://mashedlife.com/tools.php
     
    I try to use the best of 2 worlds.
     
    Thanks

  2. US LiveAtedu says:

    @Shoemaker
     
    I have not tried this with mashedlife, so I will keep this at a high level.
     
    There are 2 ways that you can interact programmatically with Exchange Labs/LiveID through Live@edu.  These are Remote PowerShell and Exchange Web Services.  You could therefore easily integrate those services with whatever method you prefer.
     
    Jonny

  3. Michael says:

    This works well if I enter step #4 with the actual values.  If I try step #4 using variables previously defined, like:set-mailbox -identity $id -password $pwI get the error:Invoke-Command : Accessing variables other than $PSCulture, $PSUICulture, $true, $false, $null is not permitted in the data language…+         Invoke-Command <<<<  -Runspace $rs {set-mailbox -identity $id -password $pw}

  4. US LiveAtedu says:

    @MrPurcell:
    To feed in parameters, you need to covert the password string to a secure string… commands below:
     
    $Username = "admin@mydomain.com"$Password = ConvertTo-SecureString \’MyPassword\’ -AsPlainText -Force $Livecred = New-Object System.Management.Automation.PSCredential $Username, $Password

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

%d bloggers like this: