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

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 Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

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

%d bloggers like this: