Partilhar via


WhoAmI for Office 365

If you've ever struggled to find out who your current session is logged in as when you connected to Office 365, here's a tidbit to shed some light on it:

(Get-PSSession |?{$_.ComputerName -like "*outlook.com"})[0].RunSpace.ConnectionInfo.Credential.UserName

You can also use RunSpace.OriginalConnectionInfo.Credential.UserName.  The SDK says ConnectionInfo vs OriginalConnectionInfo:

ConnectionInfo - Connection information for remote Runspaces, null for local Runspaces

OriginalConnectionInfo - ConnectionInfo originally supplied by the user

I have found them to have the same output in the context of Office 365 to this point, but if any of my readers stumbles upon a difference, I'd be happy to learn!