0

I am searching a specific OU, then disabling OWA for all users in the OU. This script runs daily.

I have the following script that works properly but is updating ALL the users in the OU.

$OU='OU=SomeOU,DC=Domain,DC=com'
$ext14='00254'
Get-Mailbox -OrganizationalUnit $OU| Where {$_.CustomAttribute14 -eq $ext14} | Set-CASMailbox -OWAEnabled:$false

I would like to ONLY update users that -OWAEnabled is set to $True (and change to $false) in this OU and sub OUs. This would reduce my calls to Exchange. Unfortunately, Set-CASMailbox does not seem to have an OU or CustomAttribute property to query against.

Any suggestions??

GreetRufus
  • 421
  • 2
  • 9
  • 19

2 Answers2

0

Try this:

Get-CASMailbox -OrganizationalUnit $OU | ? {
  $_.CustomAttribute14 -eq $ext14 -and $_.OWAEnabled
} | % {
  Set-CASMailbox -Identity $_.Identity -OWAEnabled:$false
}
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
0

The CASMailbox object does not have the OU or CustomAttribute properties, but the Mailbox object does have protocolsettings property collection, so:

$OU='OU=SomeOU,DC=Domain,DC=com'
$ext14='00254'
Get-Mailbox -OrganizationalUnit $OU|
Where {($_.CustomAttribute14 -eq $ext14) -and ($_.protocolsettings -match 'OWA.1'} |
Set-CASMailbox -OWAEnabled:$false
mjolinor
  • 66,130
  • 7
  • 114
  • 135