【Management】DPM 2007 の初期設定を自動化 その2 番外編 ~ Attach-ProductionServer.ps1 の中身を見る

以前投稿した、以下の記事の続きです。

その2の②において、DPMサーバーに保護サーバーを認識させる際に、Attach-ProductionServer.ps1 を使用しました。これは、DPM で提供されているスクリプトです。

じゃ、この中身はどうなっているのか、せっかくなので見ておきましょう。

 

これはよいですね。おなじみの引数の設定です。

param([string] $DPMServerName, [string] $PSName, [string] $UserName, [string] $Password , [string] $Domain)

ここも大丈夫ですね。おなじみ、 DPMサーバーが引数として指定されていなければ、プロンプトを出してDPMサーバーの入力を求めています。

if(!$args[0]) { if(!$DPMServerName) { $DPMServerName = read-host "DPMServer:" } }

もし、-? または -help が引数として指定されていれば、書式を表示しています。

else { if(("-?","-help") -contains $args[0]) { write-host Usage:: write-host Attach-ProductionServer.ps1 -DPMServername [dpmserver] -PSName [Production server] -Username [PS admin username] -Password [Password] -domain [User domain] write-host Help:: write-host -Registers a server to be protected with this DPM computer. The target server should meet the following requirements: Have a DPM agent installed. DPMMachine name must be provided as the DPM server when installing this agent. Alternatively, you can install the agent without specifying the DPM server and later configure it using the SetDpmServer.exe utility. write-host exit 0 } else { write-host "Usage -? for Help" exit 1 } }

以下も、引き続き、引数チェックをしています。

if(!$PSName) { $PSName = read-host "PSName:" } if(!$UserName) { $UserName = read-host "UserName:" } if(!$Password) { $Pwd = read-host "Password:" -assecurestring } else { $Pwd = ConvertTo-SecureString $Password -asPlainText -force } if(!$Domain) { $Domain = read-host "Domain:" }

DPMサーバーに接続しています。ここで取得した $dpmserver オブジェクトが重要ですので覚えておいてください。

$dpmServer = Connect-DPMServer $DPMServerName if (!$dpmServer) { Write-Error "Unable to connect to $dpmServerName" exit 1 }

ここです。上で取得した $dpmServer のメソッドである、 「AttachProductionServer」を使用して、保護サーバーをDPMサーバーにアタッチしています。これがうまくいくと、DPM管理コンソールのエージェント一覧に、保護サーバーがリストされます。

#Call Attach production server method on DPM server $dpmServer.AttachProductionServer($PSName, $UserName, $Pwd, $Domain)

以下は、エラーが発生した場合の処理です。エラー番号やメッセージを画面に表示します。

trap { Write-host "There is failure while attaching production server" -ForeGroundColor Red $e = $_.Exception write-Error $e.Error.Problem write-host $e.Error.Resolution -ForeGroundColor Green #Dispose DPMserver object if ($dpmServer) { $dpmServer.Dispose() } exit 1 }

最後に、DPMサーバーとの接続を解除して処理完了です。

#Dispose DPMserver object if ($dpmServer) { $dpmServer.Dispose() } Write-Host "Attached ProductionServer successfully" -ForeGroundColor Green

大したスクリプトじゃなかったですね。見るまでもありませんでした。

参考までに、以下のコマンドで出力した、Connect-DPMServer で取得したオブジェクトの member を こちら に掲載しておきますので、AttachProductionServer 以外のメソッドやプロパティについても確認してみてください。DPMのコマンドレットは、Connect-DPMServer を起点にしていることがわかると思います。

Connect-DPMServer DJ-DPM01 | Get-Member | format-list