Hello Folks, This piece of the article talks about getting started with PnP PowerShell which applies to SharePoint 2013/2016 as well as SharePoint Online to manage the SharePoint environment remotely via PowerShell Scripting as the commands use CSOM.
If you take PowerShell which means in simple terms you are going to automate some repetitive admin-related tasks which help to ease the job of developers/admins drastically.
To get started, the first thing is to set up the environment. There are certain steps to be followed for the setup.
- Installation
There are 2 ways to install the cmdlets. We recommend, where possible, installing them from the PowerShell Gallery. Check out the “Getting Started with the Gallery” section to make sure you have all requirements in place.
Alternatively, you can download the setup files and install the cmdlets directly.
- PowerShell Gallery
If your main OS is Windows 10, or if you have PowerShellGet installed, you can run the following commands to install the PowerShell cmdlets:
SharePoint Version | Command to install |
SharePoint Online | Install-Module SharePointPnPPowerShellOnline |
SharePoint 2016 | Install-Module SharePointPnPPowerShell2016 |
SharePoint 2013 | Install-Module SharePointPnPPowerShell2013 |
If your System is running with PowerShell Version 3 or 4, you’ll get an error stating below when you try executing the SharePoint Online Command,
Run this command to check the version of your PowerShell installed in your system
$PSVersionTable.PSVersion
To get that sorted out, you’ll need to install the PackageManagement PowerShell Modules Preview – March 2016 to proceed forward
The preview release includes PackageManagement (previously known as OneGet) and PowerShellGet Windows PowerShell modules. The versions of these modules include the functionality of those that shipped with WMF 5.0.
The preview also installs exclusively on systems running Windows PowerShell 4 or Windows PowerShell 3 only. This preview will not install on any systems running Windows PowerShell 5 (including Windows 10) which already ship with these modules.
If you plan to move to Windows PowerShell 5, we advise you to skip installing this preview and instead install our WMF 5.0 or upgrade to Windows 10.
After successful installation of PackageManagement PowerShell Modules Preview – March 2016 in the server, proceed forward
For this demo, I’ll be using Windows 10 as base OS. Open PowerShell ISE from your Windows 10 machine
Execute this command for SharePoint Online in the PowerShell Editor
Install-Module SharePointPnPPowerShellOnline
It gives a popup stating PowerShellGet Requires NuGet Provider version ‘2.8.5.201’ or newer to interact with NuGet-based repositories.
Click “Yes” to install the NuGetProvider Packet Management
PowerShell will download the DLL from the oneget.org site
During the process, you get a popup stating that you are installing the modules from an untrusted repository
Click “Yes” to proceed.
The SharePointPnPPowerShellOnline package will start getting installed
After successful installation, verify the installed module by running this command
Get-Module SharePointPnPPowerShell* -ListAvailable | Select-Object Name,Version | Sort-Object Version -Descending
PS C:\WINDOWS\system32> Get-Module SharePointPnPPowerShell* -ListAvailable | Select-Object Name,Version | Sort-Object Version -Descending
Name Version
—- ——-
SharePointPnPPowerShellOnline 3.2.1810.0
Here is how you can connect to a SharePoint Online Site using PnP PowerShell
Connect-PnPOnline -Url https://o365cr7.sharepoint.com -Credentials (Get-Credential)
And enter the credentials to connect to the site
Once you are connected to the SharePoint online site you can perform numerous operations like Create, Read, Update, Delete operations, and a lot more. To see the available cmdlets for the installed PnP module, execute this command,
Get-Command -Module *PnP*
PS C:\WINDOWS\system32> Get-Command -Module *PnP*
CommandType | Name | Version | Source |
Alias | Connect-PnPHubSite | 3.2.1810.0 | SharePointPnPPowerShellOnline |
Alias | Disconnect-PnPHubSite | 3.2.1810.0 | SharePointPnPPowerShellOnline |
Alias | Ensure-PnPFolder | 3.2.1810.0 | SharePointPnPPowerShellOnline |
Alias | Execute-PnPQuery | 3.2.1810.0 | SharePointPnPPowerShellOnline |
Alias | Load-PnPProvisioningTemplate | 3.2.1810.0 | SharePointPnPPowerShellOnline |
Function | Disable-PnpDevice | 1.0.0.0 | PnpDevice |
Function | Enable-PnpDevice | 1.0.0.0 | PnpDevice |
Function | Get-PnpDevice | 1.0.0.0 | PnpDevice |
Function | Get-PnpDeviceProperty | 1.0.0.0 | PnpDevice |
Cmdlet | Add-PnPApp | 3.2.1810.0 | SharePointPnPPowerShellOnline |
Cmdlet | Add-PnPClientSidePage | 3.2.1810.0 | SharePointPnPPowerShellOnline |
Cmdlet | Add-PnPClientSidePageSection | 3.2.1810.0 | SharePointPnPPowerShellOnline |
Cmdlet | Add-PnPClientSideText | 3.2.1810.0 | SharePointPnPPowerShellOnline |
Cmdlet | Add-PnPClientSideWebPart | 3.2.1810.0 | SharePointPnPPowerShellOnline |
Hope this article will be helpful to get started with PnP PowerShell in SharePoint Online or SharePoint 2016/2013.
You may like the following PowerShell tutorials:
- Connect to SharePoint Online Site using PowerShell
- How to perform IIS backup and restore using PowerShell
- How to use PnP PowerShell in SharePoint Online
- The term Get-SPweb is not recognized as the name of a cmdlet function script file or operable program error in SharePoint PowerShell
I’m a SharePoint Consultant with extensive experience in SharePoint/Office 365 and related technologies and I’m currently based out of Coimbatore (India).
hello sir,
thanks for giving that type of information.
Change your topic to only in SharePoint online