I have a list of Office 365 users that I want to reset the passwords for. I would like to reset the password for each user and then output the username and password to a CSV file.
Using the Set-MsolUserPassword cmdlet only returns the password, so I'm a bit stuck.
So far, this is what I have:
[Reflection.Assembly]::LoadWithPartialName("System.Web")
foreach ( $name in $names ) {
$newPassword = $([System.Web.Security.Membership]::GeneratePassword(9,1))
Set-MsolUserPassword -UserPrincipalName $name.UserPrincipalName -ForceChangePassword 1 -NewPassword $newPassword -TenantId $tenID
}
This returns a long list of passwords. What I would like it to do is return a CSV file containing $name.UserPrincipalName and $newPassword.