PowerShell is cool. I don’t quite understand how it all works just yet, I am still learning PowerShell. Here is some quick advice before we move on, don’t fall in love with a cmdlet because they have been known to disappear from time to time. Having said all that PowerShell is extremely powerful for managing your Office 365 environment. I have been focusing on PowerShell basics lately, and how to get going with Office 365. In this blog I’d like to cover how to connect to Office 365 and add a domain using strictly PowerShell. In a few previous blogs, I performed these same things through the GUI
http://365unity.com/?p=60 and http://365unity.com/?p=96
First off before you can use the Office 365 cmdlets there are a few requirements you must meet.
- You must be running Windows 7, Windows 8 or Windows 8.1
- .Net Framework 3.5.1 Should be installed
- The Microsoft Online Assistant should be installed (http://www.microsoft.com/en-ca/download/details.aspx?id=28177)
- This software sits in the background and assists with logging Lync and Outlook onto Office 365
- Windows Azure Active Directory Module for Windows PowerShell (https://bposast.vo.msecnd.net/MSOPMW/Current/amd64/AdministrationConfig-en.msi)
If you struggled with the last step and wanted to yank out your hair because you were sure you installed the right version of Microsoft Online Assistant. Read this
You need to install the Microsoft Online Assistant Services Sign-In Assistant Beta (http://www.microsoft.com/en-my/download/details.aspx?id=39267)…They have not fixed this in over a year, I am not sure why.
Once the Beta version of Sign-In Assistant is installed you can install the Azure Active Directory Module for PowerShell. Once installed we’re ready to connect to Office 365 via PowerShell
Connecting to Office 365
The first thing we are going to do is run the Windows Azure Active Directory Module for Windows PowerShell
The first PowerShell cmdlet we are going to use here is on that will allow us to connect to the domain
When it connects successfully, we will not see a confirmation. To validate if you are in properly you can run a cmdlet such as
get-msoldomain and it should return at least your company.onmicrosoft.com
Perfect, we’ve validated that we’ve connected to Office 365 via PowerShell.
Add a Domain to Office 365 via PowerShell
Now we are going to add our domain to Office 365. If you’ve read my other blogs, there are 4 steps to adding a domain and through PowerShell it’s no different
- Add Domain
- Get Verification DNS record
- Add DNS record to DNS provider
- Validate ownership of the domain
Firstly we are going to add the domain
New-MSOLDomain -Authentication Managed -Name 365unity.com
You will notice that the Status is set to unverified. This will be fixed in the next two commands.
Get-MSOLDomainVerificationDNS -domainname 365unity.com -Mode DNSTxtRecord (You could also use DNSMxRecord here, but TXT is easiest)
Copy the DNS TXT record info and create the record with the DNS provider hosting your domain name, in my case it’s GoDaddy.
Now we can confirm that we own the domain, this step may take up to an hour depending on your TTL setting.
Confirm-MSOLDomain -DomainName 365unity.com
and we should get a successfully validated message.
Now to make sure that it works, we can run Get-MSOLDomain and we should see that its status changed to verified
What I really like about PowerShell is that it skips all of the wizards and let’s you do what you want to do. What can be intimidating about it is you may not know all of the commands available to you. I am often using tab to run through all of the possible commands based on a first few letters.