Tip

How to change Office 365 user passwords via PowerShell

Whether you’re managing Exchange Server or Windows Server, password management is an important task for any administrator. The song remains the same for Office 365. Because Microsoft gives you better control of Office 365’s features and functions at the command line, you should know the commands you’ll need to change users’ passwords from there, as well as how to set them to never expire when the situation warrants it.


Carrying out administrative tasks using Office 365’s Web-based GUI is in many ways more difficult than managing them in Windows. In Windows, you’re responsible for a wide range of configuration tabs that house all the properties associated with each user. Dealing with them in

    Requires Free Membership to View

Office 365 adds the extra overhead of the Web, plus you have to wait for Web pages to refresh.

Office 365’s administrative console is essentially a “skin” for PowerShell commands that perform the actual work. Any user management that can be performed via the GUI can also be done at the command line -- if you’ve got the right commands.

Two common activities associated with users are changing their passwords and, for the privileged few, setting passwords to never expire. By default, Office 365 requires user passwords to be changed every 90 days. In my experience, this can be a nuisance when excessive security isn’t of utmost importance.

Changing a user’s password requires knowing his UserPrincipalName, which maps to the primary login credential associated with said user. For most users, the UserPrincipalName looks like the following: userName@domain.onmicrosoft.com.

Armed with that info, you can use the following PowerShell command to change the user’s password:

Set-MsolUserPassword -UserPrincipalName username@domain.onmicrosoft.com -NewPassword "P@ssw0rd!"

In certain cases, you might not need to change a password to anything specific, but instead to a random value. Office 365 can supply that random password for you by eliminating the –NewPassword argument. The cmdlet looks like this:

Set-MsolUserPassword -UserPrincipalName username@domain.onmicrosoft.com

After running the above command, Office 365 will display the password it generates, which you can then share with your users.

With a tip of the hat to security best practices, there occasionally comes a time when a user’s account shouldn’t undergo a regular password change. Using Office 365’s PowerShell, you can set those passwords to never expire with the following command:

Get-MsolUser -UserPrincipalName username@domain.onmicrosoft.com | Set-MsolUser -PasswordNeverExpires $true

Note that the command actually sets the user’s PasswordNeverExpiresproperty to $true. If you want to verify whether a user’s password will expire or not, use the following command:

Get-MsolUser -UserPrincipalName username@domain.onmicrosoft.com |fl *

In the list that appears, look for the PasswordNeverExpires property. You’ll find it along with the surprisingly short list of other user properties that Office 365 tracks.

ABOUT THE AUTHOR:
Greg Shields,
MVP, is a partner and principal technologist with Concentrated Technology. An IT industry analyst, author, speaker and trainer, you can find Greg at www.concentratedtech.com.

This was first published in June 2012

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.