我正在使用新的自给自足的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
Run Code Online (Sandbox Code Playgroud)
当我从powershell调用它时,它的行为就像它完成没有错误,但网站没有启动,我已经停止.Windows 2008 R2服务器,PS 2.0.一旦它准备推出,我将在2003服务器上运行它.
这是我的成绩单:
Transcript started, output file is C:\TESTSTART.TXT
is stopped
Start-Website : Cannot …Run Code Online (Sandbox Code Playgroud)