Connect-SPOCSOM.ps1
############################## #.SYNOPSIS #Creates a context object for connection to SharePoint Online. # #.DESCRIPTION #Creates a context object to the supplied site using the SharePointPnPPowerShellOnline module. This context is stored as a global #variable. It can also be assigned to a differenent variable to support mulitple connections to multiple sites, simultaneously. # #02/21/2010 - Updated to use SharePointPnPPowerShellOnline to support modern authentiction methods. # #.PARAMETER SiteURL #The site for the context. # #.EXAMPLE #$credentail = Get-PSCredential #Connect-SPCSOM -credential $credential -SiteURL "Https://tenantname.sharepoint.com/sites/test" # #$ctx = Connect-SPCSOM -username "<username>" -SiteURL "Https://tenantname.sharepoint.com/sites/test" # #.NOTES #Need to work on the global variable usage in other functions. This doesn't seem to be working 100%. ############################## Function Connect-SPOCSOM { [CmdletBinding()] Param( [Parameter(Mandatory=$true)] [String]$SiteURL ) #Create the CSOM Context Write-Verbose -Message "Creating connection to $SiteURL" Connect-PnPOnline -Url $SiteURL -UseWebLogin $Context = Get-PnPContext Write-Verbose -Message "Assign context to globabl variable." $Global:SPOCSOMContext= $Context return $Context } |