Azure Cloud Service Startup task that needs to run a PowerShell script
全部,
注意:经过一些反馈,我已经更新了问题。
感谢@jisaak到目前为止的帮助。
我需要运行PowerShell脚本,该脚本在部署Cloud Service时添加TCP绑定和其他一些内容。
这是我的云服务项目:
这是我的Cloud Service项目和Webrole项目:
这是我在ServiceDefinition.csdef中的任务:
这是我要运行的PowerShell脚本:
这是我对Startup.cmd的尝试:
部署后,我会在Azure日志中得到此信息:
这在powershell日志中:
任何帮助将不胜感激。
我想我快要到那里了,但是在网络上遵循其他人的语法似乎并不能使我到达那里。
谢谢
拉斯
我认为问题在于,批处理命令解释器在运行Startup.cmd时运行的工作目录与预期不符。
Startup.cmd位于
因此,命令
oleStartup.ps1
我知道的解决方案是:
解决方案1:
使用
oleStartup.ps1
替代品2:
在Startup.cmd中更改当前的工作目录,以便找到相对路径
oleStartup.ps1
解决方案3:
正如Don Lockhart的答案所建议的那样,不要将Startup目录复制到输出中,而应在Visual Studio项目中将其设置为" Content"。这意味着其中的文件将存在于Azure实例的
oleStartup.ps1
好,
因此,在进行了许多不同的尝试以使其工作之后,我将重新回到这一点。
我尝试使用:
- ServiceDefinition.csdef中的启动配置
- 我尝试在扫描Windows Azure日志的服务器上注册计划的任务,以查找[System [Provider [@ Name ='Windows Azure Runtime 2.6.0.0']和EventID = 10004]]
由于安全性或事件发生的时间以及IIS尚未完全设置,因此无济于事。
因此,我终于忍住了Bullets,并使用了我的Webrole.cs =>公共替代bool OnStart()方法:
在ServiceDefinition.csdef中与此结合:
现在一切正常。这不是最令人满意的结果,因为其他一些实现方法感觉更优雅。另外,许多其他人指出,他们还有其他方法可以正常工作。也许我最终会到达那里,但是我的时间受到了限制。
谢谢
拉斯
过去,我发现不将内容复制到输出目录更加容易。我有approot \\\\ bin作为工作目录。我的startUp任务元素的commandLine属性使用对.cmd文件的相对引用,如下所示:
.cmd文件也相对地从工作目录引用PowerShell脚本:
1 2 | PowerShell -ExecutionPolicy Unrestricted -f ..\\StartUp\ oleStartup.ps1 |
您不需要在cmd中设置执行策略-只需调用脚本即可。另外,您应该使用相对路径,因为您不能依赖于存在
将批次更改为:
1 2 | powershell -executionpolicy unrestricted -file .\ oleStartup.ps1 |
在Visual Studio中右键单击
如果这仍然不起作用,请在您的
编辑:
尝试采用以下脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | Import-Module WebAdministration $site = $null do # gets the first website until the result is not $null { $site = Get-WebSite | select -first 1 Sleep 1 } until ($site) # get the appcmd path $appcmd = Join-Path ([System.Environment]::GetFolderPath('System')) 'inetsrv\\appcmd.exe' # ensure the appcmd.exe is present if (-not (Test-Path $appcmd)) { throw"appcmd.exe not found in '$appcmd'" } # The rest of your script .... |