Does anyone have an example of Get-pnpweb with connection parameter please? I'm trying to get to a different web in my script and I believe the only way to achieve this is using this parameter, but I can't seem to find an example.
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.Sign up to join this community
Connection needs to be returned from PnP command when you connect to a site/web you can implement this as below.
#Web 1 already connected Connect-PnPOnline -Url "https://mytenant.sharepoint.com/sites/web1" -Credentials $creds -ReturnConnection #Connecting Web2 with connection $connection = Connect-PnPOnline -Url "https://mytenant.sharepoint.com/sites/web2" -Credentials $creds -ReturnConnection #get Web2 using connection $webs = Get-PnPWeb -Connection $connection
While I think this works, you might want to look into Set-PnPContext that I've added later in my answer.
$connectionA = Connect-PnPOnline -Url https://siteA.com -CurrentCredentials -ReturnConnection $connectionB = Connect-PnPOnline -Url https://siteB.com -CurrentCredentials -ReturnConnection Get-PnPWeb -Connection $connectionA Get-PnPWeb -Connection $connectionB
Sets the Client Context to use by the cmdlets, which allows easy context switching. See examples for details.
Connect-PnPOnline -Url $siteAurl -Credentials $credentials $ctx = Get-PnPContext Get-PnPList # returns the lists from site specified with $siteAurl Connect-PnPOnline -Url $siteBurl -Credentials $credentials Get-PnPList # returns the lists from the site specified with $siteBurl Set-PnPContext -Context $ctx # switch back to site A Get-PnPList # returns the lists from site A