Skip to content

Instantly share code, notes, and snippets.

@OlafD
Created March 27, 2019 07:48
Show Gist options
  • Save OlafD/2d52bde7d0e1ce6ce46c599fcf09a559 to your computer and use it in GitHub Desktop.
Save OlafD/2d52bde7d0e1ce6ce46c599fcf09a559 to your computer and use it in GitHub Desktop.
Simple starter für a PowerShell script, when needed to connect to the SharePoint Online site. Can work with credentials or web login.
param (
[Parameter(Mandatory=$true)]
$Url,
$Cred,
[switch]$UseWebLogin
)
if ($UseWebLogin.ToBool() -eq $false)
{
if ($Cred -eq $null)
{
$Cred = Get-Credential
}
Write-Host "Connect to $Url using credentials"
Connect-PnPOnline -Url $Url -Credentials $Cred
}
else
{
Write-Host "Connect to $Url using webLogin"
Connect-PnPOnline -Url $Url -UseWebLogin
}
# your code here...
Write-Host "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment