0

Is there any command, or other way, that I can get the username that I have used for logging in to the Exchange-module in PowerShell?

For clarification: This functionality is to be used in a script that will handle permissions for a group of Exchange-admins. And to avoid having to type their admin-accountnames each time they run the script, it would be great if the script could get the name of the account they used when logging in with the PowerShell Exchange-module.

Smorkster
  • 322
  • 3
  • 10

2 Answers2

0

You can get your username in the following code:

Get-Mailbox -ResultSize Unlimited | ForEach {
    $user = $_.SamAccountName
    Get-MobileDeviceStatistics -Mailbox:$_.Identity |
    Select-Object @{label="User" ; expression={$user}},DeviceOS, lastsuccesssync
}

how to get exact user name from get-mobiledevicestatistics in powershell

Alina Li
  • 884
  • 1
  • 6
  • 5
  • Sorry for not mentioning this, but since we have a huge number of users, get them all is not an option. Plus, testing the code gives a list of evert user, their device (if they have any) and last successful sync. – Smorkster Sep 18 '18 at 09:56
  • you can try the following code : "Get-Mailbox -ResultSize unlimited | Format-Table -Auto DisplayName, LitigationHoldEnabled" reference from : https://learn.microsoft.com/en-us/exchange/recipients-in-exchange-online/manage-user-mailboxes/use-powershell-to-display-mailbox-information – Alina Li Sep 18 '18 at 10:30
0

I never found an clear answer for this, so I insteed used my domain-AD username to search for correct useraccount.

Smorkster
  • 322
  • 3
  • 10