Reset password for single user
#Connect to MSOnline.
Connect-MsolService;
$Acc = read-host 'Email address of user need reset password'
$NewPassword= read-host 'Enter new password for users'
Set-MsolUserPassword -UserPrincipalName $Acc -NewPassword $NewPassword -ForceChangePassword $false;
Get-PSSession | Remove-PSSession
#End
Reset password for multiple users
Create users list
#Create users list
mkdir C:\Temp; ii C:\Temp;
New-Item -Path "C:\temp\Users.csv" -ItemType File;
Add-Content "C:\temp\Users.csv" "UserName";
notepad.exe .\Users.csv
#End
Reset users password
#Connect to MSOnline
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force;
Install-PackageProvider -Name NuGet -Force;
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted;
Install-Module -Name MSOnline;
Connect-MsolService;
$NewPassword= read-host 'Enter new password for users'
Import-Csv -Path "C:\Temp\Users.csv" |
ForEach { Set-MsolUserPassword -UserPrincipalName $_.UserName -NewPassword $NewPassword -ForceChangePassword $false}
Get-PSSession | Remove-PSSession
#End
Edit the script
If you want to force user change their account password in the first time sign in, let using
-ForceChangePassword $true
instead of
-ForceChangePassword $false
5/5 - (1 vote)