0
votes

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.

2

2 Answers

0
votes

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

0
votes

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