Created
July 14, 2017 19:46
-
-
Save BasantPandey/8bc25ad8b0976bac64f6cb311fb980c5 to your computer and use it in GitHub Desktop.
Introduction to PNP Basic Command Part1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module 'C:\Users\basantp\Documents\PNP Blog Section\Code\SharePointPnPPowerShell2013\SharePointPnP.PowerShell.2013.Commands.dll'; | |
try { | |
Set-PnPTraceLog -On -LogFile 'C:\Users\basantp\Documents\PNP Blog Section\Code\traceoutput.txt' -Level Error -Delimiter "," | |
$Url1 = "<SiteURL>" | |
$Url2 = "<SiteURL>" | |
Connect-PnPOnline -Url $Url1 -CurrentCredentials -ErrorAction Stop | |
Write-host "Site $Url1 connected". | |
$Context1= Get-PnPContext | |
#Get the list of $url1 | |
# if you https://github.com/SharePoint/PnP-PowerShell/blob/master/Documentation/SetPnPContext.md | |
# if you simply write Get-PnPList, you will get the error as mentioned below | |
# The collection has not been initialized. It has not been requested or the request has not been executed. | |
# It may need to be explicitly requested. | |
$list =Get-PnPList | |
write-host "Total number of list exist in this site $($list.Length)" | |
Connect-PnPOnline -Url $Url2 -CurrentCredentials -ErrorAction Stop | |
Write-host "Site $Url2 connected". | |
#Get the list of $url2 | |
$Context2= Get-PnPContext | |
$list2 =Get-PnPList | |
write-host "Total number of list exist in this site $($list2.Length)" | |
Set-PnPContext -Context $Context1 # switch back to context1 | |
$items = Get-PnPListItem -List "User Information List" | |
write-host "Total number of Item exist in the user information list $($items.Length)" | |
Set-PnPContext -Context $Context2 # switch back to context2 | |
$items2 = Get-PnPListItem -List "User Information List" | |
write-host "Total number of Item exist in the user information list $($items2.Length)" | |
} | |
catch { | |
Write-Host "Site not found" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you check the SetPnPContext link the example very confusing for me, and simple copy this and paste to the PowerShell the code not work for me.
I am getting the most general error
. To fix this you just put the variable in the front if you get this type of issue any while working with pnp powershell cmdlets.
Please check my PNP PoweShell blog series.