Selecting the User Account Property Values to be Returned
Summary: Use Windows PowerShell to Manage Office 365 using Windows PowerShell cmdlets, scripts, and batch processes.
Windows PowerShell gives you the ability to do things the way you want to do them. For example, we’ve already seen that running the Get-MsolUser cmdlet brings back three property values:
UserPrincipalName
DisplayName
isLicensed
That’s nice, but what if what we’d really like to see is the user’s display name, the department he or she works for, and the country/region where our user “consumes” Office 365 services? What then?
Note
Yes, “consumes” isn’t exactly a great word, either. But don’t worry about the terminology: the UsageLocation property indicates the geographic location where the user typically uses Office 365. And that’s very important: Office 365 licenses, policies, and available features revolve, in part, around this location.
As we’ve already seen, Get-MsolUser only shows us one of our preferred properties: DisplayName. Looks like we’re out of luck, right?
Right. Well, unless we run this command instead:
Get-MsolUser | Select-Object DisplayName, Department, UsageLocation
Here’s what that command returns:
DisplayName Department UsageLocation
----------- ---------- -------------
Zrinka Makovac Sales & Marketing US
Bonnie Kearney Sales & Marketing US
Fabrice Canel Legal US
Brian Johnson
Anne Wallace Executive Management US
Alex Darrow Sales & Marketing US
David Longmuir Operations US
We won’t bother explaining how this all works today; that’s too much for an overview article. Instead, we’ll just note that the Select-Object cmdlet (which ships as part of Windows PowerShell 3.0) allows you to pick and choose the properties you want a cmdlet to return. You say you only want to see values for UsageLocation property? Then tell Select-Object to return just that one property:
Get-MsolUser | Select-Object DisplayName
Select-Object even lets you return all the property values for an item; try running this command and see what happens:
Get-MsolUser | Select-Object *
That’s useful because, as we’ve already seen, cmdlets don’t always return all the information available for an item. If you want to see everything Get-MsolUser has to say about a user then use a command similar to this:
Get-MsolUser -UserPrincipalName "BelindaN@litwareinc.onmicosoft.com" | Select-Object *
And here’s a handy bonus command, one that returns information about the users who do not have a usage location. (That’s important, because you won’t be able to do certain things with those users until that location has been set.) Here’s the command:
Get-MsolUser | Where-Object {$_.UsageLocation -eq $Null} | Select-Object DisplayName, Department, UsageLocation
And here’s the data that comes back:
DisplayName Department UsageLocation
----------- ---------- -------------
Brian Johnson
Scott Wallace Operations
Those are the only two users we have who don’t currently have a UsageLocation.
Next: Configuring User Account Property Values