Select-Object returns the first result as my column name instead of as a result

Instead of

Select-Object  Identity, AccessRights, $MailBox.Name} 

Add this

Select-Object  Identity, AccessRights, @{l="Name";e={$MailBox.Name}}} 

where l stands for Label and e stands for Expression.

You can read more about custom tables here https://technet.microsoft.com/en-us/library/ee692794.aspx?f=255&MSPPError=-2147217396


$MailBox.Name lives in outer scope. It isn't a valid property of item returned from Get-mailboxfolderpermission.

You can use calculated property in Select-Object to add additional data to the result:

{Get-mailboxfolderpermission $Mailbox | Where-object {$_.User -match "Default" -AND $_.AccessRights -match "Owner"} | Select-Object  Identity, AccessRights,@{Name="Name"; Expression={$MailBox.Name}}

Calculated property is declared by hash table with keys:

  • Name — the name of the property
  • Expression — script block that returns a value

See "EXAMPLE 4" here for another example of calculated property.

Tags:

Powershell