Office 365 User Management with PowerShell

Unity Connect Amsterdam

I am so excited to be speaking at Unity Connect Amsterdam 2015! BTW, you get a discount if you register with “McDer10”. I am getting my content together for my session Managing Office 365 with PowerShell and thought I’d share a tip that saves me TONS of times when working with a new demo tenant. With a little tweak I know this can be used in production too, more about that at the end.

Change All Your Demo Users Passwords

I use Microsoft Office Demos for my Office 365 demo sites because I get a fully fleshed out demo for 90 days. When that expires I set up a new one. When the provisioning completes I get an email with the “default password”, but if anyone in the audience knows this process (and they are evil and mean spirited) they can do terrible things to me and my demo. When I login for the first time as the Administrator I change the password, but I needed a quick way to change the passwords for the 25 accounts that get created. Here is my script. You should only have to edit the $adminuser and $newpassword variables. Then run the script in the Windows PowerShell or Windows Azure Active Directory Module for Windows PowerShell.

#Get the administrator user account

$adminuser = "admin@myo365site.onmicrosoft.com"
#Get the NEW password for your users

$newpasswd = "foo@12345"
# This will pop-up a dialog and request your password

$cred = Get-Credential -Credential $adminuser
#——– Import the Local Microsoft Online PowerShell Module Cmdlets and Connect to O365 Online ———–

Import-Module MSOnline
Connect-MsolService -Credential $cred
#Enumerate all users except Administrator

Get-MsolUser | Where-Object {$_.UserPrincipalName -ine $adminuser} | foreach{
#Set their Password to something known

    Write-Host "Setting:" $_.UserPrincipalName
    Set-MsolUserPassword UserPrincipalName $_.UserPrincipalName NewPassword $newpasswd -ForceChangePassword $false | Out-Null
}

What About Production

I suppose there could come a day when you actually need to change all the user passwords. Like, if you are running the Office 365 site for Ashley Madison. In that case just change "-ForceChangePassword $false" to $true. When your users login with new the $newpasswd they will be prompted to change their password.

I’d love to see you in Amsterdam! Remember the discount code!

|| Office 365 || PowerShell

comments powered by Disqus

Let's Get In Touch!


Ready to start your next project with us? That’s great! Give us a call or send us an email and we will get back to you as soon as possible!

+1.512.539.0322