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

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Featured Post

The Retro Powershell - Looking good in 8-Bit | Part 1

I wrote a little script that, when placed in your PowerShell Profile, will print a message similar to the old boot message you got from you...