Get PnPListItem Parameter set cannot be resolved using the specified named parameters
SharePoint Diary » PowerShell » PnP PowerShell » 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: 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 (Select the appropriate download as per your operating system) on Windows 7/8, Windows 2008, or in Windows 2012/R2 environments. Restart your machine to complete the installation. How to install PnP PowerShell for SharePoint Online? 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 in 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: Update-Module SharePointPnPPowerShellOnline This solves the issues like “WARNING: A newer version of PnP PowerShell is available: 3.19.2003.0. Consider upgrading.”. 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 also hard-code credentials in your script, such as: $SiteURL="https://Crescent.sharepoint.com" $UserName="[email protected]" $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 Permissions required to connect to SharePoint Online from PnP PowerShell: What permissions are required for you to connect to SharePoint Online from PnP PowerShell? 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! 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 prompt to enter the credential that is MFA aware! Connect-PnPOnline -Url $SiteURL -Interactive 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: New-PnPList -Title "Team Documents" -Template DocumentLibrary Reference: https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/new-pnplist?view=sharepoint-ps Create a Subsite: New-PnPWeb -Title "emea" -Url "emea" -Template "STS#0" SharePoint Online PnP PowerShell to Create Site Collection #Define Variables $AdminCenterURL = "https://Crescent-admin.sharepoint.com" $SiteURL = "https://Crescent.sharepoint.com/sites/procurement" $SiteTitle = "Crescent Procurement Portal" $SiteOwner = "[email protected]" $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:
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! Connect-PnPOnline -Url "https://Crescent.sharepoint.com" 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.
Related Posts
Salaudeen Rajack – SharePoint Architect. Primarily on Infrastructure, Operations, Administration and Architecture! Want to contribute? |