Reputation: 4345
I have the following code that executes an exchange cmdlet however when I get the result back it gives me a value like this:
Microsoft.Exchange.Management.RecipientTasks.MailboxAcePresentationObject
How can I get the text value of this object and not the object itself?
this is the code I am using to get my value.
powershell.Runspace = runspace;
powershell = PowerShell.Create();
PSCommand command = new PSCommand();
command.AddCommand("Get-MailboxPermission");
command.AddParameter("Identity", "myname");
powershell.Commands = command;
powershell.Runspace = runspace;
Collection<PSObject> result = powershell.Invoke();
StringBuilder sb = new StringBuilder();
foreach (PSObject ps in result)
{
sb.AppendLine(ps.ToString());
}
sb.AppendLine();
lbl.Text += sb.ToString();
Upvotes: 2
Views: 617
Reputation: 13579
What do you want the string representation to be? The ToString is giving you the class name (which is the default behavior for objects)
You can look at the class definition to figure out what you want to display.
If you want to display it like the Exchange shell does, you can look at how its view is defined in exchange.format.ps1xml - here's a snippet from that file which would seem to indicate it displays the properties Identity, User, AccessRights, IsInherited, and Deny.
Alternatively, you could change your pipeline to do out-string (or format-table or whatever) so it's already been formatted as the desired string before it leaves PowerShell.
<View>
<Name>Microsoft.Exchange.Management.RecipientTasks.MailboxAcePresentationObject</Name>
<ViewSelectedBy>
<TypeName>Microsoft.Exchange.Management.RecipientTasks.MailboxAcePresentationObject</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>Identity</Label>
<Width>20</Width>
</TableColumnHeader>
<TableColumnHeader>
<Label>User</Label>
<Width>20</Width>
</TableColumnHeader>
<TableColumnHeader>
<Label>AccessRights</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>IsInherited</Label>
<Width>11</Width>
</TableColumnHeader>
<TableColumnHeader>
<Label>Deny</Label>
<Width>5</Width>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>Identity</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>User</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>AccessRights</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>IsInherited</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Deny</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
Upvotes: 1