How to Connect to SharePoint Online using PnP PowerShell?
Requirement: Connect to SharePoint Online using PnP PowerShell.
SharePoint Patterns and Practices (PnP) for SharePoint Online is a set of PowerShell cmdlets written by the community to manage SharePoint Online efficiently. PnP PowerShell internally uses the Client-Side Object model code for its operations. With PnP PowerShell, we can reduce the number of lines in our scripts by utilizing its built-in cmdlets and reducing the complexity of scripting implementations. To connect to SharePoint Online from PnP PowerShell, here are the steps:
Proceed with Step 1 only if you need the legacy PnP Module for any backward compatibility as the PnP.PowerShell module doesn’t support SharePoint On-Premises (2013, 2016 and 2019) as of today.
Step 1: Install SharePoint Online PnP PowerShell Module
To start with PnP PowerShell, You need to download and install Windows Management Framework 5.1 from https://www.microsoft.com/en-us/download/details.aspx?id=54616, If you are running Operating Systems like Windows 7/8, Windows 2008, or Windows 2012/R2. Select the appropriate download for your operating system and restart your machine to complete the installation. On Windows 10 and later, it’s already installed.
How to install PnP PowerShell for SharePoint Online?
Open SharePoint Online Management Shell or Windows PowerShell as Administrator and Run the below command:
Install-Module SharePointPnPPowerShellOnline
Confirm the prompt, and this downloads and installs the PnP module for SharePoint Online. This module provides cmdlets that allow you to connect to and manage your SharePoint Online environment easily.
Download SharePoint Online PnP PowerShell: You can also download and install the MSI installer from GitHub: Download PnP PowerShell for SharePoint Online (MSI),
Install SharePoint Online PnP PowerShell Module, If not installed Already:
Let’s check if the PnP PowerShell module is already installed on the local machine. If not, install it!
#Check if SharePoint Online PnP PowerShell module has been installed
Try {
Write-host "Checking if SharePoint Online PnP PowerShell Module is Installed..." -f Yellow -NoNewline
$SharePointPnPPowerShellOnline = Get-Module -ListAvailable "SharePointPnPPowerShellOnline"
If(!$SharePointPnPPowerShellOnline)
{
Write-host "No!" -f Green
#Check if script is executed under elevated permissions - Run as Administrator
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Write-Host "Please Run this script in elevated mode (Run as Administrator)! " -NoNewline
Read-Host "Press any key to continue"
Exit
}
Write-host "Installing SharePoint Online PnP PowerShell Module..." -f Yellow -NoNewline
Install-Module SharePointPnPPowerShellOnline -Force -Confirm:$False
Write-host "Done!" -f Green
}
Else
{
Write-host "Yes!" -f Green
Write-host "Importing SharePoint Online PnP PowerShell Module..." -f Yellow -NoNewline
Import-Module SharePointPnPPowerShellOnline -DisableNameChecking
Write-host "Done!" -f Green
}
}
Catch{
write-host "Error: $($_.Exception.Message)" -foregroundcolor red
}
Update SharePoint Online PnP PowerShell Module
To update an existing PnP PowerShell Module, use the following:
Update-Module SharePointPnPPowerShellOnline
This solves the issues like “WARNING: A newer version of PnP PowerShell is available: 3.19.2003.0. Consider upgrading.”.
Step 2: Connect to SharePoint Online using PnP PowerShell
Once you have installed the PnP PowerShell module for SharePoint Online, the next step is to establish a connection to the SharePoint Online site. PnP PowerShell module connects to a particular SharePoint Online site collection instead of connecting to the tenant as in SharePoint Online Management Shell’s Connect-SPOService. Here is how to connect to the SharePoint Online site using PnP PowerShell:
Connect-PnPOnline -Url https://Crescent.sharepoint.com
You’ll be prompted to enter credentials to connect. Enter the user name and password to connect to your SharePoint Online site. You can use the PowerShell console or PowerShell ISE to write PowerShell scripts. You can also hard-code credentials in your script, such as:
$SiteURL="https://Crescent.sharepoint.com"
$UserName="Salaudeen@thecrescenttech.com"
$Password = "password"
$SecurePassword = ConvertTo-SecureString -String $Password -AsPlainText -Force
$Cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName, $SecurePassword
#connect to sharepoint online site using powershell
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
You can also use the client ID and client secret method to connect to SharePoint Online from PnP PowerShell: How to Connect to SharePoint Online using ClientID ClientSecret?
Permissions required to connect to SharePoint Online from PnP PowerShell: What permissions are required for you to connect to SharePoint Online from PnP PowerShell? Global Admin? Well, it depends on the cmdlet you are running. E.g., Read permissions are enough if you need to get items from a list, whereas you need tenant admin rights to create a new site collection!
Connect to SharePoint Online using PnP PowerShell MFA
You can also use -Interactive switch to connect from the currently logged-in user’s session. If there are no existing sessions found, You’ll get a browser window to login, which is MFA-aware!
Connect-PnPOnline -Url $SiteURL -UseWebLogin
In the new PnP.PowerShell, we have an improved switch “-Interactive” which can be used with multi factor authentication enabled accounts. If you get “Connect-PnPOnline : A parameter cannot be found that matches parameter name ‘Interactive’.”, that means you are not running the latest PnP PowerShell module. So, your options are either Upgrade the PnP PowerShell module or replace the “Interactive” switch with “UseWebLogin”. Once the connection is established, you can start using PnP PowerShell cmdlets. Here are some examples of using PnP PowerShell cmdlets in SharePoint Online:
Create a List or Document Library:
To create a document library in SharePoint Online using PnP PowerShell, use:
New-PnPList -Title "Team Documents" -Template DocumentLibrary
How do I create a list in PnP PowerShell? Here is an example:
New-PnPList -Title "ProjectsV3" -Template GenericList
Reference: https://pnp.github.io/powershell/cmdlets/new-pnplist.html
Create a Subsite:
New-PnPWeb -Title "emea" -Url "emea" -Template "STS#0"
SharePoint Online PnP PowerShell to Create Site Collection
Here is another example of creating a site collection using PnP PowerShell.
#Define Variables
$AdminCenterURL = "https://Crescent-admin.sharepoint.com"
$SiteURL = "https://Crescent.sharepoint.com/sites/procurement"
$SiteTitle = "Crescent Procurement Portal"
$SiteOwner = "Salaudeen@TheCrescentTech.com"
$Template = "STS#0"
$Timezone = 4
$StorageQuota = 1000
#Get Credentials to connect
$Cred = Get-Credential
#Connect to Tenant Admin
Connect-PnPOnline -URL $AdminCenterURL -Credential $Cred
#Create site collection based on given parameters
New-PnPTenantSite -Url $SiteURL -Owner $SiteOwner -Title $SiteTitle -Template $Template -TimeZone $TimeZone -StorageQuota $StorageQuota
Use Credentials from Windows Credentials Store to Connect to PnP Online:
To avoid credential popups, you can store your credentials in the Windows credentials store and connect to PnP online without a user name password prompt! Here is how:
- Open Control Panel >> Windows credential manager
- Select Windows Credentials >> Click on “Add a new Generic credential”
- Enter your SharePoint Site URL, User Name, and Password and hit save.
From now on, You can connect to PnP Online with the specified URL without the Credentials parameter. It also works for any sites underneath the given URL!
E.g.
Connect-PnPOnline -Url "https://Crescent.sharepoint.com"
SharePoint Online: Get PnP PowerShell Commands
To get all available cmdlets of PnP PowerShell, use:
Get-Command -Module SharePointPnPPowerShellOnline
There are 370 cmdlets available today in the PnP PowerShell module for SharePoint Online.
Cmdlet Name | Description |
---|---|
Add-PnPApp | Add/upload an available app to the app catalog. * Supported in SharePoint Online. |
Add-PnPPage | Adds a Client-Side Page. * Supported in SharePoint Online. |
Add-PnPPageSection | Adds a new section to a Client-Side page. * Supported in SharePoint Online. |
Add-PnPPageTextPart | Adds a text element to a client-side page. * Supported in SharePoint Online. |
Add-PnPPageWebPart | Adds a Client-Side Web Part to a client-side page. * Supported in SharePoint Online. |
Add-PnPContentType | Adds a new content type |
Add-PnPContentTypeToDocumentSet | Adds a content type to a document set |
Add-PnPContentTypeToList | Adds a new content type to a list |
Add-PnPCustomAction | Adds a custom action |
Add-PnPDataRowsToSiteTemplate | Adds datarows to a list inside a PnP Provisioning Template |
Add-PnPDocumentSet | Creates a new document set in a library. |
Add-PnPEventReceiver | Adds a new remote event receiver |
Add-PnPField | Add a field |
Add-PnPFieldFromXml | Adds a field to a list or as a site column based upon a CAML/XML field definition |
Add-PnPFieldToContentType | Adds an existing site column to a content type |
Add-PnPFile | Uploads a file to Web |
Add-PnPFileToSiteTemplate | Adds a file to a PnP Provisioning Template |
Add-PnPFolder | Creates a folder within a parent folder |
Add-PnPHtmlPublishingPageLayout | Adds an HTML based publishing page layout |
Add-PnPHubSiteAssociation | Connects a site to a hubsite. * Supported in SharePoint Online. |
Add-PnPIndexedProperty | Marks the value of the propertybag key specified to be indexed by search. |
Add-PnPJavaScriptBlock | Adds a link to a JavaScript snippet/block to a web or site collection |
Add-PnPJavaScriptLink | Adds a link to a JavaScript file to a web or site collection |
Add-PnPListFoldersToSiteTemplate | Adds folders to a list in a PnP Provisioning Template |
Add-PnPListItem | Adds an item to a list |
Add-PnPMasterPage | Adds a Masterpage |
Add-PnPNavigationNode | Adds an item to a navigation element |
Add-PnPMicrosoft365GroupToSite | Groupifies a classic team site by creating an Office 365 group for it and connecting the site with the newly created group. * Supported in SharePoint Online. |
Add-PnPSiteTemplate | Adds a PnP Provisioning Template object to a tenant template. * Supported in SharePoint Online. |
Add-PnPPublishingImageRendition | Adds an Image Rendition if the Name of the Image Rendition does not already exist. This prevents creating two Image Renditions that share the same name. |
Add-PnPPublishingPage | Adds a publishing page |
Add-PnPPublishingPageLayout | Adds a publishing page layout |
Add-PnPRoleDefinition | Adds a Role Definition (Permission Level) to the site collection in the current context |
Add-PnPSiteClassification | Adds one ore more site classification values to the list of possible values. Requires a connection to the Microsoft Graph. * Supported in SharePoint Online. |
Add-PnPSiteCollectionAdmin | Adds one or more users as site collection administrators to the site collection in the current context |
Add-PnPSiteCollectionAppCatalog | Adds a Site Collection scoped App Catalog to a site. * Supported in SharePoint Online. |
Add-PnPSiteDesign | Creates a new Site Design on the current tenant. * Supported in SharePoint Online. |
Add-PnPSiteDesignTask | This command is used to apply a published site design to a specified site collection target. It schedules the operation allowing for the application of larger site scripts (Invoke-PnPSiteDesign is limited to 30 actions and subactions). This command is intended to replace Invoke-PnPSiteDesign and is useful when you need to apply a large number of actions or multiple site scripts. * Supported in SharePoint Online. |
Add-PnPSiteScript | Creates a new Site Script on the current tenant. * Supported in SharePoint Online. |
Add-PnPStoredCredential | Adds a credential to the Windows Credential Manager |
Add-PnPTaxonomyField | Add a taxonomy field |
Add-PnPTenantCdnOrigin | Adds a new origin to the public or private content delivery network (CDN). * Supported in SharePoint Online. |
Add-PnPTenantSequence | Adds a tenant sequence object to a tenant template. * Supported in SharePoint Online. |
Add-PnPTenantSequenceSite | Adds an existing tenant sequence site object to a tenant template. * Supported in SharePoint Online. |
Add-PnPTenantSequenceSubSite | Adds a tenant sequence sub site object to a tenant sequence site object. * Supported in SharePoint Online. |
Add-PnPTenantTheme | Adds or updates a theme to the tenant. * Supported in SharePoint Online. |
Add-PnPGroupMember | Adds a user to a group |
Add-PnPView | Adds a view to a list |
Add-PnPWebhookSubscription | Adds a new Webhook subscription. * Supported in SharePoint Online. |
Add-PnPWebPartToWebPartPage | Adds a web part to a web part page in a specified zone |
Add-PnPWebPartToWikiPage | Adds a web part to a wiki page in a specified table row and column |
Add-PnPWikiPage | Adds a wiki page |
Add-PnPWorkflowDefinition | Adds a workflow definition |
Add-PnPWorkflowSubscription | Adds a workflow subscription to a list |
Invoke-PnPSiteTemplate | Applies a site template to a web |
Apply-PnPTenantTemplate | Applies a tenant template to the current tenant. * Supported in SharePoint Online. |
Approve-PnPTenantServicePrincipalPermissionRequest | Approves a permission request for the current tenant’s “SharePoint Online Client” service principal. * Supported in SharePoint Online. |
Clear-PnPDefaultColumnValues | Clear default column values for a document library |
Clear-PnPListItemAsRecord | Undeclares a list item as a record. * Supported in SharePoint Online. |
Clear-PnPRecycleBinItem | Permanently deletes all or a specific recycle bin item |
Clear-PnPTenantRecycleBinItem | Permanently deletes a site collection from the tenant-scoped recycle bin |
Connect-PnPMicrosoftGraph | Connect to the Microsoft Graph |
Connect-PnPOnline | Connect to a SharePoint site |
Convert-PnPFolderToSiteTemplate | Creates a pnp package file of an existing template xml, and includes all files in the current folder |
Convert-PnPSiteTemplate | Converts a provisioning template to another schema version |
ConvertTo-PnPPage | Converts a classic page (wiki or web part page) into a Client-Side Page. * Supported in SharePoint Online. |
Copy-PnPFile | Copies a file or folder to a different location |
Copy-PnPItemProxy | Proxy cmdlet for using Copy-Item between SharePoint provider and FileSystem provider |
Deny-PnPTenantServicePrincipalPermissionRequest | Denies a permission request for the current tenant’s “SharePoint Online Client” service principal. * Supported in SharePoint Online. |
Disable-PnPFeature | Disables a feature |
Disable-PnPInPlaceRecordsManagementForSite | Disables in-place records management for a site. |
Disable-PnPPowerShellTelemetry | Disables PnP PowerShell telemetry tracking |
Disable-PnPResponsiveUI | Deactivate the PnP Response UI add-on |
Disable-PnPSiteClassification | Disables Site Classifications for the tenant. Requires a connection to the Microsoft Graph. * Supported in SharePoint Online. |
Disable-PnPTenantServicePrincipal | Enables the current tenant’s “SharePoint Online Client” service principal. * Supported in SharePoint Online. |
Disconnect-PnPOnline | Disconnects the context |
Enable-PnPFeature | Enables a feature |
Enable-PnPInPlaceRecordsManagementForSite | Enables in place records management for a site. |
Enable-PnPPowerShellTelemetry | Enables PnP PowerShell telemetry tracking. |
Enable-PnPResponsiveUI | Activates the PnP Response UI Add-on |
Enable-PnPSiteClassification | Enables Site Classifications for the tenant. Requires a connection to the Microsoft Graph. * Supported in SharePoint Online. |
Enable-PnPTenantServicePrincipal | Enables the current tenant’s “SharePoint Online Client” service principal. * Supported in SharePoint Online. |
Export-PnPPage | Exports a Client Side Page to a PnP Provisioning Template. * Supported in SharePoint Online. |
Export-PnPTaxonomy | Exports a taxonomy to either the output or to a file. |
Export-PnPTermGroupToXml | Exports a taxonomy TermGroup to either the output or to an XML file. |
Find-PnPFile | Finds a file in the virtual file system of the web. |
Get-PnPAccessToken | Returns the current OAuth Access token |
Get-PnPApp | Returns the available apps from the app catalog. * Supported in SharePoint Online. |
Get-PnPAppAuthAccessToken | Returns the access token |
Get-PnPApp | Returns a SharePoint AddIn Instance |
Get-PnPAuditing | Get the Auditing setting of a site |
Get-PnPAuthenticationRealm | Returns the authentication realm |
Get-PnPAvailableClientSideComponents | Gets the available client side components on a particular page. * Supported in SharePoint Online. |
Get-PnPAzureADManifestKeyCredentials | Return the JSON Manifest snippet for Azure Apps |
Get-PnPAzureCertificate | Get PEM values and manifest settings for an existing certificate (.pfx) for use when using CSOM via an app-only ADAL application. |
Get-PnPClientSideComponent | Retrieve one or more Client-Side components from a page. * Supported in SharePoint Online. |
Get-PnPClientSidePage | Gets a Client-Side Page. * Supported in SharePoint Online. |
Get-PnPConnection | Returns the current context |
Get-PnPContentType | Retrieves a content type |
Get-PnPContentTypePublishingHubUrl | Returns the url to Content Type Publishing Hub |
Get-PnPContext | Returns the current context |
Get-PnPCustomAction | Return user custom actions |
Get-PnPDefaultColumnValues | Gets the default column values for all folders in document library |
Get-PnPDocumentSetTemplate | Retrieves a document set template |
Get-PnPEventReceiver | Return registered eventreceivers |
Get-PnPException | Returns the last exception that occured |
Get-PnPFeature | Returns all activated or a specific activated feature |
Get-PnPField | Returns a field from a list or site |
Get-PnPFile | Downloads a file. |
Get-PnPFolder | Return a folder object |
Get-PnPFolderItem | List content in folder |
Get-PnPGroup | Returns a specific SharePoint group or all SharePoint groups in site. |
Get-PnPGroupMember | Retrieves all members of a group |
Get-PnPGroupPermissions | Returns the permissions for a specific SharePoint group |
Get-PnPHealthScore | Retrieves the healthscore |
Get-PnPHideDefaultThemes | Returns if the default / OOTB themes should be visible to users or not. * Supported in SharePoint Online. |
Get-PnPHomePage | Return the homepage |
Get-PnPHubSite | Retrieve all or a specific hubsite. * Supported in SharePoint Online. |
Get-PnPIndexedPropertyKeys | Returns the keys of the property bag values that have been marked for indexing by search |
Get-PnPInPlaceRecordsManagement | Returns if the place records management feature is enabled. |
Get-PnPJavaScriptLink | Returns all or a specific custom action(s) with location type ScriptLink |
Get-PnPLabel | Gets the label/tag of the specfied list or library (if applicable). * Supported in SharePoint Online. |
Get-PnPList | Returns a List object |
Get-PnPListInformationRightsManagement | Get the site closure status of the site which has a site policy applied |
Get-PnPListItem | Retrieves list items |
Get-PnPListRecordDeclaration | Returns the manual record declaration settings for a list. * Supported in SharePoint Online. |
Get-PnPMasterPage | Returns the URLs of the default Master Page and the custom Master Page. |
Get-PnPNavigationNode | Returns all or a specific navigation node |
Get-PnPPowerShellTelemetryEnabled | Returns true if the PnP PowerShell Telemetry has been enabled. |
Get-PnPProperty | Returns a previously not loaded property of a ClientObject |
Get-PnPPropertyBag | Returns the property bag values. |
Get-PnPSiteTemplate | Generates a provisioning site template from a web |
Get-PnPProvisioningTemplateFromGallery | Retrieves or searches provisioning templates from the PnP Template Gallery |
Get-PnPPublishingImageRendition | Returns all image renditions or if Identity is specified a specific one |
Get-PnPRecycleBinItem | Returns the items in the recycle bin from the context |
Get-PnPRequestAccessEmails | Returns the request access e-mail addresses. * Supported in SharePoint Online. |
Get-PnPRoleDefinition | Retrieves a Role Definitions of a site |
Get-PnPSearchConfiguration | Returns the search configuration |
Get-PnPSearchCrawlLog | Returns entries from the SharePoint search crawl log. * Supported in SharePoint Online. |
Get-PnPSite | Returns the current site collection from the context. |
Get-PnPSiteClassification | Returns the defined Site Classifications for the tenant. Requires a connection to the Microsoft Graph. * Supported in SharePoint Online. |
Get-PnPSiteClosure | Get the site closure status of the site which has a site policy applied |
Get-PnPSiteCollectionAdmin | Returns the current site collection administrators of the site colleciton in the current context |
Get-PnPSiteCollectionTermStore | Returns the site collection term store |
Get-PnPSiteDesign | Retrieve Site Designs that have been registered on the current tenant. * Supported in SharePoint Online. |
Get-PnPSiteDesignRights | Returns the principals with design rights on a specific Site Design. * Supported in SharePoint Online. |
Get-PnPSiteDesignRun | Retrieves a list of site designs applied to a specified site collection. If the WebUrl parameter is not specified we show the list of designs applied to the current site. The returned output includes the ID of the scheduled job, the web and site IDs and the site design ID,version and title. * Supported in SharePoint Online. |
Get-PnPSiteDesignRunStatus | Retrieves and displays a list of all site script actions executed for a specified site design applied to a site. * Supported in SharePoint Online. |
Get-PnPSiteDesignTask | Used to retrieve a scheduled site design script. It takes the ID of the scheduled site design and the URL for the site where the site design is scheduled to be applied. * Supported in SharePoint Online. |
Get-PnPSitePolicy | Retrieves all or a specific site policy |
Get-PnPSiteScript | Retrieve Site Scripts that have been registered on the current tenant. * Supported in SharePoint Online. |
Get-PnPSiteSearchQueryResults | Executes a search query to retrieve indexed site collections |
Get-PnPStorageEntity | Retrieve Storage Entities / Farm Properties from either the Tenant App Catalog or from the current site if it has a site scope app catalog. * Supported in SharePoint Online. |
Get-PnPStoredCredential | Get a credential |
Get-PnPSubWeb | Returns the subwebs of the current web |
Get-PnPTaxonomyItem | Returns a taxonomy item |
Get-PnPTaxonomySession | Returns a taxonomy session |
Get-PnPTenant | Returns organization-level site collection properties. * Supported in SharePoint Online. |
Get-PnPTenantAppCatalogUrl | Retrieves the url of the tenant scoped app catalog. * Supported in SharePoint Online. |
Get-PnPTenantCdnEnabled | Retrieves if the Office 365 Content Delivery Network has been enabled. * Supported in SharePoint Online. |
Get-PnPTenantCdnOrigin | Returns the current registered origins from the public or private content delivery network (CDN). * Supported in SharePoint Online. |
Get-PnPTenantCdnPolicies | Returns the CDN Policies for the specified CDN (Public | Private). * Supported in SharePoint Online. |
Get-PnPTenantRecycleBinItem | Returns all modern and classic site collections in the tenant scoped recycle bin. * Supported in SharePoint Online. |
Get-PnPTenantSequence | Returns one or more provisioning sequence object(s) from a tenant template |
Get-PnPTenantSequenceSite | Returns one or more sites from a tenant template |
Get-PnPTenantServicePrincipal | Returns the current tenant’s “SharePoint Online Client” service principal. * Supported in SharePoint Online. |
Get-PnPTenantServicePrincipalPermissionGrants | Gets the collection of permission grants for the “SharePoint Online Client” service principal. * Supported in SharePoint Online. |
Get-PnPTenantServicePrincipalPermissionRequests | Gets the collection of permission requests for the “SharePoint Online Client” service principal. * Supported in SharePoint Online. |
Get-PnPTenantSite | Retrieve site information. * Supported in SharePoint Online. |
Get-PnPTenantTheme | Returns all or a specific theme. * Supported in SharePoint Online. |
Get-PnPTerm | Returns a taxonomy term |
Get-PnPTermGroup | Returns a taxonomy term group |
Get-PnPTermSet | Returns a taxonomy term set |
Get-PnPTheme | Returns the current theme/composed look of the current web. |
Get-PnPTimeZoneId | Returns a time zone ID |
Get-PnPUnifiedGroup | Gets one Office 365 Group (aka Unified Group) or a list of Office 365 Groups. * Supported in SharePoint Online. |
Get-PnPUnifiedGroupMembers | Gets members of a particular Office 365 Group (aka Unified Group). * Supported in SharePoint Online. |
Get-PnPUnifiedGroupOwners | Gets owners of a particular Office 365 Group (aka Unified Group). * Supported in SharePoint Online. |
Get-PnPUPABulkImportStatus | Get user profile bulk import status. * Supported in SharePoint Online. |
Get-PnPUser | Returns site users of current web |
Get-PnPUserProfileProperty | You must connect to the tenant admin website (https://:<tenant>-admin.sharepoint.com) with Connect-PnPOnline in order to use this cmdlet. |
Get-PnPView | Returns one or all views from a list |
Get-PnPWeb | Returns the current web object |
Get-PnPWebhookSubscriptions | Gets all the Webhook subscriptions of the resource. * Supported in SharePoint Online. |
Get-PnPWebPart | Returns a web part definition object |
Get-PnPWebPartProperty | Returns a web part property |
Get-PnPWebPartXml | Returns the web part XML of a web part registered on a site |
Get-PnPWebTemplates | Returns the available web templates. * Supported in SharePoint Online. |
Get-PnPWikiPageContent | Gets the contents/source of a wiki page |
Get-PnPWorkflowDefinition | Returns a workflow definition |
Get-PnPWorkflowInstance | Get workflow instances |
Get-PnPWorkflowSubscription | Return a workflow subscription |
Grant-PnPHubSiteRights | Grant additional permissions to the permissions already in place to associate sites to Hub Sites for one or more specific users. * Supported in SharePoint Online. |
Grant-PnPSiteDesignRights | Grants the specified principals rights to use the site design. * Supported in SharePoint Online. |
Grant-PnPTenantServicePrincipalPermission | Explicitly grants specified permission to the “SharePoint Online Client” service principal. * Supported in SharePoint Online. |
Import-PnPAppPackage | Adds a SharePoint Addin to a site |
Import-PnPTaxonomy | Imports a taxonomy from either a string array or a file |
Import-PnPTermGroupFromXml | Imports a taxonomy TermGroup from either the input or from an XML file. |
Import-PnPTermSet | Imports a taxonomy term set from a file in the standard format. |
Install-PnPApp | Installs an available app from the app catalog. * Supported in SharePoint Online. |
Install-PnPSolution | Installs a sandboxed solution to a site collection. WARNING! This method can delete your composed look gallery due to the method used to activate the solution. We recommend you to only to use this cmdlet if you are okay with that. |
Invoke-PnPQuery | Executes the currently queued actions |
Invoke-PnPSiteDesign | Apply a Site Design to an existing site. * Requires Tenant Administration Rights *. * Supported in SharePoint Online. |
Invoke-PnPWebAction | Executes operations on web, lists and list items. |
Measure-PnPList | Returns statistics on the list object – * Supported in: SharePoint Online, SharePoint 2016, SharePoint 2019. |
Measure-PnPResponseTime | Gets statistics on response time for the specified endpoint by sending probe requests |
Measure-PnPWeb | Returns statistics on the web object – * Supported in: SharePoint Online, SharePoint 2016, SharePoint 2019. |
Move-PnPClientSideComponent | Moves a Client-Side Component to a different section/column. * Supported in SharePoint Online. |
Move-PnPFile | Moves a file to a different location |
Move-PnPFolder | Move a folder to another location in the current web |
Move-PnPItemProxy | Proxy cmdlet for using Move-Item between SharePoint provider and FileSystem provider |
Move-PnPListItemToRecycleBin | Moves an item from a list to the Recycle Bin |
Move-PnPRecycleBinItem | Moves all items or a specific item in the first stage recycle bin of the current site collection to the second stage recycle bin. * Supported in SharePoint Online. |
New-PnPAzureCertificate | Generate a new 2048bit self-signed certificate and manifest settings for use when using CSOM via an app-only ADAL application. |
New-PnPExtensibilityHandlerObject | Creates an ExtensibilityHandler Object, to be used by the Get-SPOProvisioningTemplate cmdlet |
New-PnPGroup | Adds group to the Site Groups List and returns a group object |
New-PnPList | Creates a new list |
New-PnPPersonalSite | Office365 only: Creates a personal / OneDrive For Business site. * Supported in SharePoint Online. |
New-PnPSiteTemplate | Creates a new provisioning template object |
New-PnPSiteTemplateFromFolder | Generates a provisioning template from a given folder, including only files that are present in that folder |
New-PnPSite | Creates a new site collection. * Supported in SharePoint Online. |
New-PnPTenantSequence | Creates a new tenant sequence object. * Supported in SharePoint Online. |
New-PnPTenantSequenceCommunicationSite | Creates a communication site object. * Supported in SharePoint Online. |
New-PnPTenantSequenceTeamNoGroupSite | Creates a new team site without an Office 365 group in-memory object. * Supported in SharePoint Online. |
New-PnPTenantSequenceTeamNoGroupSubSite | Creates a team site subsite with no Office 365 group object. * Supported in SharePoint Online. |
New-PnPTenantSequenceTeamSite | Creates a team site object. * Supported in SharePoint Online. |
New-PnPTenantSite | Creates a new site collection for the current tenant |
New-PnPTenantTemplate | Creates a new tenant template object. * Supported in SharePoint Online. |
New-PnPTerm | Creates a taxonomy term |
New-PnPTermGroup | Creates a taxonomy term group |
New-PnPTermSet | Creates a taxonomy term set |
New-PnPUnifiedGroup | Creates a new Office 365 Group (aka Unified Group). * Supported in SharePoint Online. |
New-PnPUPABulkImportJob | Submit up a new user profile bulk import job. * Supported in SharePoint Online. |
New-PnPUser | Adds a user to the built-in Site User Info List and returns a user object |
New-PnPWeb | Creates a new subweb under the current web |
Publish-PnPApp | Publishes/Deploys/Trusts an available app in the app catalog. * Supported in SharePoint Online. |
Read-PnPSiteTemplate | Loads/Reads a PnP file from the file system |
Read-PnPTenantTemplate | Loads/Reads a PnP tenant template from the file system and returns an in-memory instance of this template. * Supported in SharePoint Online. |
Register-PnPHubSite | Registers a site as a hubsite. * Supported in SharePoint Online. |
Remove-PnPApp | Removes an app from the app catalog. * Supported in SharePoint Online. |
Remove-PnPClientSideComponent | Removes a Client-Side component from a page. * Supported in SharePoint Online. |
Remove-PnPClientSidePage | Removes a Client-Side Page. * Supported in SharePoint Online. |
Remove-PnPContentType | Removes a content type from a web |
Remove-PnPContentTypeFromDocumentSet | Removes a content type from a document set |
Remove-PnPContentTypeFromList | Removes a content type from a list |
Remove-PnPCustomAction | Removes a custom action |
Remove-PnPEventReceiver | Remove an eventreceiver |
Remove-PnPField | Removes a field from a list or a site |
Remove-PnPFieldFromContentType | Removes a site column from a content type |
Remove-PnPFile | Removes a file. |
Remove-PnPFileFromSiteTemplate | Removes a file from a PnP Provisioning Template |
Remove-PnPFolder | Deletes a folder within a parent folder |
Remove-PnPGroup | Removes a group from a web. |
Remove-PnPHubSiteAssociation | Disconnects a site from a hubsite. * Supported in SharePoint Online. |
Remove-PnPIndexedProperty | Removes a key from propertybag to be indexed by search. The key and it’s value remain in the propertybag, however it will not be indexed anymore. |
Remove-PnPJavaScriptLink | Removes a JavaScript link or block from a web or sitecollection |
Remove-PnPList | Deletes a list |
Remove-PnPListItem | Deletes an item from a list |
Remove-PnPNavigationNode | Removes a menu item from either the quicklaunch or top navigation |
Remove-PnPPropertyBagValue | Removes a value from the property bag |
Remove-PnPPublishingImageRendition | Removes an existing image rendition |
Remove-PnPRoleDefinition | Remove a Role Definition from a site |
Remove-PnPSearchConfiguration | Remove the search configuration |
Remove-PnPSiteClassification | Removes one or more existing site classification values from the list of available values. Requires a connection to the Microsoft Graph. * Supported in SharePoint Online. |
Remove-PnPSiteCollectionAdmin | Removes one or more users as site collection administrators from the site collection in the current context |
Remove-PnPSiteCollectionAppCatalog | Removes a Site Collection scoped App Catalog from a site. * Supported in SharePoint Online. |
Remove-PnPSiteDesign | Removes a Site Design. * Supported in SharePoint Online. |
Remove-PnPSiteDesignTask | Removes a Site Design Task. If the execution of the associated site script has already started the execution will not be terminated. * Supported in SharePoint Online. |
Remove-PnPSiteScript | Removes a Site Script. * Supported in SharePoint Online. |
Remove-PnPStorageEntity | Remove Storage Entities / Farm Properties from either the tenant scoped app catalog or the current site collection if the site has a site collection scoped app catalog. * Supported in SharePoint Online. |
Remove-PnPStoredCredential | Removes a credential |
Remove-PnPTaxonomyItem | Removes a taxonomy item |
Remove-PnPTenantCdnOrigin | Removes an origin from the Public or Private content delivery network (CDN). * Supported in SharePoint Online. |
Remove-PnPTenantSite | Removes a site collection. * Supported in SharePoint Online. |
Remove-PnPTenantTheme | Removes a theme. * Supported in SharePoint Online. |
Remove-PnPTermGroup | Removes a taxonomy term group and all its containing termsets |
Remove-PnPUnifiedGroup | Removes one Office 365 Group (aka Unified Group) or a list of Office 365 Groups. * Supported in SharePoint Online. |
Remove-PnPUser | Removes a specific user from the site collection User Information List |
Remove-PnPGroupMember | Removes a user from a group |
Remove-PnPView | Deletes a view from a list |
Remove-PnPWeb | Removes a subweb in the current web |
Remove-PnPWebhookSubscription | Removes a Webhook subscription from the resource. * Supported in SharePoint Online. |
Remove-PnPWebPart | Removes a web part from a page |
Remove-PnPWikiPage | Removes a wiki page |
Remove-PnPWorkflowDefinition | Removes a workflow definition |
Remove-PnPWorkflowSubscription | Remove workflow subscription |
Rename-PnPFile | Renames a file in its current location |
Rename-PnPFolder | Renames a folder |
Request-PnPReIndexList | Marks the list for full indexing during the next incremental crawl |
Request-PnPReIndexWeb | Marks the web for full indexing during the next incremental crawl |
Reset-PnPFileVersion | Resets a file to its previous version |
Resolve-PnPFolder | Returns a folder from a given site relative path, and will create it if it does not exist. |
Restore-PnPRecycleBinItem | Restores the provided recycle bin item to its original location |
Restore-PnPTenantRecycleBinItem | Restores a site collection from the tenant scoped recycle bin. * Supported in SharePoint Online. |
Resume-PnPWorkflowInstance | Resume a workflow |
Revoke-PnPSiteDesignRights | Revokes the specified principals rights to use the site design. * Supported in SharePoint Online. |
Revoke-PnPTenantServicePrincipalPermission | Revokes a permission that was previously granted to the “SharePoint Online Client” service principal. * Supported in SharePoint Online. |
Save-PnPSiteTemplate | Saves a PnP site template to the file system |
Save-PnPTenantTemplate | Saves a PnP provisioning hierarchy to the file system. * Supported in SharePoint Online. |
Send-PnPMail | Sends an email using the Office 365 SMTP Service or SharePoint, depending on the parameters specified. See detailed help for more information. |
Set-PnPAppSideLoading | Enables the App SideLoading Feature on a site |
Set-PnPAuditing | Set Auditing setting for a site |
Set-PnPAvailablePageLayouts | Sets the available page layouts for the current site |
Set-PnPPage | Sets parameters of a Client-Side Page. * Supported in SharePoint Online. |
Set-PnPClientSideText | Set Client-Side Text Component properties. * Supported in SharePoint Online. |
Set-PnPClientSideWebPart | Set Client-Side Web Part properties. * Supported in SharePoint Online. |
Set-PnPContext | Set the ClientContext |
Set-PnPDefaultColumnValues | Sets default column values for a document library |
Set-PnPDefaultContentTypeToList | Sets the default content type for a list |
Set-PnPDefaultPageLayout | Sets a specific page layout to be the default page layout for a publishing site |
Set-PnPDocumentSetField | Sets a site column from the available content types to a document set |
Set-PnPField | Changes one or more properties of a field in a specific list or for the whole web |
Set-PnPFileCheckedIn | Checks in a file |
Set-PnPFileCheckedOut | Checks out a file |
Set-PnPGroup | Updates a group |
Set-PnPGroupPermissions | Adds and/or removes permissions of a specific SharePoint group |
Set-PnPHideDefaultThemes | Defines if the default / OOTB themes should be visible to users or not. * Supported in SharePoint Online. |
Set-PnPHomePage | Sets the home page of the current web. |
Set-PnPHubSite | Sets hubsite properties. * Supported in SharePoint Online. |
Set-PnPIndexedProperties | Marks values of the propertybag to be indexed by search. Notice that this will overwrite the existing flags, i.e. only the properties you define with the cmdlet will be indexed. |
Set-PnPInPlaceRecordsManagement | Activates or deactivates in the place records management feature. |
Set-PnPLabel | Sets a label/tag on the specified list or library. * Supported in SharePoint Online. |
Set-PnPList | Updates list settings |
Set-PnPListInformationRightsManagement | Get the site closure status of the site which has a site policy applied |
Set-PnPListItem | Updates a list item |
Set-PnPListItemAsRecord | Declares a list item as a record. * Supported in SharePoint Online. |
Set-PnPListItemPermission | Sets list item permissions |
Set-PnPListPermission | Sets list permissions |
Set-PnPListRecordDeclaration | The RecordDeclaration parameter supports 4 values: AlwaysAllowManualDeclaration, NeverAllowManualDeclaration, UseSiteCollectionDefaults. * Supported in SharePoint Online. |
Set-PnPMasterPage | Set the masterpage |
Set-PnPMinimalDownloadStrategy | Activates or deactivates the minimal downloading strategy. |
Set-PnPPropertyBagValue | Sets a property bag value |
Set-PnPSiteTemplateMetadata | Sets metadata of a provisioning template |
Set-PnPRequestAccessEmails | Sets Request Access Emails on a web. * Supported in SharePoint Online. |
Set-PnPSearchConfiguration | Sets the search configuration |
Set-PnPSite | Sets Site Collection properties. * Supported in SharePoint Online. |
Set-PnPSiteClosure | Opens or closes a site which has a site policy applied |
Set-PnPSiteDesign | Updates a Site Design on the current tenant. * Supported in SharePoint Online. |
Set-PnPSitePolicy | Sets a site policy |
Set-PnPSiteScript | Updates an existing Site Script on the current tenant. * Supported in SharePoint Online. |
Set-PnPStorageEntity | Set Storage Entities / Farm Properties in either the tenant scoped app catalog or the site collection app catalog. * Supported in SharePoint Online. |
Set-PnPTaxonomyFieldValue | Sets a taxonomy term value in a listitem field |
Set-PnPTenant | Sets organization-level site collection properties. * Supported in SharePoint Online. |
Set-PnPTenantCdnEnabled | Enables or disabled the public or private Office 365 Content Delivery Network (CDN). * Supported in SharePoint Online. |
Set-PnPTenantCdnPolicy | Sets the CDN Policies for the specified CDN (Public | Private). * Supported in SharePoint Online. |
Set-PnPTenantSite | Set site information. * Supported in SharePoint Online. |
Set-PnPTheme | Sets the theme of the current web. |
Set-PnPTraceLog | Turn log tracing on or off |
Set-PnPUnifiedGroup | Sets Office 365 Group (aka Unified Group) properties. * Supported in SharePoint Online. |
Set-PnPUserProfileProperty | Office365 only: Uses the tenant API to retrieve site information. |
Set-PnPView | Change view properties |
Set-PnPWeb | Sets properties on a web |
Set-PnPWebhookSubscription | Updates a Webhook subscription. * Supported in SharePoint Online. |
Set-PnPWebPartProperty | Sets a web part property |
Set-PnPWebPermission | Set permissions |
Set-PnPWebTheme | Sets the theme of the current web. * Supported in SharePoint Online. |
Set-PnPWikiPageContent | Sets the contents of a wikipage |
Start-PnPWorkflowInstance | Starts a workflow instance on a list item |
Stop-PnPWorkflowInstance | Stops a workflow instance |
Submit-PnPSearchQuery | Executes an arbitrary search query against the SharePoint search index |
Test-PnPListItemIsRecord | Checks if a list item is a record. * Supported in SharePoint Online. |
Test-PnPOffice365GroupAliasIsUsed | Tests if a given alias is already used used. * Supported in SharePoint Online. |
Test-PnPTenantTemplate | Tests a tenant template for invalid references |
Uninstall-PnPApp | Uninstalls an available add-in from the site |
Uninstall-PnPApp | Removes an app from a site |
Uninstall-PnPSolution | Uninstalls a sandboxed solution from a site collection |
Unpublish-PnPApp | Unpublishes/retracts an available add-in from the app catalog. * Supported in SharePoint Online. |
Unregister-PnPHubSite | Unregisters a site as a hubsite. * Supported in SharePoint Online. |
Update-PnPApp | Updates an available app from the app catalog. * Supported in SharePoint Online. |
Update-PnPSiteClassification | Updates Site Classifications for the tenant. Requires a connection to the Microsoft Graph. * Supported in SharePoint Online. |
To connect to Azure AD with PowerShell, Install the PowerShell module for Azure Active Directory “Install-Module AzureAD”. Once installed, you can connect to Azure AD using “Connect-AzureAD”.
More info: Connect to Azure AD in PowerShell
Install the PowerShell module for Microsoft Teams using “Install-Module -Name MicrosoftTeams”. Once installed, you can connect to Teams using “Connect-MicrosoftTeams”
More info: Connect to Teams from PowerShell
Yes, You can use the SharePoint Online Management Shell to connect to SharePoint Online. More info: How to connect to SharePoint Online using PowerShell?
Hello,
After applying the “Connect-PnPOnline” Cmdlt I got this error message “Host not reachable”. Please how do solve this problem?
Thank you.
If you are connecting to Azure on the same script, try connecting to SharePoint first using Connect-PnPOnline cmdlet. Also, Try updating your PnP.Powershell module.
Nice content very helpful!
I’m getting Error “Connect-PnpOnline : Parameter set cannot be resolved using the specified named parameters.”
This is because: You have Multi-Factor Authentication (MFA) enabled. To fix this error, use the -Interactive parameter. E.g.
Connect-PnPOnline -Url https://yourdomain.sharepoint.com -Interactive
You’ll get a prompt to enter your credentials.