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

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

- We need to browse to the URL and enter the code, we can do this either on another computer or even on mobile

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

- On successfully entering the credentials we will get following message


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

Thanks for reading 🙂 HAVE A GREAT TIME AHEAD 🙂
2 Responses
[…] 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… […]
[…] 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… […]
You must log in to post a comment.