syg_hira's tech-work memo

某人材サービス会社の情報共有インフラ担当のおぼえがきです。MicrosoftのEnterprise製品多め。

リモートサーバから、IISのWebサイト構成

複数のサーバに、メンテナンス画面用サイトを構成するためのセットアップスクリプト。
#----------
#新規作成
robocopy \\SourceRepositoryServer\C$\SourceDirectory \\WebServer\C$\Sites\Maintenance /S /E /R:0 /W:0
Invoke-Command -ComputerName $ComputerName -ScriptBlock { `
Import-Module WebAdministration; `
New-WebSite -Name Maintenance -Port 80 -PhysicalPath C:\Sites\Maintenance -Force; `
Set-WebConfigurationProperty -Filter /system.webserver/security/authentication/windowsauthentication -name enabled -Value true -PSPath IIS:\ -location Maintenance; `
Set-WebConfigurationProperty -Filter /system.webserver/security/authentication/anonymousAuthentication -name enabled -Value false -PSPath IIS:\ -location Maintenance; `
Set-WebConfigurationProperty -Filter /system.webServer/httpRedirect -name enabled -Value true -PSPath IIS:\ -location Maintenance; `
Set-WebConfigurationProperty -Filter /system.webServer/httpRedirect -name destination -Value "http://WebServer/maintenance.htm" -PSPath IIS:\ -location Maintenance; `
Set-WebConfigurationProperty -Filter /system.webServer/httpRedirect -name exactDestination -Value true -PSPath IIS:\ -location Maintenance; `
Remove-Module WebAdministration; `
}
 
作業マシンにIIS管理ツールが入ってないことを想定し、Invoke-Command一本で、Webサーバ上のWebAdministrationモジュール→サイト構成→モジュールアンロードを実行。スクリプト外出しにするほうがめんどくさかったので。
 
サイトには、ロードバランサーの死活監視のための認証設定(ロードバランサーには常に401認証エラーを返させる)と、URIにかかわらずmaintenance.htmを表示させるためのリダイレクト設定。
 
robocopy は、リモートで実行させると、リモートサーバから見たほかのサーバに認証が渡らないので、Invoke-Commandの外に出して、あくまでもローカルサーバから実行。
CredSSPを使いこなせばいけるのかな?