Need a powershell script

This topic contains 2 replies, has 2 voices, and was last updated by  Haribaskaran Krishnan 3 years, 5 months ago.

  • Author
    Posts
  • #13399

    Hi,

    Need a poweshell script for this simple requirement. I have one DL called "Example". Here I wanted to set the Custom attribute 13 for this group members mailbox as Yes and rest of the mailbox custom attribute 13 as No.I tried something here. Please let me know any corrections?

    $Group = "DL name"

    if (mailbox -filter -eq{ $group})

    Set-Mailbox -CustomAttribute13 'No'

    else

    Set-Mailbox -CustomAttribute13 'Yes'

    will it work. I donot have test environment to test this. If some one help will be appreciated more.

    Thanks

  • #13401

    Dave Wyatt
    Moderator

    You've got some PowerShell syntax issues there which I can offer some guidance on, but you're also using Exchange cmdlets / objects, and I'm not familiar enough with them to give you a complete answer off the top of my head. Here's what I can see, though:

    • mailbox -filter -eq { $group }

      This is not a valid PowerShell expression.

    • Curly braces are not optional after PowerShell "if" and "else" statements (or any other type of compound statement, for that matter.)
    • Your calls to Set-Mailbox don't specify which mailbox you're modifying, and they aren't receiving any pipeline input. This would produce errors.

    Here's an example of how you might rearrange this code to address these problems. However, keep in mind that I haven't tested this. The calls to Get-Mailbox and Set-Mailbox might not be correct yet, and the object returned by Get-Mailbox may not have a "Name" property (or it might not be the correct property to compare with your $group variable.) Hopefully this gets you on the right track, though:

    $group = "DL name"
     
    Get-Mailbox |
    ForEach-Object {
        $mailbox = $_
    
        if ($mailbox.Name -eq $group)
        {
            $value = 'Yes'
        }
        else
        {
            $value = 'No'
        }
    
        $mailbox | Set-Mailbox -CustomAttribute13 $value
    }
    
  • #13402

    Thanks Dave. Let me check and get back to you on this.

You must be logged in to reply to this topic.