Get the ForceChangePassword Office 365 User Setting with PowerShell
Recently I was asked by a friend if I knew of a way to get the value of the setting that forces a user to change their password when the next log in to Office 365. The friend wanted to get this value for all users using PowerShell.
Changing this setting is fairly straight forward either in the Office 365 portal or using the Set-MsolUserPassword cmdlet in the MSOnline PowerShell module:
However retrieving the current value of the setting isn’t possible using Get-MoslUser cmdlet - the attribute does not appear in the returned object:
Instead, we need to use the Get-AzureADUser cmdlet in the AzureAD PowerShell Module to query the Azure Active Directory for the Office 365 tenant.
If you don’t have the AzureAD module installed, use Install-Module cmdlet to install it from the PowerShell Gallery:
Then connect to the AzureAD using the Connect-AzureAD cmdlet. Once connected you can run the following command to get the user object and show only the appropriate property (ForceChangePasswordNextLogin of the PasswordProfile object):
If you wanted to get a list of all users with the ForceChangePasswordNextLogin property set to true then you could use:
This is all fairly straight forward once you figure out which object in Azure AD contains the information required.