0
votes

As per the subject, I'm trying to get the name of a property and the value assocaited with that property, for a specific mailbox.

So, the line below gets me a nice list of the available object properties, and a default column displayed in the output has the heading 'Name'

Get-Mailbox -Identity "Person Name" | gm

I then want to say something like:

  1. For the object: "Mailbox of Person Name"
  2. Where the property of "Mailbox of Person Name" has a name like 'quota'
  3. List both the actual property name and it's value for "Mailbox of Person Name"

I've tried a number of things using -ExpandProperty/Select-Object/Where-Object but they're all failing. I'm sure this is pretty basic, but Powershell is definitely not my strength. Can anyone show me how to structure this pipeline correctly?

2

2 Answers

1
votes

You seem to have used the correct commandlets. Where-Object filters. Select-Object selects specific properties.

From my experience, sometimes what you see on the console doesn't match the actual property name because there is a formatter that can even change the column name. If you you drive the Where-Object and Select-Object with that virtual property name then they do fail. Also sometimes, the output is not really a recordset that works well with these cmdlets.

My advice is to always check the type of an object when things go strange. Starting from $items=Get-Mailbox -Identity "Person Name". Then $items.GetType() reveals the actual .net type. Then $items.Count reveals if it is actually an array or a single object. Then $items|ForEach-Object {$_.GetType()} reveals the type of each object.

Also the $items|Get-Member is very helpful to figure out the property names. If necessary use it also within your loop.

That is how I troubleshoot strange behaviors and if you can post your findings and the code you tried with Where-Object and Select-Object that would be a great help.

1
votes

You do not need to use Where-Object, only Select-Object:

Get-Mailbox -Identity "Person Name" | Select-Object -Property *quota*