Need a powershell script


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' 


Set-Mailbox  -CustomAttribute13 'Yes'

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


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 }<br><br>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'
        $value = 'No'

    $mailbox | Set-Mailbox -CustomAttribute13 $value

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