0
votes

So for the past couple weeks, I've been playing around with a few powershell scripts. Currently I've been working with get-CASmailbox. I'm trying to get this script to check the status of activesync and for any disabled protocol's (imap, pop, mapi, etc.) and prompt to turn it on using set-CASmailbox if it detects that any are disabled.

I've got no problem running get-CASmailbox, it returns the exact information I'm looking for, but I'm having a little bit of trouble with "If" statements to get this script working.

Figured I would start light and just have an "If ($actsync -eq "False") {Write-Host 'n'n "Activesync is disabled"}" message pop up. I can work the set prompt later but I cannot for the life of me get the parameter to return as just "False" (at least that's what I've gathered so far.)

I've tried pulling the boolean using the following and I have been unsuccessful.

$actsync = (get-casmailbox $user).activesyncenabled

If ($actsync -eq "False") { Write-Host "Activesync is disabled" -ForegroundColor Red} oddly enough this will only write back "Activesync is disabled" when activesync is enabled, ie "ActiveSyncEnabled = true" I've tried flipping if $actsync -eq "True" but this did not provide results

and

$actsync2 = (get-casmailbox $user | fl *ActiveSyncEnabled*)

followed then by the if statement above

If I can at least get this to accurately write back "activesync is disabled" when activesync is disabled, then I should be well on my way to figuring this out, can anyone point me in the right direction?

1
Change "If ($actsync -eq "False")" to "If ($actsync -eq $false)". You are currently trying to compare the result to a string as where the returned result is a Boolean value. - CraftyB

1 Answers

0
votes

looking at the doc (https://docs.microsoft.com/en-us/powershell/module/exchange/client-access/get-casmailbox?view=exchange-ps) the command has a -Filter option. my idea is to do something like

$arrayDisabledActiveSyncUsers = Get-CASMailbox -ResultSize unlimited -Filter {ActiveSyncEnabled -eq $false}

this will return all mailboxes where activesync is disabled. you could then work with that list like the following to activate the option:

foreach($mailbox in $arrayDisabledActiveSyncUsers) {
    Set-CASMailbox $mailbox -ActiveSyncEnabled $true
}