Living a SharePoint life

Wednesday, February 1, 2017

Code Snippet: Load the SharePoint Office PnP Module in PowerShell

How do you load the PowerShell OfficeP PnP module for SharePoint?

Addendum: I've added a try/catch block to the code. This way you can be sure the module is loaded.

# Loading Office Online PnP Module
try {
    if((Get-Module "Microsoft.Online.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
        Import-Module Microsoft.Online.SharePoint.PowerShell
        Write-Host "PowerShell module Microsoft.Online.SharePoint.PowerShell initialized"
    }
    else {
        Write-Host "PowerShell module Microsoft.Online.SharePoint.PowerShell loaded"
    }
}
catch {
    throw "PowerShell module Microsoft.Online.SharePoint.PowerShell initialization failed"
    exit 3
}

Featured Post

How are Microsoft Search quota consumed?

With Office 365 Search, Microsoft has created a central entry point for the modern workplace. In one convenient spot, users can access all ...