2

In PnP PowerShell for SharePoint 2013 site, how to give credentials only once, so that it will not ask credentials again while connecting to different site collections coming from a CSV file input.

Here is the code snippet:

$SiteCollections = import-csv -path ".\Source_Destination_URLMapping.csv"

$listTitle = "variation labels" 

foreach($SiteCollection in $SiteCollections) 
{ 
    Connect-PnPOnline -Url $SiteCollection.SiteUrl (get-pnplistitem -list "variation labels").count 
}
2
  • Can you Please share the code snippet that you are executing? Looks difficult to answer without that. Commented Feb 26, 2019 at 14:55
  • @GautamSheth $SiteCollections = import-csv -path ".\Source_Destination_URLMapping.csv" $listTitle = "variation labels" foreach($SiteCollection in $SiteCollections) { Connect-PnPOnline -Url $SiteCollection.SiteUrl (get-pnplistitem -list "variation labels").count } Commented Feb 26, 2019 at 15:14

2 Answers 2

2

Assuming that the same account has access to all the site collections in the csv file, you can simply ask the user for credentials using the Get-Credential method.

You can then pass these credentials to Connect-PnPOnline and get your data as below:

$SiteCollections = import-csv -path ".\Source_Destination_URLMapping.csv"

$listTitle = "variation labels" 

$creds = Get-Credential

foreach($SiteCollection in $SiteCollections) 
{ 
    Connect-PnPOnline -Url $SiteCollection.SiteUrl -Credentials $creds 
    Write-Host (get-pnplistitem -list "variation labels").count 
}
0

Simply open PowerShell and enter this: Connect-PnPOnline -Url https://xyz.sharepoint.com (if you are working on subsite then you have to write full subsite address here) after that it will simply open a popup box and it will ask to enter login credentials then login .. After this step you don't need to login again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.