by kusakari
12. 2月 2010 21:12
PowerShell から IIS 7.5 のハンドラーマッピングの操作(作成・変更・削除)をしてみたいと思います。
環境は前回からの続きで、下記の環境です。
■参照
まずは、現在のハンドラマッピングの状況を確認してみたいと思います。
現在の、Default Web Site に対するマッピング状況を出力するには、下記のコマンドで一覧を出力できます。
Get-WebHandler -PSPath "iis:/sites/default web site"
もしくは、下記のような感じでも参照出来ます。
Get-WebConfiguration /system.webserver/handlers/* -PSPath "iis:/sites/default web site"
■作成
次に、下図のような感じのハンドラーマッピングを、PowerShellから Default Web Site に対して作成するには...。

次のような感じのコマンドを入力します。
New-WebHandler -Name "CGI" -Path *.cgi -Verb * -Modules IsapiModule -ScriptProcessor "c:\perl\bin\perlis.dll" -PSPath "iis:/sites/default web site"
■変更
次に、今作成したハンドラーマッピングの設定を編集してみたいと思います。
ハンドラーマッピングの名前を「CGI-2」に変更したい場合は、例えば下記のような感じで変更できます。
Set-WebConfiguration "/system.webserver/handlers/add[@name='CGI']/@name" -Value "CGI-2" -PSPath "IIS:/sites/Default Web Site"
また、実行可能ファイルのパスを「C:\Perl\bin\perlis.dll」から「C:\Perl\bin\perl.exe "%s" %s」に変更するには、下記のような感じにコマンドを入力します。
Set-WebConfiguration "/system.webserver/handlers/add[@name='CGI-2']/@scriptProcessor" -Value "C:\Perl\bin\perl.exe ""%s"" %s" -PSPath "IIS:/sites/Default Web Site"
変更した結果は下図のようになります。

■削除
上で設定した、Default Web Site にマップしている「CGI-2」のハンドラーマッピングの削除を行うには、下記のような感じで削除できます。
Remove-WebHandler -Name "CGI-2" -PSPath "iis:/sites/default web site"
a2a6fddc-b297-4810-b54d-5a1ee648ea86|0|.0
Category: IIS, PowerShell
Tags: