2009-09-02 17 views

答えて

0

& IISによってホストされているTCP/IPソケットを有効にすることを無効にすることについて、私は盲目的な前提にしています。 (ない、たとえば、ブロックする方法を探して/ファイアウォールのレベルで物事のブロックを解除、または完全に何か他のもの。)その場合は、私が転がっ必要なスクリプトを持って起こる...

# Get the IIsWebServer and IIsWebServerSetting WMI objects matching a display name, and combine them into one object 
function Get-IIsWeb 
{ 
    param (
     [string] $displayName = "", 
     [string] $computer = "localhost" 
    ) 

    if ($displayName -eq "") 
     { $filter = "" } 
    else 
     { $filter = "ServerComment='$displayName'"}  

    Get-WmiObject -namespace "root\MicrosoftIISv2" -class "IIsWebServerSetting" -filter $filter -computer $computer -authentication 6 | % { 
     $temp = $_ 
     Get-WmiObject -namespace "root\MicrosoftIISv2" -class "IIsWebServer" -filter "Name='$($_.Name)'" -computer $computer -authentication 6 | 
      add-member -membertype NoteProperty -name Settings -value $temp -passthru 
    } 
} 

# Stop all websites on a given computer that are bound to the specified port, unless they are scoped to a 
# host header or IP address 
function Stop-WebsiteOnPort 
{ 
    [CmdletBinding()]  
    param (
     [Parameter(Mandatory=$true, valuefrompipeline=$true)] 
     [int] $port, 
     [Parameter(Position=0)] 
     [string] $computer = "localhost", 
     [Parameter()] 
     [string] $hostName = $null, 
     [Parameter()] 
     [string] $ip = $null 
    ) 

    begin { $websites = Get-IIsWeb -computer $computer } 

    process 
    { 
     # I don't think you can do this filter in WQL 
     $websites | 
      ? { 
       ($_.settings.serverbindings | ? {$_.port -eq $port -and $_.Hostname -eq $hostName -and $_.IP -eq $ip} | measure).count -gt 0 
      } | 
      % { 
       $_.stop() 
      }    
    } 
} 

実際WMIは、サイトを再び有効にするためのコードは、上のコードを停止するコードとほとんど同じです。しかし、もう少し作業をする必要があります。特定のポートを使用するように設定された任意のサイトがありますが、一度に実行できるサイトは1つだけです。ユーザーから追加のパラメータが必要になるか、「正しい」サイトを選択するためのヒューリスティックが必要になります。

+0

私はこれがまさに私が必要とするものだと思います!本当にありがとう。 –

+0

第2の見通しでは、私はそれが私が必要と考えるとは思わない。ここでは何が起きているのですか?サーバー上で実行され、ユーザーがポート12345でクライアントツールを使用して接続できるTM1というOLAPツールがあります。サーバー上のキューブは毎日更新されますが、接続や計算を試みるユーザーは遅くなります。更新が行われている間に接続をブロックし、更新が完了したらそれらを許可します。更新が行われるためには、サービスが実行されている必要があります。 –

+0

(a)TM1のドキュメントを参照し、サービスを停止せずに接続を切り替える(b)ネットワーク層のユーザーをブロックする、つまりファイアウォールまたはIPSECなどを使用するプログラマチックな方法があることを願ってください。 –

関連する問題