私は現在、古い古い夜間にスケジュールされたバッチファイルを更新し、新しい自給自足のPowerShellスクリプトに置き換えています。
私が困っているのはウェブサイトのスタートです。現在のテストコードを使用してサイトのリストを取得して表示することはできますが、停止した場合に正しく開始する方法を見つけることができません。
Set-ExecutionPolicy Unrestricted
start-transcript -path C:\TESTSTART.TXT
#function to get list of websites that are currently stopped
function Get-StoppedSites {
Import-Module WebAdministration
$website = Get-ChildItem IIS:\Sites | where {$_.State -eq 'Stopped'}
write-host "$website is stopped"
}
#function to start the stopped website
function StartSites {
param(
$websitename
)
start-website $websitename
write-host "$website was started"
}
$Script = Get-StoppedSites
$Script | ForEach-Object{StartSites -websitename $website}
stop-transcript
これをPowerShellから呼び出すと、エラーなしで完了したように動作しますが、停止したWebサイトは開始されません。Windows 2008 R2サーバー、PS2.0。ただし、ロールアウトの準備ができたら、2003サーバーでこれを実行します。
これが私のトランスクリプトです:
Transcript started, output file is C:\TESTSTART.TXT
is stopped
Start-Website : Cannot validate argument on parameter 'Name'. The argument is null. Supply a non-null argument and try
the command again.
At C:\Users\Administrator\Desktop\test.ps1:14 char:18
+ start-website <<<< $websitename
+ CategoryInfo : InvalidData: (:) [Start-Website], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.IIs.PowerShell.Provider.StartWebsiteCommand
was started
**********************
Windows PowerShell Transcript End
End time: 20120823150248
ここで私がどこで/何が間違っているのかを理解するのを手伝ってくれませんか?ありがとう!