Skip navigation
Office 365 Patterns and Practices PowerShell Commands

Office 365 Patterns and Practices PowerShell Commands

By now you have heard about the great project that Microsoft and the Community have been working on called “Patterns and Practices”. If not, then you must have been sleeping J

This project is Microsoft’s way of creating samples and documentation of how things should be done within the Office 365 space. It is intended to help us create better solutions, and adhere to the best practice and recommended approaches designated by those at Microsoft who actually work on the products themselves. The project is stored within GitHub allowing for anyone to access to the source as well as fork a local copy if needed. There are three core GitHub repository forks that are available.

To access the repositories, we can simply browse the GitHub site using the links provided.

To be able to utilize this code and build the setup’s, you will first need to download and install the following items.

WIX Toolset: http://wix.codeplex.com/

Windows Management Framework v4.0: http://www.microsoft.com/en-us/download/details.aspx?id=40855

Once these are downloaded and installed we are ready to go. If you are just simply wanting to install the PowerShell components, then you can simply download the created MSI’s from here:

https://github.com/officedev/pnp-powershell/releases

To just use the PowerShell commands, simply download the one that you need. For this we will download the “SharePointPnPPowerShellOnline.msi”, though you could download them all as needed.

Once we have it downloaded we can run the MSI themselves which is short and sweet and installs what is needed. Next we need to load a PowerShell Window, we will use the SharePoint One, and run one of the following commands (if your OS is Windows 10):

  • SharePoint 2013: Install-Module SharePointPnPPowerShell2013
  • SharePoint 2016: Install-Module SharePointPnPPowerShell2016
  • SharePoint Online: Install-Module SharePointPnPPowerShellOnline

If you are some other operating system, like my Windows Server 2012 R2, then you will need to run the following command:

Invoke-Expression (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/OfficeDev/PnP-PowerShell/master/Samples/Modules.Install/Install-SharePointPnPPowerShell.ps1')

This command will download what is needed and run you through an installer.

From this you will need to select the version that you wish to setup, for this we will use the SharePoint Online version which is the default.

Continue the wizard and install all that is needed.

Now that it is all installed, we can run a simple command to see what options are available.

To begin using the SharePoint Online Commands, you first need to set some credentials. If you use the same ones often you can store them within the Windows Credential manager and use those later.

Once you are connected then you can use any of the new PowerShell commands to create, update, delete and read from the SharePoint Online site. Using the “Get-SPOList” will grab the core lists from within the connected Site Collection that was used within the “Connect-SPOnline”.

As you can see so far I have only ran two commands to retrieve this list, where normally I would have run multiple commands to connect to SharePoint Online, Access the SPSite and SPWeb objects along with iterating the SPList objects.

One of the purposes of these commands is to not only show you in the code how to write successful PowerShell Cmdlets but also are provided to make our life a little easier by either providing methods that don’t exist within the core SharePoint On-Premises or Online products or enhance what is there to reduce the amount of PowerShell we have to write.

A great example of this would be creating a new list.

New-SPOList -Title "Sample PnP Docs" -Template DocumentLibrary -Url "SamplePnPDocs"

To see a full list of all the commands, what they do and how to use them, you can visit this link.

https://github.com/OfficeDev/PnP-PowerShell/blob/master/Documentation/readme.md

All in all, the Patterns and Practices PowerShell commands are a great addition when using SharePoint Online or SharePoint On-Premises.

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish