How to get List Items from online
SharePoint using PnP PowerShell
SharePoint
Patterns and Practices (PnP)
contains a library of PowerShell commands (PnP PowerShell) that allows you to
perform complex provisioning and artifact management actions towards
SharePoint.
PnP PowerShell
Script Command: https://www.powershellgallery.com/packages/SharePointPnPPowerShellOnline/3.13.1909.0
Prerequisite
Please install
the below setup files if you are working in Windows 7 the other OS details
refer the above PnP link.
1)
SharePoint
Online Management Shell
Download Location: https://www.microsoft.com/en-us/download/details.aspx?id=35588
After Installed the “SharePoint Online Management Shell”,
you can try the “Connect-PnPOnline” command.
Please install the PnP PowerShell If you
get the below error because the PnP module is not available.
Try
to run this command for SharePoint Online
“Install-Module
SharePointPnPPowerShellOnline”
If you get the above error,
please install the “Windows Management Framework”
2)
Windows
Management Framework
Download
Location : https://www.microsoft.com/en-us/download/details.aspx?id=54616
After
installed the “Windows Management Framework” , again you can run the below
command.
“Install-Module
SharePointPnPPowerShellOnline”
Sample Code to Get list Items
The below
code is applicable to SharePoint Server 2013, SharePoint Server 2016,
SharePoint Server 2019, SharePoint Online.
$siteurl="Site URL"
Connect-PnPOnline -Url $siteurl
$listItems= (Get-PnPListItem -List
AngularVendor -Fields "Title")
foreach($listItem in $listItems){
Write-Host "Title" : $listItem["Title"]
Write-Host "---------------------------"
}
Sample Code to create a new List view
#Config Variables
$SiteURL = ""
$ListName= "TestList"
$ViewName= "TestView"
$ViewFields = @("ID","Title")
$Query = "<Where><Eq><FieldRef
Name = 'ID' /><Value Type =
'Number'>5</Value></Eq></Where>"
Try {
#Connect to PNP Online
Connect-PnPOnline -Url $SiteURL
#Create New View Add-PnPView
Add-PnPView -List $ListName -Title $ViewName
-Fields $ViewFields -Query $Query -ErrorAction Stop
Write-host "View '$ViewName' Created
Successfully!" -f Green
}
catch {
write-host "Error: $($_.Exception.Message)"
-foregroundcolor Red
}
|
No comments:
Post a Comment