Get-MobileDeviceStatistics Issue

%3CLINGO-SUB%20id%3D%22lingo-sub-166291%22%20slang%3D%22en-US%22%3EGet-MobileDeviceStatistics%20Issue%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-166291%22%20slang%3D%22en-US%22%3E%3CP%3EGreetings%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECan%20someone%20explain%20if%20I%20do%20a%3A%3C%2FP%3E%0A%3CP%3EGet-Mailbox%20-Identity%20joeSmith%40domain.com%20I%20get%20a%20result%3C%2FP%3E%0A%3CP%3EGet-MobileDeviceStatistics%20-mailbox%20joesmith%40domain.com%20I%20get%20a%20result%3C%2FP%3E%0A%3CP%3Ebut%3C%2FP%3E%0A%3CP%3EGet-Mailbox%20-Identity%20joesmith%40domain.com%20%7C%20Get-MobileDeviceStatistics%20-mailbox%20%24_.userprincipalname%20I%20get%20an%20error%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECannot%20validate%20argument%20on%20parameter%20'Mailbox'.%20The%20argument%20is%20null%20or%20empty.%20Provide%20an%20argument%20that%20is%20not%20null%20or%20empty%2C%20and%20%3CBR%20%2F%3Ethen%20try%20the%20command%20again.%3CBR%20%2F%3E%20%2B%20CategoryInfo%20%3A%20InvalidData%3A%20(%3A)%20%5BGet-MobileDeviceStatistics%5D%2C%20ParameterBindingValidationException%3CBR%20%2F%3E%20%2B%20FullyQualifiedErrorId%20%3A%20ParameterArgumentValidationError%2CGet-MobileDeviceStatistics%3CBR%20%2F%3E%20%2B%20PSComputerName%20%3A%20ps.outlook.com%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20have%20tried%20-Mailbox%20%24_%20and%20-Mailbox%3A%24_%20also.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-166291%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Eget-mobiledevicestatistics%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-166717%22%20slang%3D%22en-US%22%3ERe%3A%20Get-MobileDeviceStatistics%20Issue%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-166717%22%20slang%3D%22en-US%22%3E%3CP%3EAh!%26nbsp%3B%20So%20you%20do%20need%20a%20foreach%20statement%20even%20though%20you%20are%20only%20pulling%20one%20object.%26nbsp%3B%20Makes....%20sense....%20I%20guess.%26nbsp%3B%20Me%2C%20being%20logical%20(my%20fault)%2C%20would%20have%20thought%20foreach%20would%20loop%202%20or%20more%20objects.%26nbsp%3B%20Silly%20me.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-166596%22%20slang%3D%22en-US%22%3ERe%3A%20Get-MobileDeviceStatistics%20Issue%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-166596%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20are%20not%20using%20the%20correct%20syntax.%20Try%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3EGet-Mailbox%20vasil%20%7C%20%25%20%7B%20Get-MobileDeviceStatistics%20-Mailbox%20%24_.UserPrincipalName%20%7D%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Highlighted
Frequent Contributor

Greetings,

 

Can someone explain if I do a:

Get-Mailbox -Identity joeSmith@domain.com I get a result

Get-MobileDeviceStatistics -mailbox joesmith@domain.com I get a result

but

Get-Mailbox -Identity joesmith@domain.com | Get-MobileDeviceStatistics -mailbox $_.userprincipalname I get an error?

 

Cannot validate argument on parameter 'Mailbox'. The argument is null or empty. Provide an argument that is not null or empty, and
then try the command again.
+ CategoryInfo : InvalidData: (:) [Get-MobileDeviceStatistics], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Get-MobileDeviceStatistics
+ PSComputerName : ps.outlook.com

 

I have tried -Mailbox $_ and -Mailbox:$_ also.

2 Replies
Highlighted

You are not using the correct syntax. Try this:

 

Get-Mailbox vasil | % { Get-MobileDeviceStatistics -Mailbox $_.UserPrincipalName }
Highlighted

Ah!  So you do need a foreach statement even though you are only pulling one object.  Makes.... sense.... I guess.  Me, being logical (my fault), would have thought foreach would loop 2 or more objects.  Silly me.