Introduction
In the previous Quick PowerShell Post of the Week we connected to Microsoft Teams PowerShell with Certificate Based Authentication. This week we will walk through the process of connecting to the SharePoint PNP PowerShell module with Certificate Based Authentication. For clarity sake, we need to make sure that you the reader understands which module this is:
SharePoint Online PowerShell: Connects with Tenant Admin credentials and targets Tenant level changes. Updated by the Windows PowerShell team.
SharePoint PnP PowerShell: Connects as current user and at a Site Collection Level. This module also has more granular controls (additional parameters), updated by the PNP team.
Version history of each module is shown below:
Where to Start?
With the SharePoint PnP module, there are two cmdlets provided within the module itself which can create the appropriate Azure App needed for CBA to work with SharePoint PnP. First we run this:
Register-PnPManagementShellAccess
Login
Consent
Once this is completed, we can now use another cmdlet in a one-liner to set up an app and certificates for authentication:
$PnPRegistration = Register-PnPAzureADApp -ApplicationName "PnP PowerShell Access" -Tenant scoles.onmicrosoft.com -OutPath c:\scripts\certs -DeviceLogin $PnPRegistration
Which will perform device authentication with a code:
Then ask for credentials for the SharePoint Online connection:
App creation with credentials:
$PnPRegistration
Check in Azure AD – App Registrations:
Make sure to import your certificate:
Connecting to PnP SharePoint with CBA
To make this connection we need to get the Azure App ID (b4514d36-55a7-4b76-841f-f2749e2591ec) from above as well as the location of the certificate file (c:\scripts\certs\PnP PowerShell Access.pfx) also shown above. Then we can run this command to connect:
Connect-PnPOnline -ClientId b4514d36-55a7-4b76-841f-f2749e2591ec -Url "https://scoles.sharepoint.com" -Tenant scoles.onmicrosoft.com -CertificatePath 'c:\scripts\certs\PnP PowerShell Access.pfx'
Now we are connected with Certificate Based Authentication.
————————————————————————————————–
See previous Quick PowerShell Posts of the Week [ HERE ]
————————————————————————————————–
Comments? Questions?
Feel free to leave your Comments below! Learn to more efficiently utilize PowerShell to manage Exchange Server, Exchange Online, Microsoft Defender for Office or Microsoft Purview Compliance portals by picking up frequently updated eBooks: