In this webinar, our experts showcase a variety of demo use cases of how different components of the...
In today's blog, we'll go over how to use PowerShell to manage your Microsoft Office 365 environment. You may ask yourself "Why would I want to use PowerShell when Microsoft already gives me a graphical user interface to work with?" Well, the front end of the user interface is nice for simple tasks, but the real power of Office 365 lives in the Cmdlets of PowerShell. Those commands will help you manage your domain.
Note: PowerShell has a lot to offer in the way of automation. Like any new computer language you learn, there is learning curve and it is sometimes easy to get lost. Hang in there! After learning the basic Cmdlets, you will start seeing for yourself how useful solutions can be created.
So, let's get set up for the trip!
You will also need to download and install these files:
Once you have met the prerequisites above, you're ready to actually connect to your Office365 domain. Here is the script you will need to run:
Import-Module MSOnline
$O365Cred = Get-Credential
$O365Session = New-PSSession –ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365Cred -Authentication Basic -AllowRedirection
Import-PSSession $O365Session -AllowClobber
Connect-MsolService –Credential $O365Cred
So, what's going on here? Here's the breakdown, line-by-line:
Easy, right?
WARNING: Depending on your granted access, you could easily cause havoc in the system if you're not careful. Be mindful of the power you have at your fingertips. If you ever have doubt about what a command might do, use the –whatif parameter available with most Cmdlets to make sure.
Okay, so you're connected. Now what? Introducing Get-Msoluser! This is one handy command. It returns the following information about all the users in your organization:
UserPrincipalName
DisplayName
isLicensed
Now, say you only want to look for user with a 't' somewhere in their name. Use: Get-MsolUser -SearchString "t".
You can also pipe Get-MsolUser output into another command such as Remove-MsolUser. For instance, say you're doing some cleanup of accounts. You can use this command to delete all accounts with 'Sunshine' in their name: Get-MsolUser –SearchString "Sunshine"| Remove-MsolUser
What you DON'T what to use is this: Get-MsolUser | Remove-MsolUser. That would delete your entire organization! Remember, with great power comes great responsibility. This goes back to the warning about being careful.
Stay tuned for upcoming blogs on other useful Powershell Cmdlets. Looking for more tips and tricks on working with Office 365 instead? We've got plenty of great blogs on the topic.
That's all for now!
Happy CRM'ing!