我目前用新的自给自足的 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 调用它时,它的行为就像它没有错误地完成,但是我已经停止的网站没有启动。Windows 2008 R2 服务器,PS 2.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
你们能帮我弄清楚我在这里做错了什么吗?谢谢!