Unable to connect sharepoint online site collection using powershell

%3CLINGO-SUB%20id%3D%22lingo-sub-3294751%22%20slang%3D%22en-US%22%3EUnable%20to%20connect%20sharepoint%20online%20site%20collection%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3294751%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20to%20upload%20the%20CSV%20file%20data%20to%20the%20SharePoint%20list%20using%20Powershell%2C%20here%20the%20connection%20is%20established%20up%20to%20the%20admin%20site.%20but%20it%20is%20not%20accessing%20the%20Sharepoint%20site%20collection%2C%20showing%20an%20error%20like%20as%3A%3C%2FP%3E%3CP%3EConnect-SPOService%20%3A%20Could%20not%20authenticate%20to%20SharePoint%20Online%20%3CFONT%20color%3D%22%23CF3600%22%3E%3CA%20href%3D%22https%3A%2F%2Fsiteurl(%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fsiteurl(%3C%2FA%3Ehere%20I%20am%20providing%20actuall%20site%20url%2C%20till%20site%20name)%3C%2FFONT%3Eusing%20OAuth%202.0%3CBR%20%2F%3EAt%20line%3A1%20char%3A1%3CBR%20%2F%3E%2B%20Connect-SPOService%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20NotSpecified%3A%20(%3A)%20%5BConnect-SPOService%5D%2C%20AuthenticationException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20Microsoft.Online.SharePoint.PowerShell.AuthenticationException%2CMicrosoft.Online.SharePoint.PowerShell.ConnectSPOService%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3294751%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESharePoint%20Online%20Powershell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3295099%22%20slang%3D%22en-US%22%3ERe%3A%20Unable%20to%20connect%20sharepoint%20online%20site%20collection%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3295099%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F38365%22%20target%3D%22_blank%22%3E%40Kevin%20Morgan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20point%20is%3A%20You%20can't%20connect%20the%20individual%20site%20collection%20using%20this%20command%20(%3CSPAN%20class%3D%22%22%3EConnect-SPOService%3C%2FSPAN%3E%20).%20The%20command%20is%20designed%20to%20connect%20only%20with%20admin%20site.%20Once%20you%20connected%20the%20Admin%20site%2C%20you%20can%20use%20the%20following%20command%20to%20get%20specific%20site%20details.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EGet-SPOSite%20-Identity%20https%3A%2F%2Fcontoso.sharepoint.com%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20you%20can%20use%20the%20commands%20listed%20in%20the%20below%20post%20to%20manage%20SPO%20sites.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fsharepoint-online%2F%3Fview%3Dsharepoint-ps%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fsharepoint-online%2F%3Fview%3Dsharepoint-ps%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20use%20these%20commands%20only%20to%20manage%20SPO%20sites%20and%20I%20believe%2C%20you%20can't%20manage%20specific%20list%20or%20list%20items%20using%20these%20commands.%20So%2C%20you%20have%20to%20either%20use%20PnP%20PowerShell%20or%20CSOM%20based%20PowerShell.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3295032%22%20slang%3D%22en-US%22%3ERe%3A%20Unable%20to%20connect%20sharepoint%20online%20site%20collection%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3295032%22%20slang%3D%22en-US%22%3EThanks%20for%20your%20reply%2C%3CBR%20%2F%3EActually%2C%20I%20do%20not%20see%20any%20error%20while%20connecting%20to%20the%20admin%20site%2C%20only%20here%20this%20issue%20is%20connecting%20to%20the%20Sharepoint%20site%20collection.%3CBR%20%2F%3Eplease%20let%20me%20know%20about%20this%20issue.%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3295020%22%20slang%3D%22en-US%22%3ERe%3A%20Unable%20to%20connect%20sharepoint%20online%20site%20collection%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3295020%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1373391%22%20target%3D%22_blank%22%3E%40Lokeswar_Reddy%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20expected%20error%20since%20you%20need%20to%20pass%20the%20Admin%20site%20URL%20(Tenant%20site%20url)%20for%26nbsp%3BConnect-SPOService.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20check%20this%20post%20%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fsharepoint-online%2Fconnect-sposervice%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fsharepoint-online%2Fconnect-sposervice%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EConnect-SPOService%20-url%20https%3A%2F%2FTenantName-admin.sharepoint.com%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20you%20know%2C%20the%26nbsp%3BConnect-SPOService%20cmdlet%20is%20belong%20to%20SPO%20Management%20module.%20For%20List%20items%20update%2C%20you%20have%20to%20either%20use%20CSOM%20based%20script%20or%20PnP%20PowerShell%20commands.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24SiteUrl%20%3D%20%22https%3A%2F%2Fcrescent.sharepoint.com%2Fsites%2Fmarketing%22%0A%24ListName%20%3D%20%22CustomerContacts%22%0A%24CSVPath%20%3D%20%22C%3A%5Ctemp%5CCustomerContacts.csv%22%0A%20%0A%23Get%20CSV%20file%20content%0A%24CSVData%20%3D%20Import-CsV%20-Path%20%24CSVPath%0A%20%0A%23Connect%20to%20site%0AConnect-PnPOnline%20%24SiteUrl%20-Interactive%0A%20%0A%23Iterate%20through%20each%20Row%20in%20the%20CSV%20and%20import%20as%20list%20item%20SPO%20List%0AForEach%20(%24Row%20in%20%24CSVData)%0A%7B%0A%23Add%20List%20Items%0AAdd-PnPListItem%20-List%20%24ListName%20-Values%20%40%7B%0A%22CustomerName%22%20%3D%20%24(%24Row.CustomerName)%3B%0A%22Email%22%20%3D%20%24(%24Row.Email)%3B%20%0A%22Mobile%22%20%3D%20%24(%24Row.Mobile)%3B%0A%7D%3B%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3294937%22%20slang%3D%22en-US%22%3ERe%3A%20Unable%20to%20connect%20sharepoint%20online%20site%20collection%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3294937%22%20slang%3D%22en-US%22%3EHave%20you%20tried%20to%20use%20the%20PNP%20Module%3F%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

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

4 Replies
Have you tried to use the PNP Module?

@Lokeswar_Reddy 

 

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);
};
}

 

 

 

 

Thanks for your reply,
Actually, I do not see any error while connecting to the admin site, only here this issue is connecting to the Sharepoint site collection.
please let me know about this issue.

@Kevin Morgan 

 

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.