# enables Outlook Anywhere RPC over HTTP für a given list of User # ATTN: disableds every other User !! so list must contain ALL Users # Start Testmode # .\set-oaaccess.ps1 –filename osUser.txt -whatif -verbose | Export-Csv .\oaUsers.csv -NoTypeInformation param ( [string]$filename = ".\oaUsers.txt", [switch]$whatif, [switch]$verbose, [switch]$debug ) set-psdebug -strict $ErrorActionPreference = "Stop" if($Verbose){$VerbosePreference = "Continue"} if($debug){Set-PSDebug -Step} write-host "Loading List of allowed OA-Users" [hashtable]$oaUsers = @{} foreach ($oaUser in (get-content -Path $filename)) { write-Verbose -message "Adding $oaUser" $oaUsers.add($oaUser, $true) } Write-verbose "Loading Mailboxes ... Please wait" foreach ($mailbox in (get-mailbox -resultsize unlimited)) { write-verbose -Message "Processing ($mailbox.samaccountname)" if ($oaUsers.item($mailbox.name) ` -or $oaUsers.item($mailbox.alias) ` -or $oaUsers.item($mailbox.samaccountname) ` -or $oaUsers.item($mailbox.PrimarySmtpAddress)) { write-verbose -Message "Enable OA" set-casmailbox -identity $mailbox -MAPIBlockOutlookRpcHttp:$false -whatif:$whatif @{"mailbox"=$mailbox.alias; "oaenabled"=$true} New-Object Object | Add-Member NoteProperty "Mailbox" -value $mailbox.alias -PassThru | add-member NoteProperty "OA" $true -PassThru } else { write-verbose -Message "Disable OA" set-casmailbox -identity $mailbox -MAPIBlockOutlookRpcHttp:$true -whatif:$whatif New-Object Object | Add-Member NoteProperty "Mailbox" -value $mailbox.alias -PassThru | add-member NoteProperty "OA" $false -PassThru } }