[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Get Username in PowerShell

Posted on 2012-08-23
12
Medium Priority
?
1,570 Views
Last Modified: 2012-08-23
I an trying to get the usernames and mailbox size corresponding to all mailboxes on an Exchange 2003 server.

I've got this:
Get-WMIObject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer r2d2 | sort-object MailboxDisplayName | Sort-Object Size -Descending | format-table MailboxDisplayName,Size

It works great, but I like to change the MailboxDisplayName to something that gives me the UserName/samAccountName instead.

Is it possible?
0
Comment
Question by:Kasper Katzmann
  • 5
  • 5
  • 2
12 Comments
 
LVL 52

Expert Comment

by:Manpreet SIngh Khatra
ID: 38324313
Change MailboxDisplayName -> DistinguishName .... check the attribute and change it to it.

- Rancy
0
 
LVL 35

Accepted Solution

by:
Ernie Beek earned 2000 total points
ID: 38324318
I once found this one:
Get-WmiObject -Class Exchange_Mailbox -NameSpace root\microsoftexchangev2 -ComputerName ExchangeServer | Sort-Object MailboxDisplayName | Format-Table MailboxDisplayName, @{Label='SamAccountName';Expression={(Get-QADUser -Identity $_.LegacyDN).SamAccountName}}, ServerName, StorageGroupName, StoreName, Size -auto

From: http://blogs.microsoft.co.il/blogs/scriptfanatic/archive/2009/07/16/mapping-a-wmi-mailbox-to-its-ad-user-account.aspx
0
 
LVL 52

Expert Comment

by:Manpreet SIngh Khatra
ID: 38324323
You can also have "cn" or "displayName" or "name".
All these attributes just have the Display Name :)

- Rancy
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 

Author Comment

by:Kasper Katzmann
ID: 38324328
It only gives blank fields. I have used both DistinguishName and DistinguishedName.
0
 

Author Comment

by:Kasper Katzmann
ID: 38324403
Ok, if I put in Format-List instead of Format-Table, I get the some good info. I can see that the LegacyDN in fact holds the username. As in:

LegacyDN : /O=COMPANY NAME/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=ELS

Is there a way to strip the output abowe, so that I only get the last three letters and if one of those three letters are a "=" then remove it?
0
 
LVL 52

Expert Comment

by:Manpreet SIngh Khatra
ID: 38324563
These 3 attributes in AD have the "Display Name" something like "Last, First" and so is that wahat you want ? (( "cn" or "displayName" or "name" ))

What you have in the Legacy Exchaneg DN could be either DisplayName or Alias.

- Rancy
0
 

Author Comment

by:Kasper Katzmann
ID: 38324578
No, it's the username/loginname i need
0
 
LVL 52

Expert Comment

by:Manpreet SIngh Khatra
ID: 38324596
mailNickname - UserID

msDS-PrincipalName - DomainName\UserID

I guess this is what your looking for ? Just to let you know i am checking this in ADSIEDIT on W2k8 with E2k10 .... so if you have issues you can check with ADSIEDIT for an attribute on a user to understand what attribute you want :)

- Rancy
0
 

Author Comment

by:Kasper Katzmann
ID: 38324615
Dosn't work either.
I guess the problem is that I'm using Get-WMIObject instead of calling the AD.
0
 
LVL 52

Expert Comment

by:Manpreet SIngh Khatra
ID: 38324669
Get-QADUser is for AD .... maybe this will work

- Rancy
0
 

Author Closing Comment

by:Kasper Katzmann
ID: 38324735
@erniebeek - I used your suggestion, but I had to change it a bit, to make it work.

Get-QADUser was changed to Get-User and then... viola

Get-WmiObject -Class Exchange_Mailbox -NameSpace root\microsoftexchangev2 -ComputerName r2d2 | Sort-Object
 size -descending | Format-Table @{Label='SamAccountName';Expression={(Get-User -Identity $_.LegacyDN).SamAccountName}},
Size -auto
0
 
LVL 35

Expert Comment

by:Ernie Beek
ID: 38324770
I was just looking the other way...........
But you managed to get it to work :)

Glad I could help you in the right direction and thx 4 the points.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question