Skip to content

Instantly share code, notes, and snippets.

@OlafD
Created December 20, 2023 15:21
Show Gist options
  • Save OlafD/85826ba77df8509d550a79ed2df94c0f to your computer and use it in GitHub Desktop.
Save OlafD/85826ba77df8509d550a79ed2df94c0f to your computer and use it in GitHub Desktop.
[CmdletBinding(DefaultParameterSetName = "Interactive")]
param (
[Parameter(Mandatory, ParameterSetName = "UserPassword")]
[Parameter(Mandatory, ParameterSetName = "Interactive")]
[Parameter(Mandatory, ParameterSetName = "AppIDCertificate")]
[string] $Url,
[Parameter(Mandatory, ParameterSetName = "UserPassword")]
[pscredential] $Credentials,
[Parameter(Mandatory, ParameterSetName = "AppIDCertificate")]
[string] $ClientID,
[Parameter(Mandatory, ParameterSetName = "AppIDCertificate")]
[string] $CertificatePath,
[Parameter(Mandatory, ParameterSetName = "AppIDCertificate")]
[securestring] $CertificatePassword
)
Write-Verbose -Message ("Trying to connect with method " + $PSCmdlet.ParameterSetName)
Write-Verbose -Message ("Connect to " + $Url)
switch ($PSCmdlet.ParameterSetName)
{
"Interactive"
{
Connect-PnPOnline -Url $Url -Interactive
}
"UserPassword"
{
Connect-PnPOnline -Url $Url -Credentials $Credentials
}
"AppIDCertificate"
{
Connect-PnPOnline -Url $Url -ClientId $ClientID -CertificatePath $CertificatePath -CertificatePassword $CertificatePassword
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment