Sometimes I need to change the password for a Azure AD user, and set the password to never expire. Usually for a service account. Here is how you can do this with PowerShell:
# Clear the shell cls
# Installing the AzureAD module Install-Module AzureAD
Write-Host “First you must login with your AzureAD admin account” -fore Yellow
# Connecting to AzureAD Connect-AzureAD
# Creating a variable for the user $user = Read-host “What is the users e-mail address?”
# Ask for the new password $pwd = Read-Host “Please type in the new password” -AsSecureString
# Setting the new password for the account Set-AzureADUserPassword -ObjectId $user -Password $pwd
# Make the password never expire Set-AzureADUser -ObjectId $user -PasswordPolicies DisablePasswordExpiration
# Will the users password expire? Get-AzureADUser -ObjectId $user | Select-Object UserprincipalName,@{ N=”PasswordNeverExpires”;E={$_.PasswordPolicies -contains “DisablePasswordExpiration”} }
Write-Host “This script is finished” -fore Green
Comments