Microsoft 365 – Few approaches / options for Connecting to tenant using PnP PowerShell – Connect-PnPOnline – Part 1

Microsoft 365 - Connecting to Microsoft tenant using PnP PowerShell - Connect-PnPOnline
Microsoft 365 - Connecting to Microsoft tenant using PnP PowerShell - Connect-PnPOnline

Hi All,

Greetings for the day 🙂 LIFE IS BEAUTIFUL 🙂

Today discussion on one more very useful PowerShell CMDLET 🙂

Background : Many times I or my team need write few PowerShell scripts where we need to connect to Microsoft 365 tenant. Sometime we uses PnP PowerShell cmdlet.

So here in 2 part series we will discuss few approaches to connect to Microsoft 365 Tenant using PnP PowerShell cmdlet – Connect-PnPOnline and respective use cases – when to use which approach

Prerequisites :

  • If SharePoint PnP module is not installed, kindly please install by using following one of the option
  • Execute the following command

Install-Module SharePointPnPPowerShellOnline 

Details :

Different options available to connect Microsoft 365 tenant using Connect-PnPOnline are

  • Using Interactive parameter as
    • When we use –Interactive parameter, we get prompted for user name and password to login
    • Once we connected with valid user name and password we are ready to execute the PnP CMDLETs (context will be ready to execute other PnP commands)
    • We could use this option while
      • testing our PowerShell scripts OR
      • only one time execution OR
      • occasionally manually execution
Connect-PnPOnline -Interactive

Microsoft 365 - Connecting to Microsoft tenant using PnP PowerShell - Connect-PnPOnline
Fig : Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline
Microsoft 365 - Connecting to Microsoft tenant using PnP PowerShell - Connect-PnPOnline, on successful connection - ready to execute the PnP cmdlets - Here executing Get-PnPConnection
Fig : Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline, on successful connection – ready to execute the PnP cmdlets – Here executing Get-PnPConnection
  • Using Credentials (Get-Credential) parameter
    • When we use -Credential (Get-Credential) parameter, we will get prompted for user name and password
    • Once we entered credentials successfully, we are ready to execute other PnP CMDLETs

Connect-PnPOnline -Url https://knowledgejunction1.sharepoint.com -Credentials (Get-Credential)

Microsoft 365 - Connecting to Microsoft tenant using PnP PowerShell - Connect-PnPOnline - Using parameter -Credentials (Get-Credential)
Fig : Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline – Using parameter -Credentials (Get-Credential) – prompt for user name and password

Fig : Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline – Using parameter -Credentials (Get-Credential) – after successfully entering the credentials – executing other PnP cmdlet

Connect-PnPOnline -Url "https://knowledgejunction1.sharepoint.com" -ClientId <MY APP CLIENT ID> -ClientSecret <MY CLIENT SECRET>

Microsoft 365 - Connecting to Microsoft tenant using PnP PowerShell - Connect-PnPOnline - Using ClientId and ClientSecret
Fig : Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline – Using ClientId and ClientSecret

$password = (ConvertTo-SecureString -AsPlainText 'myprivatekeypassword' -Force)

Connect-PnPOnline -Url "https://knowledgejunction1.sharepoint.com" -ClientId <MY CLIENT ID> -CertificatePath 'c:\mycertificate.pfx' -CertificatePassword $password  -Tenant 'knowledgejunction1.onmicrosoft.com'

In next article we will discuss some more approaches 🙂 STAY TUNED…

Thanks for reading 🙂 HAVE A FANTASTIC TIME AHEAD 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL. ENJOY THE WHOLE JOURNEY :) Founder of Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

5 Responses

  1. December 18, 2021

    […] last article – Microsoft 365 – Few approaches / options for Connecting to tenant using PnP PowerShell –… we discussed few approaches / options for connecting SharePoint site / generating context using PnP […]

  2. April 3, 2023

    […] Microsoft 365 – Few approaches / options for Connecting to tenant using PnP PowerShell – Connect-PnPOnline – Part 1 – https://knowledge-junction.in/2021/12/16/microsoft-365-few-approaches-options-for-connecting-to-ten&#8230; […]

  3. April 13, 2023

    […] We have detailed article on connecting our Microsoft 365 tenant using PnP, please have a look – https://knowledge-junction.in/2021/12/16/microsoft-365-few-approaches-options-for-connecting-to-tena&#8230; […]

  4. April 14, 2023

    […] Microsoft 365 – Few approaches / options for Connecting to tenant using PnP PowerShell – Connect-PnPOnline – Part 1 – https://knowledge-junction.in/2021/12/16/microsoft-365-few-approaches-options-for-connecting-to-tena&#8230; […]

  5. February 9, 2026

    […] Microsoft 365 – Few approaches / options for Connecting to tenant using PnP PowerShell – Connect… […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.