Office 365 & Exchange Online Password PowerShell Commands

The Admin Centres for Office 365 and for Exchange Online are great for simple and singular tasks regarding password management and policy, however, if you wish to carry wider tasks or bulk user management PowerShell is the best option. You can manage multiple domains simultaneously, or script the commands to include a CSV file of as many users as you require.

Set an Office 365 or Exchange Online user password so that it never expires

Set-MsolUserUserPrincipalName user.name@serviceteamit.co.uk -PasswordNeverExpires $True

This option turns off password expiry policy so that the user password never expires.

Set an Office 365 or Exchange Online user password so that it expires

Set-MsolUser -UserPrincipalName user.name@serviceteamit.co.uk -PasswordNeverExpires $False

This option turns on password expiry policy so that the user password expires according to the policy.

Enable password policy in Office 365 or Exchange Online

Get-MsolUser | Set-MsolUserPasswordNeverExpires $False

This option turns on password policy for all users so that the user passwords never expire.

Disable password policy in Office 365 or Exchange Online

Get-MsolUser | Set-MsolUserPasswordNeverExpires $True

This option turns off password policy for all users so that the user passwords expire according to the policy.

Set the Office 365 or Exchange Online Password Policy

Set-MsolPasswordPolicy -DomainName serviceteamit.co.uk -NotificationDays 14 -ValidityPeriod 90

This option sets the password policy for the domain serviceteamit.co.uk to a valid password period of 90 days and notify the user 14 days prior to expiry.

Create a new password for a user in Office 365 or Exchange Online

Set-MsolUserPassword -UserPrincipalName user.name@serviceteamit.co.uk -NewPassword An3wPa55w0rd -ForceChangePassword $False

This option sets the password to the chosen password An3wPa55w0rd for the named user user.name@serviceteamit.co.uk.

Create a new password for all users in Office 365 or Exchange Online

Get-MsolUser |%{Set-MsolUserPassword -UserPrincipalName $_.UserPrincipalName –NewPassword An3wPa55w0rd -ForceChangePassword $False}

This options sets the password to the chosen password An3wPa55w0rd for all users.

Set a new password for all users in Office 365 or Exchange Online with a CSV

  1. Create your CSV or export your user list from Office 365 or Exchange Online:
    Get-MsolUser | Select -All|Export-CSV C:serviceteamitcustomersuser_export.csv

    This option exports the user list in a handy CSV saving to the path C:serviceteamitcustomersuser_export.csv.

  2. Create unique passwords for all your users via your favourite bulk password generator.
  3. Import your CSV to Office 365 or Exchange Online:
    Import-CSV –Path C:serviceteamitcustomersuser_import.csv| ForEach-Object { Set-MsolUserPassword -UserPrincipalName $_.UserPrincipalName –NewPassword $_.NewPassword -ForceChangePassword $True }

    This option imports the user list from the the path C:serviceteamitcustomersuser_import.csv and requires users reset their password when they first login. You can download a sample CSV file Office 365 & Exchange Online sample CSV user_import.csv.

You can find additional information regarding passwords in this post. If you have any questions or need a little more in-depth help please get in touch.

With over 20 years of experience, Serviceteam IT design and deliver sophisticated connectivity, communication, continuity, and cloud services, for organisations that need to stay connected 24/7. We take the time to fully understand your current challenges, and provide a solution that gives you a clear understanding of what you are purchasing and the benefits it will bring you.

To find out how we can help you, call us on 0121 468 0101, use the Contact Us form, or why not drop in and visit us at 49 Frederick Road, Edgbaston, Birmingham, B15 1HN.

We’d love to hear from you!

1 reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply