Kasper Katzmann
asked on
Get Username in PowerShell
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can also have "cn" or "displayName" or "name".
All these attributes just have the Display Name :)
- Rancy
All these attributes just have the Display Name :)
- Rancy
ASKER
It only gives blank fields. I have used both DistinguishName and DistinguishedName.
ASKER
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?
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?
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
What you have in the Legacy Exchaneg DN could be either DisplayName or Alias.
- Rancy
ASKER
No, it's the username/loginname i need
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
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
ASKER
Dosn't work either.
I guess the problem is that I'm using Get-WMIObject instead of calling the AD.
I guess the problem is that I'm using Get-WMIObject instead of calling the AD.
Get-QADUser is for AD .... maybe this will work
- Rancy
- Rancy
ASKER
@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';E xpression= {(Get-User -Identity $_.LegacyDN).SamAccountNam e}},
Size -auto
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';E
Size -auto
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.
But you managed to get it to work :)
Glad I could help you in the right direction and thx 4 the points.
- Rancy