[英]Is it possible to call powershell command from within Cake task
I'm switching from Psake build tool to Cake ( https://cakebuild.net/ ). 我正在从Psake构建工具切换到Cake( https://cakebuild.net/ )。 I'm creating a scripts for quite big solution (30+ projects) with (currently) 9 different deploys.
我正在为(目前)有9种不同部署的大型解决方案(30多个项目)创建脚本。 In Psake it was trivial to call PowerShell commands, since entire script has been running in powershell.
在Psake中,调用PowerShell命令很简单,因为整个脚本已在Powershell中运行。
But now I have a problem. 但是现在我有一个问题。 I have to call some commands that are running in PS, but I can't find a way to execute them.
我必须调用在PS中运行的某些命令,但是找不到执行它们的方法。
Some examples: 一些例子:
taskkill /IM iisexpress.exe
Invoke-Command -ComputerName <testing server> -ScriptBlock {import-module WebAdministration; Stop-Website <'name of website'>}
Invoke-Command -ComputerName <testing server> -ScriptBlock {import-module WebAdministration; Start-Website <'name of website'>}
I've tried with StartAndReturnProcess (example: StartAndReturnProcess("taskkill /IM iisexpress.exe"); ), but without success. 我尝试使用StartAndReturnProcess(例如: StartAndReturnProcess(“ taskkill / IM iisexpress.exe”); ),但没有成功。 I've also found Cake.IIS plugin, which would probbably solve my issues with starting and stopping IIS, but there are also smoe other PS commands that I'd like to invoke.
我还找到了Cake.IIS插件,该插件可能会解决我在启动和停止IIS时遇到的问题,但是我还想调用其他PS命令。
Is it possible to simple call a PowerShell command from Task? 是否可以从Task简单调用PowerShell命令? Something like this:
像这样:
Task("DoSomeMagic")
.Does(() =>
{
ExecutePowerShellCommad("taskkill /IM iisexpress.exe");
ExecutePowerShellCommad("Invoke-Command -ComputerName <testing server> -ScriptBlock {import-module WebAdministration; Stop-Website <'name of website'>}");
//ToDo: other magic
});
Thanx for any answer and best regards, Martin 谢谢任何回答和最诚挚的问候,马丁
Have you seen the Cake.PowerShell addin? 您看过Cake.PowerShell插件吗?
Example usage can be found here , but to provide an example (taken from readme): 可以在此处找到示例用法,但是提供了一个示例(摘自自述文件):
#addin "Cake.Powershell"
Task("Powershell-Script")
.Description("Run an example powershell command with parameters")
.Does(() =>
{
StartPowershellScript("Write-Host", args =>
{
args.AppendQuoted("Testing...");
});
});
There are more complicated examples in the readme depending on exactly what you are trying to achieve. 自述文件中有更复杂的示例,具体取决于您要实现的目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.