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:

Update: The step-1 installs the legacy PnP PowerShell Module SharePointPnPPowerShellOnline – which is archived and no longer maintained! To install the latest version of PnP PowerShell module PnP.PowerShell, refer: How to Install PnP PowerShell for SharePoint Online?
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.

install sharepoint online pnp powershell module

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 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

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 using the Connect-PnPOnline cmdlet:

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 the 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:

  1. Open Control Panel >> Windows credential manager
  2. Select Windows Credentials >> Click on “Add a new Generic credential”
  3. Enter your SharePoint Site URL, User Name, and Password and hit save.
    pnp powershell save credentials to avoid password prompt

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 PnP commands available today in the PnP PowerShell module for SharePoint Online.

Cmdlet NameDescription
Add-PnPAppAdd/upload an available app to the app catalog. * Supported in SharePoint Online.
Add-PnPPageAdds a Client-Side Page. * Supported in SharePoint Online.
Add-PnPPageSectionAdds a new section to a Client-Side page. * Supported in SharePoint Online.
Add-PnPPageTextPartAdds a text element to a client-side page. * Supported in SharePoint Online.
Add-PnPPageWebPartAdds a Client-Side Web Part to a client-side page. * Supported in SharePoint Online.
Add-PnPContentTypeAdds a new content type
Add-PnPContentTypeToDocumentSetAdds a content type to a document set
Add-PnPContentTypeToListAdds a new content type to a list
Add-PnPCustomActionAdds a custom action
Add-PnPDataRowsToSiteTemplateAdds datarows to a list inside a PnP Provisioning Template
Add-PnPDocumentSetCreates a new document set in a library.
Add-PnPEventReceiverAdds a new remote event receiver
Add-PnPFieldAdd a field
Add-PnPFieldFromXmlAdds a field to a list or as a site column based upon a CAML/XML field definition
Add-PnPFieldToContentTypeAdds an existing site column to a content type
Add-PnPFileUploads a file to Web
Add-PnPFileToSiteTemplateAdds a file to a PnP Provisioning Template
Add-PnPFolderCreates a folder within a parent folder
Add-PnPHtmlPublishingPageLayoutAdds an HTML based publishing page layout
Add-PnPHubSiteAssociationConnects a site to a hubsite. * Supported in SharePoint Online.
Add-PnPIndexedPropertyMarks the value of the propertybag key specified to be indexed by search.
Add-PnPJavaScriptBlockAdds a link to a JavaScript snippet/block to a web or site collection
Add-PnPJavaScriptLinkAdds a link to a JavaScript file to a web or site collection
Add-PnPListFoldersToSiteTemplateAdds folders to a list in a PnP Provisioning Template
Add-PnPListItemAdds an item to a list
Add-PnPMasterPageAdds a Masterpage
Add-PnPNavigationNodeAdds an item to a navigation element
Add-PnPMicrosoft365GroupToSiteGroupifies 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-PnPSiteTemplateAdds a PnP Provisioning Template object to a tenant template. * Supported in SharePoint Online.
Add-PnPPublishingImageRenditionAdds 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-PnPPublishingPageAdds a publishing page
Add-PnPPublishingPageLayoutAdds a publishing page layout
Add-PnPRoleDefinitionAdds a Role Definition (Permission Level) to the site collection in the current context
Add-PnPSiteClassificationAdds one ore more site classification values to the list of possible values. Requires a connection to the Microsoft Graph. * Supported in SharePoint Online.
Add-PnPSiteCollectionAdminAdds one or more users as site collection administrators to the site collection in the current context
Add-PnPSiteCollectionAppCatalogAdds a Site Collection scoped App Catalog to a site. * Supported in SharePoint Online.
Add-PnPSiteDesignCreates a new Site Design on the current tenant. * Supported in SharePoint Online.
Add-PnPSiteDesignTaskThis 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-PnPSiteScriptCreates a new Site Script on the current tenant. * Supported in SharePoint Online.
Add-PnPStoredCredentialAdds a credential to the Windows Credential Manager
Add-PnPTaxonomyFieldAdd a taxonomy field
Add-PnPTenantCdnOriginAdds a new origin to the public or private content delivery network (CDN). * Supported in SharePoint Online.
Add-PnPTenantSequenceAdds a tenant sequence object to a tenant template. * Supported in SharePoint Online.
Add-PnPTenantSequenceSiteAdds an existing tenant sequence site object to a tenant template. * Supported in SharePoint Online.
Add-PnPTenantSequenceSubSiteAdds a tenant sequence sub site object to a tenant sequence site object. * Supported in SharePoint Online.
Add-PnPTenantThemeAdds or updates a theme to the tenant. * Supported in SharePoint Online.
Add-PnPGroupMemberAdds a user to a group
Add-PnPViewAdds a view to a list
Add-PnPWebhookSubscriptionAdds a new Webhook subscription. * Supported in SharePoint Online.
Add-PnPWebPartToWebPartPageAdds a web part to a web part page in a specified zone
Add-PnPWebPartToWikiPageAdds a web part to a wiki page in a specified table row and column
Add-PnPWikiPageAdds a wiki page
Add-PnPWorkflowDefinitionAdds a workflow definition
Add-PnPWorkflowSubscriptionAdds a workflow subscription to a list
Invoke-PnPSiteTemplateApplies a site template to a web
Apply-PnPTenantTemplateApplies a tenant template to the current tenant. * Supported in SharePoint Online.
Approve-PnPTenantServicePrincipalPermissionRequestApproves a permission request for the current tenant’s “SharePoint Online Client” service principal. * Supported in SharePoint Online.
Clear-PnPDefaultColumnValuesClear default column values for a document library
Clear-PnPListItemAsRecordUndeclares a list item as a record. * Supported in SharePoint Online.
Clear-PnPRecycleBinItemPermanently deletes all or a specific recycle bin item
Clear-PnPTenantRecycleBinItemPermanently deletes a site collection from the tenant-scoped recycle bin
Connect-PnPMicrosoftGraphConnect to the Microsoft Graph
Connect-PnPOnlineConnect to a SharePoint site
Convert-PnPFolderToSiteTemplateCreates a pnp package file of an existing template xml, and includes all files in the current folder
Convert-PnPSiteTemplateConverts a provisioning template to another schema version
ConvertTo-PnPPageConverts a classic page (wiki or web part page) into a Client-Side Page. * Supported in SharePoint Online.
Copy-PnPFileCopies a file or folder to a different location
Copy-PnPItemProxyProxy cmdlet for using Copy-Item between SharePoint provider and FileSystem provider
Deny-PnPTenantServicePrincipalPermissionRequestDenies a permission request for the current tenant’s “SharePoint Online Client” service principal. * Supported in SharePoint Online.
Disable-PnPFeatureDisables a feature
Disable-PnPInPlaceRecordsManagementForSiteDisables in-place records management for a site.
Disable-PnPPowerShellTelemetryDisables PnP PowerShell telemetry tracking
Disable-PnPResponsiveUIDeactivate the PnP Response UI add-on
Disable-PnPSiteClassificationDisables Site Classifications for the tenant. Requires a connection to the Microsoft Graph. * Supported in SharePoint Online.
Disable-PnPTenantServicePrincipalEnables the current tenant’s “SharePoint Online Client” service principal. * Supported in SharePoint Online.
Disconnect-PnPOnlineDisconnects the context
Enable-PnPFeatureEnables a feature
Enable-PnPInPlaceRecordsManagementForSiteEnables in place records management for a site.
Enable-PnPPowerShellTelemetryEnables PnP PowerShell telemetry tracking.
Enable-PnPResponsiveUIActivates the PnP Response UI Add-on
Enable-PnPSiteClassificationEnables Site Classifications for the tenant. Requires a connection to the Microsoft Graph. * Supported in SharePoint Online.
Enable-PnPTenantServicePrincipalEnables the current tenant’s “SharePoint Online Client” service principal. * Supported in SharePoint Online.
Export-PnPPageExports a Client Side Page to a PnP Provisioning Template. * Supported in SharePoint Online.
Export-PnPTaxonomyExports a taxonomy to either the output or to a file.
Export-PnPTermGroupToXmlExports a taxonomy TermGroup to either the output or to an XML file.
Find-PnPFileFinds a file in the virtual file system of the web.
Get-PnPAccessTokenReturns the current OAuth Access token
Get-PnPAppReturns the available apps from the app catalog. * Supported in SharePoint Online.
Get-PnPAppAuthAccessTokenReturns the access token
Get-PnPAppReturns a SharePoint AddIn Instance
Get-PnPAuditingGet the Auditing setting of a site
Get-PnPAuthenticationRealmReturns the authentication realm
Get-PnPAvailableClientSideComponentsGets the available client side components on a particular page. * Supported in SharePoint Online.
Get-PnPAzureADManifestKeyCredentialsReturn the JSON Manifest snippet for Azure Apps
Get-PnPAzureCertificateGet PEM values and manifest settings for an existing certificate (.pfx) for use when using CSOM via an app-only ADAL application.
Get-PnPClientSideComponentRetrieve one or more Client-Side components from a page. * Supported in SharePoint Online.
Get-PnPClientSidePageGets a Client-Side Page. * Supported in SharePoint Online.
Get-PnPConnectionReturns the current context
Get-PnPContentTypeRetrieves a content type
Get-PnPContentTypePublishingHubUrlReturns the url to Content Type Publishing Hub
Get-PnPContextReturns the current context
Get-PnPCustomActionReturn user custom actions
Get-PnPDefaultColumnValuesGets the default column values for all folders in document library
Get-PnPDocumentSetTemplateRetrieves a document set template
Get-PnPEventReceiverReturn registered eventreceivers
Get-PnPExceptionReturns the last exception that occured
Get-PnPFeatureReturns all activated or a specific activated feature
Get-PnPFieldReturns a field from a list or site
Get-PnPFileDownloads a file.
Get-PnPFolderReturn a folder object
Get-PnPFolderItemList content in folder
Get-PnPGroupReturns a specific SharePoint group or all SharePoint groups in site.
Get-PnPGroupMemberRetrieves all members of a group
Get-PnPGroupPermissionsReturns the permissions for a specific SharePoint group
Get-PnPHealthScoreRetrieves the healthscore
Get-PnPHideDefaultThemesReturns if the default / OOTB themes should be visible to users or not. * Supported in SharePoint Online.
Get-PnPHomePageReturn the homepage
Get-PnPHubSiteRetrieve all or a specific hubsite. * Supported in SharePoint Online.
Get-PnPIndexedPropertyKeysReturns the keys of the property bag values that have been marked for indexing by search
Get-PnPInPlaceRecordsManagementReturns if the place records management feature is enabled.
Get-PnPJavaScriptLinkReturns all or a specific custom action(s) with location type ScriptLink
Get-PnPLabelGets the label/tag of the specfied list or library (if applicable). * Supported in SharePoint Online.
Get-PnPListReturns a List object
Get-PnPListInformationRightsManagementGet the site closure status of the site which has a site policy applied
Get-PnPListItemRetrieves list items
Get-PnPListRecordDeclarationReturns the manual record declaration settings for a list. * Supported in SharePoint Online.
Get-PnPMasterPageReturns the URLs of the default Master Page and the custom Master Page.
Get-PnPNavigationNodeReturns all or a specific navigation node
Get-PnPPowerShellTelemetryEnabledReturns true if the PnP PowerShell Telemetry has been enabled.
Get-PnPPropertyReturns a previously not loaded property of a ClientObject
Get-PnPPropertyBagReturns the property bag values.
Get-PnPSiteTemplateGenerates a provisioning site template from a web
Get-PnPProvisioningTemplateFromGalleryRetrieves or searches provisioning templates from the PnP Template Gallery
Get-PnPPublishingImageRenditionReturns all image renditions or if Identity is specified a specific one
Get-PnPRecycleBinItemReturns the items in the recycle bin from the context
Get-PnPRequestAccessEmailsReturns the request access e-mail addresses. * Supported in SharePoint Online.
Get-PnPRoleDefinitionRetrieves a Role Definitions of a site
Get-PnPSearchConfigurationReturns the search configuration
Get-PnPSearchCrawlLogReturns entries from the SharePoint search crawl log. * Supported in SharePoint Online.
Get-PnPSiteReturns the current site collection from the context.
Get-PnPSiteClassificationReturns the defined Site Classifications for the tenant. Requires a connection to the Microsoft Graph. * Supported in SharePoint Online.
Get-PnPSiteClosureGet the site closure status of the site which has a site policy applied
Get-PnPSiteCollectionAdminReturns the current site collection administrators of the site colleciton in the current context
Get-PnPSiteCollectionTermStoreReturns the site collection term store
Get-PnPSiteDesignRetrieve Site Designs that have been registered on the current tenant. * Supported in SharePoint Online.
Get-PnPSiteDesignRightsReturns the principals with design rights on a specific Site Design. * Supported in SharePoint Online.
Get-PnPSiteDesignRunRetrieves 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-PnPSiteDesignRunStatusRetrieves and displays a list of all site script actions executed for a specified site design applied to a site. * Supported in SharePoint Online.
Get-PnPSiteDesignTaskUsed 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-PnPSitePolicyRetrieves all or a specific site policy
Get-PnPSiteScriptRetrieve Site Scripts that have been registered on the current tenant. * Supported in SharePoint Online.
Get-PnPSiteSearchQueryResultsExecutes a search query to retrieve indexed site collections
Get-PnPStorageEntityRetrieve 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-PnPStoredCredentialGet a credential
Get-PnPSubWebReturns the subwebs of the current web
Get-PnPTaxonomyItemReturns a taxonomy item
Get-PnPTaxonomySessionReturns a taxonomy session
Get-PnPTenantReturns organization-level site collection properties. * Supported in SharePoint Online.
Get-PnPTenantAppCatalogUrlRetrieves the url of the tenant scoped app catalog. * Supported in SharePoint Online.
Get-PnPTenantCdnEnabledRetrieves if the Office 365 Content Delivery Network has been enabled. * Supported in SharePoint Online.
Get-PnPTenantCdnOriginReturns the current registered origins from the public or private content delivery network (CDN). * Supported in SharePoint Online.
Get-PnPTenantCdnPoliciesReturns the CDN Policies for the specified CDN (Public | Private). * Supported in SharePoint Online.
Get-PnPTenantRecycleBinItemReturns all modern and classic site collections in the tenant scoped recycle bin. * Supported in SharePoint Online.
Get-PnPTenantSequenceReturns one or more provisioning sequence object(s) from a tenant template
Get-PnPTenantSequenceSiteReturns one or more sites from a tenant template
Get-PnPTenantServicePrincipalReturns the current tenant’s “SharePoint Online Client” service principal. * Supported in SharePoint Online.
Get-PnPTenantServicePrincipalPermissionGrantsGets the collection of permission grants for the “SharePoint Online Client” service principal. * Supported in SharePoint Online.
Get-PnPTenantServicePrincipalPermissionRequestsGets the collection of permission requests for the “SharePoint Online Client” service principal. * Supported in SharePoint Online.
Get-PnPTenantSiteRetrieve site information. * Supported in SharePoint Online.
Get-PnPTenantThemeReturns all or a specific theme. * Supported in SharePoint Online.
Get-PnPTermReturns a taxonomy term
Get-PnPTermGroupReturns a taxonomy term group
Get-PnPTermSetReturns a taxonomy term set
Get-PnPThemeReturns the current theme/composed look of the current web.
Get-PnPTimeZoneIdReturns a time zone ID
Get-PnPUnifiedGroupGets one Office 365 Group (aka Unified Group) or a list of Office 365 Groups. * Supported in SharePoint Online.
Get-PnPUnifiedGroupMembersGets members of a particular Office 365 Group (aka Unified Group). * Supported in SharePoint Online.
Get-PnPUnifiedGroupOwnersGets owners of a particular Office 365 Group (aka Unified Group). * Supported in SharePoint Online.
Get-PnPUPABulkImportStatusGet user profile bulk import status. * Supported in SharePoint Online.
Get-PnPUserReturns site users of current web
Get-PnPUserProfilePropertyYou must connect to the tenant admin website (https://:<tenant>-admin.sharepoint.com) with Connect-PnPOnline in order to use this cmdlet.
Get-PnPViewReturns one or all views from a list
Get-PnPWebReturns the current web object
Get-PnPWebhookSubscriptionsGets all the Webhook subscriptions of the resource. * Supported in SharePoint Online.
Get-PnPWebPartReturns a web part definition object
Get-PnPWebPartPropertyReturns a web part property
Get-PnPWebPartXmlReturns the web part XML of a web part registered on a site
Get-PnPWebTemplatesReturns the available web templates. * Supported in SharePoint Online.
Get-PnPWikiPageContentGets the contents/source of a wiki page
Get-PnPWorkflowDefinitionReturns a workflow definition
Get-PnPWorkflowInstanceGet workflow instances
Get-PnPWorkflowSubscriptionReturn a workflow subscription
Grant-PnPHubSiteRightsGrant 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-PnPSiteDesignRightsGrants the specified principals rights to use the site design. * Supported in SharePoint Online.
Grant-PnPTenantServicePrincipalPermissionExplicitly grants specified permission to the “SharePoint Online Client” service principal. * Supported in SharePoint Online.
Import-PnPAppPackageAdds a SharePoint Addin to a site
Import-PnPTaxonomyImports a taxonomy from either a string array or a file
Import-PnPTermGroupFromXmlImports a taxonomy TermGroup from either the input or from an XML file.
Import-PnPTermSetImports a taxonomy term set from a file in the standard format.
Install-PnPAppInstalls an available app from the app catalog. * Supported in SharePoint Online.
Install-PnPSolutionInstalls 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-PnPQueryExecutes the currently queued actions
Invoke-PnPSiteDesignApply a Site Design to an existing site. * Requires Tenant Administration Rights *. * Supported in SharePoint Online.
Invoke-PnPWebActionExecutes operations on web, lists and list items.
Measure-PnPListReturns statistics on the list object – * Supported in: SharePoint Online, SharePoint 2016, SharePoint 2019.
Measure-PnPResponseTimeGets statistics on response time for the specified endpoint by sending probe requests
Measure-PnPWebReturns statistics on the web object – * Supported in: SharePoint Online, SharePoint 2016, SharePoint 2019.
Move-PnPClientSideComponentMoves a Client-Side Component to a different section/column. * Supported in SharePoint Online.
Move-PnPFileMoves a file to a different location
Move-PnPFolderMove a folder to another location in the current web
Move-PnPItemProxyProxy cmdlet for using Move-Item between SharePoint provider and FileSystem provider
Move-PnPListItemToRecycleBinMoves an item from a list to the Recycle Bin
Move-PnPRecycleBinItemMoves 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-PnPAzureCertificateGenerate a new 2048bit self-signed certificate and manifest settings for use when using CSOM via an app-only ADAL application.
New-PnPExtensibilityHandlerObjectCreates an ExtensibilityHandler Object, to be used by the Get-SPOProvisioningTemplate cmdlet
New-PnPGroupAdds group to the Site Groups List and returns a group object
New-PnPListCreates a new list
New-PnPPersonalSiteOffice365 only: Creates a personal / OneDrive For Business site. * Supported in SharePoint Online.
New-PnPSiteTemplateCreates a new provisioning template object
New-PnPSiteTemplateFromFolderGenerates a provisioning template from a given folder, including only files that are present in that folder
New-PnPSiteCreates a new site collection. * Supported in SharePoint Online.
New-PnPTenantSequenceCreates a new tenant sequence object. * Supported in SharePoint Online.
New-PnPTenantSequenceCommunicationSiteCreates a communication site object. * Supported in SharePoint Online.
New-PnPTenantSequenceTeamNoGroupSiteCreates a new team site without an Office 365 group in-memory object. * Supported in SharePoint Online.
New-PnPTenantSequenceTeamNoGroupSubSiteCreates a team site subsite with no Office 365 group object. * Supported in SharePoint Online.
New-PnPTenantSequenceTeamSiteCreates a team site object. * Supported in SharePoint Online.
New-PnPTenantSiteCreates a new site collection for the current tenant
New-PnPTenantTemplateCreates a new tenant template object. * Supported in SharePoint Online.
New-PnPTermCreates a taxonomy term
New-PnPTermGroupCreates a taxonomy term group
New-PnPTermSetCreates a taxonomy term set
New-PnPUnifiedGroupCreates a new Office 365 Group (aka Unified Group). * Supported in SharePoint Online.
New-PnPUPABulkImportJobSubmit up a new user profile bulk import job. * Supported in SharePoint Online.
New-PnPUserAdds a user to the built-in Site User Info List and returns a user object
New-PnPWebCreates a new subweb under the current web
Publish-PnPAppPublishes/Deploys/Trusts an available app in the app catalog. * Supported in SharePoint Online.
Read-PnPSiteTemplateLoads/Reads a PnP file from the file system
Read-PnPTenantTemplateLoads/Reads a PnP tenant template from the file system and returns an in-memory instance of this template. * Supported in SharePoint Online.
Register-PnPHubSiteRegisters a site as a hubsite. * Supported in SharePoint Online.
Remove-PnPAppRemoves an app from the app catalog. * Supported in SharePoint Online.
Remove-PnPClientSideComponentRemoves a Client-Side component from a page. * Supported in SharePoint Online.
Remove-PnPClientSidePageRemoves a Client-Side Page. * Supported in SharePoint Online.
Remove-PnPContentTypeRemoves a content type from a web
Remove-PnPContentTypeFromDocumentSetRemoves a content type from a document set
Remove-PnPContentTypeFromListRemoves a content type from a list
Remove-PnPCustomActionRemoves a custom action
Remove-PnPEventReceiverRemove an eventreceiver
Remove-PnPFieldRemoves a field from a list or a site
Remove-PnPFieldFromContentTypeRemoves a site column from a content type
Remove-PnPFileRemoves a file.
Remove-PnPFileFromSiteTemplateRemoves a file from a PnP Provisioning Template
Remove-PnPFolderDeletes a folder within a parent folder
Remove-PnPGroupRemoves a group from a web.
Remove-PnPHubSiteAssociationDisconnects a site from a hubsite. * Supported in SharePoint Online.
Remove-PnPIndexedPropertyRemoves 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-PnPJavaScriptLinkRemoves a JavaScript link or block from a web or sitecollection
Remove-PnPListDeletes a list
Remove-PnPListItemDeletes an item from a list
Remove-PnPNavigationNodeRemoves a menu item from either the quicklaunch or top navigation
Remove-PnPPropertyBagValueRemoves a value from the property bag
Remove-PnPPublishingImageRenditionRemoves an existing image rendition
Remove-PnPRoleDefinitionRemove a Role Definition from a site
Remove-PnPSearchConfigurationRemove the search configuration
Remove-PnPSiteClassificationRemoves 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-PnPSiteCollectionAdminRemoves one or more users as site collection administrators from the site collection in the current context
Remove-PnPSiteCollectionAppCatalogRemoves a Site Collection scoped App Catalog from a site. * Supported in SharePoint Online.
Remove-PnPSiteDesignRemoves a Site Design. * Supported in SharePoint Online.
Remove-PnPSiteDesignTaskRemoves 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-PnPSiteScriptRemoves a Site Script. * Supported in SharePoint Online.
Remove-PnPStorageEntityRemove 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-PnPStoredCredentialRemoves a credential
Remove-PnPTaxonomyItemRemoves a taxonomy item
Remove-PnPTenantCdnOriginRemoves an origin from the Public or Private content delivery network (CDN). * Supported in SharePoint Online.
Remove-PnPTenantSiteRemoves a site collection. * Supported in SharePoint Online.
Remove-PnPTenantThemeRemoves a theme. * Supported in SharePoint Online.
Remove-PnPTermGroupRemoves a taxonomy term group and all its containing termsets
Remove-PnPUnifiedGroupRemoves one Office 365 Group (aka Unified Group) or a list of Office 365 Groups. * Supported in SharePoint Online.
Remove-PnPUserRemoves a specific user from the site collection User Information List
Remove-PnPGroupMemberRemoves a user from a group
Remove-PnPViewDeletes a view from a list
Remove-PnPWebRemoves a subweb in the current web
Remove-PnPWebhookSubscriptionRemoves a Webhook subscription from the resource. * Supported in SharePoint Online.
Remove-PnPWebPartRemoves a web part from a page
Remove-PnPWikiPageRemoves a wiki page
Remove-PnPWorkflowDefinitionRemoves a workflow definition
Remove-PnPWorkflowSubscriptionRemove workflow subscription
Rename-PnPFileRenames a file in its current location
Rename-PnPFolderRenames a folder
Request-PnPReIndexListMarks the list for full indexing during the next incremental crawl
Request-PnPReIndexWebMarks the web for full indexing during the next incremental crawl
Reset-PnPFileVersionResets a file to its previous version
Resolve-PnPFolderReturns a folder from a given site relative path, and will create it if it does not exist.
Restore-PnPRecycleBinItemRestores the provided recycle bin item to its original location
Restore-PnPTenantRecycleBinItemRestores a site collection from the tenant scoped recycle bin. * Supported in SharePoint Online.
Resume-PnPWorkflowInstanceResume a workflow
Revoke-PnPSiteDesignRightsRevokes the specified principals rights to use the site design. * Supported in SharePoint Online.
Revoke-PnPTenantServicePrincipalPermissionRevokes a permission that was previously granted to the “SharePoint Online Client” service principal. * Supported in SharePoint Online.
Save-PnPSiteTemplateSaves a PnP site template to the file system
Save-PnPTenantTemplateSaves a PnP provisioning hierarchy to the file system. * Supported in SharePoint Online.
Send-PnPMailSends an email using the Office 365 SMTP Service or SharePoint, depending on the parameters specified. See detailed help for more information.
Set-PnPAppSideLoadingEnables the App SideLoading Feature on a site
Set-PnPAuditingSet Auditing setting for a site
Set-PnPAvailablePageLayoutsSets the available page layouts for the current site
Set-PnPPageSets parameters of a Client-Side Page. * Supported in SharePoint Online.
Set-PnPClientSideTextSet Client-Side Text Component properties. * Supported in SharePoint Online.
Set-PnPClientSideWebPartSet Client-Side Web Part properties. * Supported in SharePoint Online.
Set-PnPContextSet the ClientContext
Set-PnPDefaultColumnValuesSets default column values for a document library
Set-PnPDefaultContentTypeToListSets the default content type for a list
Set-PnPDefaultPageLayoutSets a specific page layout to be the default page layout for a publishing site
Set-PnPDocumentSetFieldSets a site column from the available content types to a document set
Set-PnPFieldChanges one or more properties of a field in a specific list or for the whole web
Set-PnPFileCheckedInChecks in a file
Set-PnPFileCheckedOutChecks out a file
Set-PnPGroupUpdates a group
Set-PnPGroupPermissionsAdds and/or removes permissions of a specific SharePoint group
Set-PnPHideDefaultThemesDefines if the default / OOTB themes should be visible to users or not. * Supported in SharePoint Online.
Set-PnPHomePageSets the home page of the current web.
Set-PnPHubSiteSets hubsite properties. * Supported in SharePoint Online.
Set-PnPIndexedPropertiesMarks 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-PnPInPlaceRecordsManagementActivates or deactivates in the place records management feature.
Set-PnPLabelSets a label/tag on the specified list or library. * Supported in SharePoint Online.
Set-PnPListUpdates list settings
Set-PnPListInformationRightsManagementGet the site closure status of the site which has a site policy applied
Set-PnPListItemUpdates a list item
Set-PnPListItemAsRecordDeclares a list item as a record. * Supported in SharePoint Online.
Set-PnPListItemPermissionSets list item permissions
Set-PnPListPermissionSets list permissions
Set-PnPListRecordDeclarationThe RecordDeclaration parameter supports 4 values: AlwaysAllowManualDeclaration, NeverAllowManualDeclaration, UseSiteCollectionDefaults. * Supported in SharePoint Online.
Set-PnPMasterPageSet the masterpage
Set-PnPMinimalDownloadStrategyActivates or deactivates the minimal downloading strategy.
Set-PnPPropertyBagValueSets a property bag value
Set-PnPSiteTemplateMetadataSets metadata of a provisioning template
Set-PnPRequestAccessEmailsSets Request Access Emails on a web. * Supported in SharePoint Online.
Set-PnPSearchConfigurationSets the search configuration
Set-PnPSiteSets Site Collection properties. * Supported in SharePoint Online.
Set-PnPSiteClosureOpens or closes a site which has a site policy applied
Set-PnPSiteDesignUpdates a Site Design on the current tenant. * Supported in SharePoint Online.
Set-PnPSitePolicySets a site policy
Set-PnPSiteScriptUpdates an existing Site Script on the current tenant. * Supported in SharePoint Online.
Set-PnPStorageEntitySet Storage Entities / Farm Properties in either the tenant scoped app catalog or the site collection app catalog. * Supported in SharePoint Online.
Set-PnPTaxonomyFieldValueSets a taxonomy term value in a listitem field
Set-PnPTenantSets organization-level site collection properties. * Supported in SharePoint Online.
Set-PnPTenantCdnEnabledEnables or disabled the public or private Office 365 Content Delivery Network (CDN). * Supported in SharePoint Online.
Set-PnPTenantCdnPolicySets the CDN Policies for the specified CDN (Public | Private). * Supported in SharePoint Online.
Set-PnPTenantSiteSet site information. * Supported in SharePoint Online.
Set-PnPThemeSets the theme of the current web.
Set-PnPTraceLogTurn log tracing on or off
Set-PnPUnifiedGroupSets Office 365 Group (aka Unified Group) properties. * Supported in SharePoint Online.
Set-PnPUserProfilePropertyOffice365 only: Uses the tenant API to retrieve site information.
Set-PnPViewChange view properties
Set-PnPWebSets properties on a web
Set-PnPWebhookSubscriptionUpdates a Webhook subscription. * Supported in SharePoint Online.
Set-PnPWebPartPropertySets a web part property
Set-PnPWebPermissionSet permissions
Set-PnPWebThemeSets the theme of the current web. * Supported in SharePoint Online.
Set-PnPWikiPageContentSets the contents of a wikipage
Start-PnPWorkflowInstanceStarts a workflow instance on a list item
Stop-PnPWorkflowInstanceStops a workflow instance
Submit-PnPSearchQueryExecutes an arbitrary search query against the SharePoint search index
Test-PnPListItemIsRecordChecks if a list item is a record. * Supported in SharePoint Online.
Test-PnPOffice365GroupAliasIsUsedTests if a given alias is already used used. * Supported in SharePoint Online.
Test-PnPTenantTemplateTests a tenant template for invalid references
Uninstall-PnPAppUninstalls an available add-in from the site
Uninstall-PnPAppRemoves an app from a site
Uninstall-PnPSolutionUninstalls a sandboxed solution from a site collection
Unpublish-PnPAppUnpublishes/retracts an available add-in from the app catalog. * Supported in SharePoint Online.
Unregister-PnPHubSiteUnregisters a site as a hubsite. * Supported in SharePoint Online.
Update-PnPAppUpdates an available app from the app catalog. * Supported in SharePoint Online.
Update-PnPSiteClassificationUpdates Site Classifications for the tenant. Requires a connection to the Microsoft Graph. * Supported in SharePoint Online.
How do I Connect to Azure Active Directory from PowerShell?

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

How do I connect to a Microsoft team using 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

Can we connect to SharePoint Online sites using 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?

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

6 thoughts on “How to Connect to SharePoint Online using PnP PowerShell?

  • Is there a way to include the login data in the script so that the user does not know it, but that an MFA query is still sent?

    Reply
  • Hello,
    After applying the “Connect-PnPOnline” Cmdlt I got this error message “Host not reachable”. Please how do solve this problem?

    Thank you.

    Reply
    • 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.

      Reply
  • Nice content very helpful!

    Reply
  • I’m getting Error “Connect-PnpOnline : Parameter set cannot be resolved using the specified named parameters.”

    Reply
    • 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.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *