Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Need a powershell script

$
0
0

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

    $mailbox | Set-Mailbox -CustomAttribute13 $value
}

Viewing all articles
Browse latest Browse all 13067

Trending Articles