Apr 26 2022 01:12 AM
I have to upload the CSV file data to the SharePoint list using Powershell, here the connection is established up to the admin site. but it is not accessing the Sharepoint site collection, showing an error like as:
Connect-SPOService : Could not authenticate to SharePoint Online https://siteurl(here I am providing actuall site url, till site name)using OAuth 2.0
At line:1 char:1
+ Connect-SPOService
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-SPOService], AuthenticationException
+ FullyQualifiedErrorId : Microsoft.Online.SharePoint.PowerShell.AuthenticationException,Microsoft.Online.SharePoint.PowerShell.ConnectSPOService
Apr 26 2022 03:04 AM
Apr 26 2022 04:50 AM - edited Apr 26 2022 04:50 AM
This is expected error since you need to pass the Admin site URL (Tenant site url) for Connect-SPOService.
You can check this post : https://docs.microsoft.com/en-us/powershell/module/sharepoint-online/connect-sposervice
Connect-SPOService -url https://TenantName-admin.sharepoint.com
As you know, the Connect-SPOService cmdlet is belong to SPO Management module. For List items update, you have to either use CSOM based script or PnP PowerShell commands.
$SiteUrl = "https://crescent.sharepoint.com/sites/marketing"
$ListName = "CustomerContacts"
$CSVPath = "C:\temp\CustomerContacts.csv"
#Get CSV file content
$CSVData = Import-CsV -Path $CSVPath
#Connect to site
Connect-PnPOnline $SiteUrl -Interactive
#Iterate through each Row in the CSV and import as list item SPO List
ForEach ($Row in $CSVData)
{
#Add List Items
Add-PnPListItem -List $ListName -Values @{
"CustomerName" = $($Row.CustomerName);
"Email" = $($Row.Email);
"Mobile" = $($Row.Mobile);
};
}
Apr 26 2022 05:10 AM
Apr 26 2022 06:18 AM
The point is: You can't connect the individual site collection using this command (Connect-SPOService ). The command is designed to connect only with admin site. Once you connected the Admin site, you can use the following command to get specific site details.
Get-SPOSite -Identity https://contoso.sharepoint.com
And you can use the commands listed in the below post to manage SPO sites.
https://docs.microsoft.com/en-us/powershell/module/sharepoint-online/?view=sharepoint-ps
You can use these commands only to manage SPO sites and I believe, you can't manage specific list or list items using these commands. So, you have to either use PnP PowerShell or CSOM based PowerShell.