Obtain SharePoint Online URL for Connect-SPOService

This goes under the category “mostly useless”, but nevertheless is an interesting example. Hardcoding stuff in scripts is never a good thing, so why not obtain the correct URL using the tools we already have (apart from copy/paste that is).

Turns out the information about all accessible endpoints can be found using the Get-MsolCompanyInformation cmdlet. It’s not immediately visible, but if you know what you are looking for, it’s easy enough to obtain.

Obviously, we will need the MSOnline module for this. Once the module is installed (and loaded if you are still on v2), you can run the Get-MsolCompanyInformation to obtain some basic information about your Office 365 tenant, such as address and contact information. Once you show the ‘hidden’ properties however, things get a bit more interesting:

Get-MsolCompanyInformation | fl *

In this case, what we are looking for is the ServiceInformation parameter. Depending on which services you have, you will see RMSOnline and/or CRMOnline and/or SharePoint Online listed there. The actual endpoints are few levels deeper, listed under ServiceElements -> ServiceParameters -> ServiceParameter:

$SPOURL = (Get-MsolCompanyInformation).ServiceInformation.ServiceElements.ServiceParameters.ServiceParameter | ? {$_.Name -eq "RootAdminUrl"}

Using this, you can generalize your Office 365 connect script in a way that you only need to provide a set of credentials, instead of having to manually edit/specify endpoints. The ServiceInstanceInformation is also useful, it gives you the Lync/Excahnge endpoints.

)

This entry was posted in Office 365, PowerShell, SharePoint Online. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *