Skip Ribbon Commands
Skip to main content

Quick Launch

Todd Klindt's home page > Todd Klindt's Office 365 Admin Blog > Posts > How to Get the Microsoft 365 Connected User with PnP PowerShell
October 08
How to Get the Microsoft 365 Connected User with PnP PowerShell

As I’ve alluded to before, I spend a lot of time in PowerShell, and most of it in the loving embrace of the PnP.PowerShell module. From time to time I find myself wanting to include logic in my scripts based on who the script is being run as, who connected to Microsoft 365. The majority of my connections where with the good old username and password combination. When that’s the case, I could use this to find how who I had connected as:

Connect-PnPOnline -Url https://m365x995492.sharepoint.com/
admin@M365x995492.onmicrosoft.com
((Get-PnPConnection).PSCredential).username

It looks like this:

image 

That worked great, right up to the point where I didn’t just log in with username credentials. For instance, the Sympraxis tenant requires MFA so I have to connect with the –Interactive parameter:

image 

Old Faithful let me down. Back to the drawing board. Poking around the Internet I saw some smart folks were using this method:

$ctx = Get-PnPContext
$ctx.Load($ctx.Web.CurrentUser)
$ctx.ExecuteQuery()
$ctx.Web.CurrentUser
$UPN = $ctx.Web.CurrentUser.Email

image 

I haven’t tried it yet with Certificate authentication, so I’m not sure how it reports that. The good news is that method also works with a username and password login:

image 

I’ve created a Function, Get-TKPnPCurrentUser, to make that short and easy to use. I've added it to the TKM365Commands module​ I published in GitHub.

tk

ShortURL: https://www.toddklindt.com/POSHGetCurrentPnPUser


edit 4/15/22 - Added link to GitHub

Comments

Bottled and jarred packaged goods

Our lives have been made easier by the introduction of bottled and jarred packaged goods. It has aided in the easy and effective transport of commodities from one location to another. Despite this, it played a critical role during the pandemic. The demand for packaged items has risen dramatically in recent years. For long-term storage of food, a variety of containers are employed. Bottles and jars are the two most common types of food packaging. Food items are packaged in glass to keep them from spoiling. Food packaging has been used since the dawn of time. When food and liquids were kept in glass jars and bottles for storage and preservation.

https://www.mygeekshelp.com/benefits-of-bottle-and-jarred-products/
 on 4/30/2022 8:48 AM

British Dissertation Help

Pick our high-quality and accurate Marketing Dissertation Help and have a sigh of relief. Our writing team will be able to assist you seamlessly regardless of the topic and its complexity and deadline. At British Dissertation Help, our focus is to ensure maximum customer satisfaction for undergraduate, postgraduate, and doctorate students in the UK.
Visit Site: https://www.britishdissertationhelp.com/dissertation-help/marketing-dissertation-help/
 on 5/3/2022 8:27 AM

Mistakes to Avoid While Writing A Case Study

Tao Davin is a guest lecturer for a renowned academic institution in the Canada. Tao Davin has pursued his Ph.D. in Sociology from Cornell University. She loves writing and blogging in her free time and has written for local magazines as well. She’s also an academic advisor and offers her support to students seeking online academic writing help.  https://myassignmenthelp.com/order-essay.html
 on 5/5/2022 12:10 AM

react native app development

Yes, React Native is used for mobile app development, mobile apps have individual platforms that they identify to their work and utilization in the technology industry.  There are so many apps in mobile app development stores for particular purposes. With the React native development, mobile apps make life easier for interaction and communication purposes like chatting with each other and professionally way on social media.  Everything works happen through the mobile apps and it is also utilized the mobile friendly and user friendly. https://www.franticpro.com/react-native-app-development/
 on 5/13/2022 12:37 AM

matlabworks

Here I am sharing a wonderful platform for students in Australia , US and UK seeking for matlabWorks This is matlabworks.com, world's no1 matlab works help company since 2014. They cover almost all wide range of matlab subjects, here you go:
 
<a href="https://matlabworks.com/matlab-assignment-help.php">MATLAB ASSIGNMENT HELP</a>, <a href="https://matlabworks.com/matlab-project-help.php">MATLAB PROJECT HELP</a>, <a href="https://matlabworks.com/electrical-engineering-assignment-help.php">MATLAB ELECTRICAL ASSIGNMENT HELP</a>, <a href="https://matlabworks.com/image-processing-assignment-help.php">MATLAB IMAGE PROCESSING ASSIGNMENT HELP</a>, <a href="https://matlabworks.com/">MATLAB WORKS</a>.
 on 5/13/2022 11:59 PM

MBA dissertation help

If you are pursuing your MBA studies, then you will be required to conduct the MBA dissertation paper. Managing appropriate MBA dissertations is too difficult. So, obtaining the services of our MBA dissertation help will be beneficial for you. Our team of experts will support you to generate high-quality dissertation papers, appropriately.
https://www.britishdissertationhelp.com/dissertation-help/mba-dissertation-help/
 on 5/14/2022 5:57 AM

matlabworks


Here I am sharing a wonderful platform for students in Australia , US and UK seeking for matlabsolutions.com This is matlabsolutions.com , world's no1 matlab  help company since 2014. They cover almost all wide range of matlab subjects, here you go:

<a href="https://www.matlabsolutions.com/au/matlab-assignment-help.php">MATLAB ASSIGNMENT HELP</a>, <a href="https://www.matlabsolutions.com/us/matlab-homework-help.php">MATLAB HOMEWROK HELP</a>, <a href="https://www.matlabsolutions.com/us/matlab-online-exam-help.php">MATLAB ONLINE EXAM HELP</a>, <a href="https://www.matlabsolutions.com/au/matlab-simulation-help.php">MATLAB SIMULATION HELP AUSTRALIA</a>, <a href="https://www.matlabsolutions.com/au/matlab-research-paper-writing.php">MATLAB RESEARCH HELP AUSTRALIA</a>


 on 5/16/2022 12:02 AM

matlabworks


Here I am sharing a wonderful platform for students in Australia , US and UK seeking for matlabsolutions.com This is matlabsolutions.com , world's no1 matlab  help company since 2014. They cover almost all wide range of matlab subjects, here you go:

<a href="https://www.matlabsolutions.com/au/matlab-assignment-help.php">MATLAB ASSIGNMENT HELP</a>, <a href="https://www.matlabsolutions.com/us/matlab-homework-help.php">MATLAB HOMEWROK HELP</a>, <a href="https://www.matlabsolutions.com/us/matlab-online-exam-help.php">MATLAB ONLINE EXAM HELP</a>, <a href="https://www.matlabsolutions.com/au/matlab-simulation-help.php">MATLAB SIMULATION HELP AUSTRALIA</a>, <a href="https://www.matlabsolutions.com/au/matlab-research-paper-writing.php">MATLAB RESEARCH HELP AUSTRALIA</a>


 on 5/16/2022 1:32 AM

Tim David

 on 5/18/2022 12:50 AM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Today's date *

Select a date from the calendar.
Please enter today's date so I know you are a real person

Twitter


Want a message when I reply to your comment? Put your Twitter handle here.

Attachments

 

 SysKit