Microsoft 365 : Detailed steps using Connect-PnPOnline with Client ID and X509 certificate

Hi All,
Greetings for the day!!!
Today sharing small PowerShell script but very useful.
Background
- If we are using PnP PowerShell and if we are authenticating using “UserName” and “Password” then authentication will fail now.
- Please refer the article for details:
- PowerShell – PnPOnline – resolving error -Connect-PnPOnline : AADSTS700016: Application with identifier ‘31359c7f-bd7e-475c-86db-fdb8c937548e’ was not found in the directory – https://knowledge-junction.in/2024/10/27/powershell-resolving-error-connect-pnponline-application-with-identifier-was-not-found-in-directory/
Different approach
- One other choice is to use – Client ID and Client Secret key
Connect-PnPOnline -Url https://knowledgejunction1.sharepoint.com/sites/TestLogoFromSiteDesign -ClientSecret fM28Q~yg21IbuJ6fPpm_3ytXOfMq6xzLNoM-NdkK -ClientId 26e9ef69-eafe-4689-b35e-c397653c9b91
- But, this approach uses legacy authentication and provides the limited functionality.
- We will get warning as well. Please have a look image below.

Recommended approach
- Use client application (appid / clientid) and X509 certificate.
- To create Azure App we can use PowerShell CMDLET –
Register-PnPEntraIDAppForInteractiveLogin
Register-PnPEntraIDAppForInteractiveLogin -ApplicationName "LIFE IS BEAUTIFUL" -SharePointDelegatePermissions "AllSites.FullControl" -Tenant knowledgejunction1.onmicrosoft.com -Interactive
- Make sure that our newly created app has permissions to SharePoint site.
- We could use the New-SelfSignedCertificate cmdlet to create a self-signed certificate.
- We have detailed article for creating certificate – PowerShell – script to generate a self-signed Certificate – exploring New-SelfSignedCertificate CMDLET – https://knowledge-junction.in/2024/01/20/powershell-script-to-generate-a-self-signed-certificate-exploring-new-selfsignedcertificate-cmdlet/
- Once we have Aure app and Certificate is ready we are ready to execute Connect-PnPOnline
$SiteURL = "https://knowledgejunction1.sharepoint.com/sites/sitewithpowershell"
Connect-PnPOnline -Tenant <My Tenant ID> -Url $SiteURL
-ClientId <My Client ID> -Thumbprint <ThumbPrint of certificate>

Thanks for reading 🙂 HAPPY SHARING 🙂 ENJOY BEAUTIFUL LIFE 🙂

2 Responses
[…] We have detailed article on using Connect-PnPOnline using with certificate and client id. Microsoft 365 : Detailed steps using Connect-PnPOnline with Client ID and X509 certificate – https://knowledge-junction.in/2024/11/19/m365-steps-for-connect-pnponline-clientid-n-x509-certificat… […]
[…] Microsoft 365 : Detailed steps using Connect-PnPOnline with Client ID and X509 certificate […]