Search code examples
powershellpowershell-2.0exchange-server-2010

PowerShell Exchange disable OWA from OU sort


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??


Solution

  • 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