Identifying account connected to exchange online powershell

kf4ape
kf4ape used Ask the Experts™
on
Working on a few Office 365 scripts for teams, etc...one issue I am running into is I need to add the creator of the group to the owner for set-unified group, execute a few teams commands, and then later drop them...so how do I find the user that is connected to the exchange online powershell connection?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
look in your script for the
Connect-MsolService -Credential

Open in new window

Most Valuable Expert 2015
Distinguished Expert 2018
Commented:
You can get this info from the ConnectionInfo property of the remote session:

(Get-PSSession).Runspace.ConnectionInfo.Credential.UserName

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial