In the course of Slalom helping clients move to the Office 365 cloud, I routinely use Powershell and it's SharePoint Online cmdlets (Office 365 & Azure AD cmdlets too!) to help manage their Tenant, both before and after migrations. While the UI contains all the tools for managing an instance, it immediately becomes tedious to click through the same actions for more than a few actions.
While the amount of cmdlets are lagging in quantity in comparison to On-Premises SharePoint, we are given several that can help us save deployment and management time. Below we'll walk through getting connected and then doing routine query transactions.
--Getting started
To get started there a few prerequisites needed to start connecting with SharePoint Online. You can connect from either a desktop or server, depending on where you have access to.
- Install PowerShell 3.0, if it's not already present (Server 2012 or Windows 8)
- Install the SharePoint Online Management Shell, which will have the cmdlets we need
- URL of your SharePoint Online Admin center (e.g. "http://ift.tt/1o7xudm", etc.)
- An Office 365 account that has Global Administrator privileges
After all these are installed, launch the SharePoint Online Management shell as this removes the need to run the Import-Module cmdlet. Here's the code we'll be working from in this example.
--Connect to SharePoint Online with credentials
Now that we're ready with the SharePoint Online shell, the first thing we need to do is create a Credential object. On Line 1 below we call the Get-Credential cmdlet which pops a logon box for us to put our "xxx@xxx.onmicrosoft.com" and password, pushing that into an object for later use. I then create a variable to store my Admin URL on Line 2 as well.
Using the above variables I then call the Connect-SPOService cmdlet on Line 3 passing them in to create a connection. Running this now should return the command prompt with no errors, which means it connected successfully. Note, with these online cmdlets no errors means success. Red error text will show in the shell if there is an error, which means one of the variables are not correct so just check them again for accuracy.
--Pull Tenant information
With our connection to our Admin Tenant locked in, the first query cmdlet to call is Get-SPOTenant on line 5 which will output a list of all the Tenant property's that have been set including quota's and sharing status.
--Pull all Site Collection's
The next cmdlet we'll test is the Get-SPOSite one on Line 7 that pulls all our Site Collection's the way I have it setup with the current piping, or you can tell it just one that you want to look at by adding in the target URL before the -Detailed property. Looking at the results returned, we can see last Modified Date, individual quotas, it's Title, and of course the sharing status.
--Pull all users for a Site Collection
Now that we have our list of Site Collection URL's, we can see all our users within that collection. On Line 9 we create a variable for reuse later with our target URL, then on Line 10 we call Get-SPOUser passing in that Site Collection URL variable. From the output below we can see that we were returned a list of all the users in our Site Collection along with their Login Names and any SharePoint Security Groups they're attached to. This can be very useful for checking who is in which SharePoint Security Groups for you site.
--Pull all Security Groups for a Site Collection
And finally, we can query a specific SharePoint Security Group to see all the individual users if we need to pull out all that have been created. On Line 12 we call Get-SPOSiteGroup again passing in the Site Collection URL variable. This final output shows us all the Groups, including Owners logins for managing and the users inside of them. Another great way to check on your security settings.
Using these SharePoint Online cmdlets is a quick and repeatable way to query your Tenant to ensure security and settings are correct. There are of course Add-xxx, Set-xxx, and Remove-xxx cmdlets to complement the Get-xxx ones I detailed above for making changes to your SharePoint Online instance during or after migration.
References:
- PowerShell for Office 365
- TechNet - Introduction to the SharePoint Online management shell
- Microsoft Downloads
-
- PowerShell 3.0 - http://ift.tt/1pvHhYK
- SharePoint Online Management Shell - http://ift.tt/1U6C1uf
- Code Repository - OneDrive
-
- http://1drv.ms/1ISmdDj (Managing_SharePointOnline_with_Powershell.ps1)
by Craig Pilkenton via Everyone's Blog Posts - SharePoint Community
No comments:
Post a Comment