R
# Elevated Powershell only!
# https://docs.microsoft.com/en-us/exchange/clients/outlook-on-the-web/http-to-https-redirection
# Директории, которым нужно вернуть SSL, Powershell и Rpc не нужно, так как нет SSL по дефолту, owa тоже, так как это в статье написано.
$VirtualDirsReqvSSL = @'
aspnet_client
Autodiscover
ecp
EWS
mapi
Microsoft-Server-ActiveSync
OAB
'@ -split "`r`n"
# Директории у которых нужно снять редирект.
$VirtualDirsReqvRedir = @'
aspnet_client
Autodiscover
ecp
EWS
mapi
Microsoft-Server-ActiveSync
OAB
owa
powershell
rpc
'@ -split "`r`n"
# set Path IIS Folder
#& set path=%Path%;C:Windows\System32\Inetsrv
if ($env:Path.IndexOf('c:\Windows\System32\Inetsrv') -lt 0) {
$env:Path += ';c:\Windows\System32\Inetsrv'
}
# Step 1: Remove the Require SSL setting from the default website
& appcmd set config "Default Web Site" -section:access -sslFlags:None -commit:APPHOST
Write-Host "Требование SSl c `"Default Web Site`" удалено!" -ForegroundColor Green
Write-Host ""
# Step 2: Restore the Require SSL setting on other virtual directories in the default website
foreach ($VirtDir in $VirtualDirsReqvSSL) {
& appcmd set config "Default Web Site/$($VirtDir)" -section:Access -sslFlags:Ssl,Ssl128 -commit:APPHOST
Write-Host "$($VirtDir) - SSL настройки восстановлены! " -ForegroundColor Green
}
# Убираем требование SSL c /owa
& appcmd set config "Default Web Site/owa" -section:Access -sslFlags:None -commit:APPHOST
# Ставим обратно требование SSL на каталог /owa/auth
& appcmd set config "Default Web Site/owa/auth" -section:Access -sslFlags:Ssl,Ssl128 -commit:APPHOST
# Step 3: Configure the default website to redirect to the /owa virtual directory
& appcmd set config "Default Web Site" -section:httpredirect -enabled:true -destination:"/owa" -childOnly:true
# Step 4: Use IIS Manager to remove http redirection from all virtual directories in the default website
foreach ($VirtDir in $VirtualDirsReqvRedir) {
& appcmd set config "Default Web Site/$($VirtDir)" -section:httpredirect -enabled:false -destination:"" -childOnly:false
Write-Host "$($VirtDir) - Настройки `"HTTP Redirect`" восстановлены! " -ForegroundColor Green
}
# Step 5:Restart IIS
Write-Host "Запуск iisreset..." -ForegroundColor Yellow
$local:answer = $null
do {
$local:answer = Read-Host -Prompt "Перезапустить IIS (Y/n)?"
}
while ( $local:answer -notmatch '^(Y|N|)$')
if ($local:answer -eq '') {
$local:answer = 'y'
}
if ($local:answer -eq 'y') {
& iisreset
Write-Host "iisreset выполнен" -ForegroundColor Green
}
else {
Write-Host "Не забудьте выполнить iisreset для применения настроек IIS!" -ForegroundColor Yellow
}