1
2
3
4
5
6
7
8
$principle = "USERNAME@SOMESHAREPOINT.COM" 
$password = 'PASSW0RT' 
$sharePointUrl = "https://SOMESHAREPOINT.COM/SitePages/Home.aspx" 
 
$credential=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $principle,$(ConvertTo-securestring $password -AsPlainText -Force)
$moduleName='Microsoft.Online.SharePoint.PowerShell'
if (!(get-module $moduleName -ea SilentlyContinue)){Install-Module -Name $moduleName -Force}
Connect-SPOService -Url $sharePointUrl -Credential $credential

Possible Errors:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
# This error occurs if the SharePoint site has not automated login enabled
 
#Connect-SPOService : Cannot contact web site 'https://ORGNAME.sharepoint.com/' or the web site does not support
#SharePoint Online credentials. The response status code is 'Unauthorized'. The response headers are
#'X-SharePointHealthScore=3, X-MSDAVEXT_Error=917656; Access+denied.+Before+opening+files+in+this+location%2c+you+must+f
#irst+browse+to+the+web+site+and+select+the+option+to+login+automatically.,
#SPRequestGuid=, request-id=,
#MS-CV=n2lJ3FpgAABhdghow6/LIg.0, Strict-Transport-Security=max-age=31536000, SPRequestDuration=15, SPIisLatency=0,
#MicrosoftSharePointTeamServices=16.0.0.20308, X-Content-Type-Options=nosniff, X-MS-InvokeApp=1; RequireReadOnly,
#Content-Length=0, Content-Type=text/plain; charset=utf-8, Date=30 Feb 2012 20:08:25 GMT, P3P=CP="ALL IND DSP COR
#ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI", Server=Microsoft-IIS/10.0,
#X-Powered-By=ASP.NET'.
#At line:1 char:1
#+ Connect-SPOService -Url $sharePointUrl -Credential $credential
#+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#    + CategoryInfo          : NotSpecified: (:) [Connect-SPOService], NotSupportedException
#    + FullyQualifiedErrorId : System.NotSupportedException,Microsoft.Online.SharePoint.PowerShell.ConnectSPOService

Related posting: