Microsoft 365 – Connecting to tenant using PnP PowerShell – Connect-PnPOnline – exploring DeviceLogIn (Device code flow) parameter- Part 2

Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline - DeviceLogin parameter
Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline - DeviceLogin parameter

Hi All,

Greetings for the day 🙂 LIFE IS BEAUTIFUL 🙂

In last article – Microsoft 365 – Few approaches / options for Connecting to tenant using PnP PowerShell – Connect-PnPOnline – Part 1 we discussed few approaches / options for connecting SharePoint site / generating context using PnP Connect-PnPOnline cmdlet.

In this article we will discuss about –DeviceLogIn parameter or DeviceCodeFlow

Using DeviceLogin parameter :

  • Enables authentication to Azure Active Directory using a device code that the user can enter into https://microsoft.com/devicelogin
  • We need web browser for interactive Azure AD authentication
  • But there are certain instances / scenarios where users need to authenticate on devices or operating system where we dont have web browser.
  • In such scenarios / cases we use DeviceLogIn option or device code flow
  • Device code flow allows us to use another device such as computer or mobile phone to sign in interactively
  • Example : IOT applications or command-line tools

How Device login / Device code flow works :

  • When user executes command, for ex below CMDLET
Connect-PnPOnline -Url https://knowledgejunction1.sharepoint.com -DeviceLogin

  • When we connect using DeviceLogin parameter, we get message along with URL – https://microsoft.com/devicelogin and Code as shown in below figure

Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline - DeviceLogin parameter
Fig : Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline – DeviceLogin parameter

  • We need to browse to the URL and enter the code, we can do this either on another computer or even on mobile
Fig : Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline - DeviceLogin parameter
Fig : Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline – DeviceLogin parameter

  • Once we entered the code, we get prompt for credentials as shown in below figure

Fig : Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline - DeviceLogin parameter
Fig : Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline – DeviceLogin parameter

  • On successfully entering the credentials we will get following message

Fig : Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline - DeviceLogin parameter
Fig : Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline – DeviceLogin parameter

Fig : Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline - DeviceLogin parameter
Fig : Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline – DeviceLogin parameter

  • On successful connection we will get context and we are ready to execute the PnP cmdlets as shown in below fig

Fig : Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline - DeviceLogin parameter
Fig : Microsoft 365 – Connecting to Microsoft tenant using PnP PowerShell – Connect-PnPOnline – DeviceLogin parameter – successfully connected

Thanks for reading 🙂 HAVE A GREAT 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. April 3, 2023

    […] Microsoft 365 – Connecting to tenant using PnP PowerShell – Connect-PnPOnline – exploring DeviceLogIn (Device code flow) parameter- Part 2 – https://knowledge-junction.in/2021/12/18/microsoft-365-connecting-to-tenant-using-pnp-powershell-con… […]

  2. April 14, 2023

    […] Microsoft 365 – Connecting to tenant using PnP PowerShell – Connect-PnPOnline – exploring DeviceLogIn (Device code flow) parameter- Part 2 – https://knowledge-junction.in/2021/12/18/microsoft-365-connecting-to-tenant-using-pnp-powershell-con… […]

  3. January 27, 2024

    […] We have detailed article on DeviceLogIn – Microsoft 365 – Connecting to tenant using PnP PowerShell – Connect-PnPOnline – exploring DeviceLogIn (Device code flow) parameter- Part 2 – https://microsoft365hub.in/2021/12/18/microsoft-365-connecting-to-tenant-using-pnp-powershell-connec… […]

  4. June 14, 2025

    […] Microsoft 365 – Connecting to tenant using PnP PowerShell – Connect-PnPOnline – exploring DeviceLogIn (Device code flow) parameter- Part 2 – https://microsoft365junction.com/2021/12/18/microsoft-365-connecting-to-tenant-using-pnp-powershell-… […]

  5. February 9, 2026

    […] Microsoft 365 – Connecting to tenant using PnP PowerShell – Connect-PnPOnline – exploring Devi… […]

Leave a Reply

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