Search code examples
powershellexchange-server-2010

Writing a mailbox property to a Variable or text box


I am writing a basic GUI that makes it easier for staff to find current mailbox/calendar rights. Essentially they type the name of the mail box and the user who's permissions they wish to check, and it writes what the permissions are

I have tried two ways and both ran into problems. The first:

$Property = get-mailboxpermission -Identity $Mailbox -User $User | Format-List AccessRights    if($Property -eq "AccessRights : {FullAccess}")
    $PermissionText.AppendText(($Property))  

Results with the output:

"Microsoft.PowerShell.Commands.Internal.Format.FormatStartData....."

(I have also get the same when simply inputting the get-mailbox command to the append text)

I have also tried instead to convert the access rights property to a variable, then writing that to the text box using if conditions as below code, but that doesn't play nice either

Method:

$Property = get-mailboxpermission -Identity $Mailbox -User $User | format-list AccessRights
if($Property -eq "AccessRights : {FullAccess}")
    {$PermissionText.AppendText("Full Access")}
if($Property -eq "AccessRights : {ReadAccess}")
    {$PermissionText.AppendText("Read Only")}

Output: Nothing whatsoever

in short, I need a way of either outputting just the permissions to the text box, or, making the variable equal something useable


Solution

  • Try this:

    $Property = Get-MailboxPermission -Identity $Mailbox -User $User | ? {$_.AccessRights -eq "FullAccess"} 
    
    if($Property)
    {
        $PermissionText.AppendText($Property.User.ToString())
    }