Answered by:
Script error: UserPrincipalName not collected

Question
-
We use a script monthly to see when a user used there Office 365 mailbox for the last time and what the total size is. We need the UserPrincipalName for additional actions. The script command for a user works fine:
PS C:\PS> Get-Recipient -Identity 1234567 | Where {$_.RecipientTypeDetails -eq 'UserMailbox'}| Get-MailboxStatistics | Select DisplayName,@{Name="UserPrincipalName";Expression={Get-User $_.DisplayName }},LastLogonTime,TotalItemSize
DisplayName UserPrincipalName LastLogonTime TotalItemSize
----------- ----------------- ------------- -------------
Doe, John 1234567 1-7-2013 7:10:04 196.3 MB (205,816,186 bytes)But when I run the script for all mailboxes, the UserPrincipalName won't be displayed:
PS C:\PS> Get-Recipient -ResultSize Unlimited| Where {$_.RecipientTypeDetails -eq 'UserMailbox'}| Get-MailboxStatistics
| Select DisplayName,@{Name="UserPrincipalName";Expression={Get-User $_.DisplayName }},LastLogonTime,TotalItemSizeDisplayName UserPrincipalName LastLogonTime TotalItemSize
----------- ----------------- ------------- -------------
Doe 1, John {} 8-11-2013 14:09:49 52.87 MB (55,436,334 bytes)
Doe 2, John {} 11-11-2013 12:01:07 49.95 MB (52,371,339 bytes)
Doe 3, John {} 8-11-2013 12:50:25 81.1 MB (85,038,697 bytes)Can anyone tell me what's wrong in the command? Thanks in advance
- Edited by FScQ Monday, November 11, 2013 11:33 AM
Monday, November 11, 2013 11:21 AM
Answers
-
- Marked as answer by Simon_WuMicrosoft contingent staff, Moderator Sunday, November 24, 2013 7:18 PM
Wednesday, November 13, 2013 9:42 AM
All replies
-
Shouldn't you be getting the UPN property from the user?
Select @{n='UPN';e={(get-user $_.displayname).UserPrincipalName)}, . . .
--- Rich Matheisen MCSE&I, Exchange MVP
Tuesday, November 12, 2013 3:57 AM -
Hi,
I have tested your command below in my Exchange 2010 environment, and it displays the UPN as domain.com/Users/username:
Get-Recipient -ResultSize Unlimited| Where {$_.RecipientTypeDetails -eq 'UserMailbox'}| Get-MailboxStatistics | Select DisplayName,@{Name="UserPrincipalName";Expression={Get-User $_.DisplayName }},LastLogonTime,TotalItemSize
And also try to improve the command as below, and it returns the UPN as username@domain.com:
Get-Recipient -ResultSize Unlimited| Where {$_.RecipientTypeDetails -eq 'UserMailbox'}| Get-MailboxStatistics | Select DisplayName,@{Name="UserPrincipalName";Expression={(Get-User $_.DisplayName).UserPrincipalName }},LastLogonTime,TotalItemSize
So I’d recommend you try restart the EMS and run the command again.
Regards,
Rebecca Tu
TechNet Community Support- Edited by Rebecca Tu Tuesday, November 12, 2013 8:42 AM
Tuesday, November 12, 2013 8:41 AM -
Hi Rebecca and Rich,
your suggestion are the same, unfortunately the command didn't work neither. Strange thing is that I made the script one and a half month ago and the command ran succesfully on Win7. On my work PC's (Windows XP and Windows 7) the command fails to show the UPN, but on my laptop Windows 8.1 Evaluation it will run successfully.
So I don't have a clue why the command is not working on Win XP and Win 7.Tuesday, November 12, 2013 12:58 PM -
I can't say why it doesn't work on those client machines. This works on an Exchange server, though:
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Select DisplayName,@{N="UserPrincipalName";E={(Get-User $_.DisplayName).UserPrincipalName }},LastLogonTime,TotalItemSize
Is there a reason why you used "Get-Recipient" instead of "Get-Mailbox"? Not that it makes any difference in the output, but it does eliminate filtering out contacts, groups, and mail-enabled users (i.e. things without a mailbox).
--- Rich Matheisen MCSE&I, Exchange MVP
Wednesday, November 13, 2013 3:22 AM -
- Marked as answer by Simon_WuMicrosoft contingent staff, Moderator Sunday, November 24, 2013 7:18 PM
Wednesday, November 13, 2013 9:42 AM