top of page
Tomas Bjerved

Change password for Azure AD user with PowerShell

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




23 views0 comments

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page