简体   繁体   English

是否可以从Cake任务中调用powershell命令

[英]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.

相关问题 PowerShell脚本从任务调度程序运行时未显示命令提示符 - Command prompt not showing when PowerShell script run from task schduler 如何从 ASP.NET 调用 Powershell 命令 - How to call Powershell command from ASP.NET 是否可以从 C# 运行 PowerShell shell 并使其保持运行,同时(同步)在其中执行多个 PowerShell 脚本? - Is it possible to run the PowerShell shell from C# and keep it running, while (synchronously) executing multiple PowerShell scripts within it? C#是否可以从类中的属性调用方法? - C# Is it possible to call a method from a property within a class? 从线程调用任务 - Call Task from Thread MvvmCross命令中的异步任务未返回 - Async task within MvvmCross Command not returning 在任务中进行异步/等待数据库调用? - Make an Async/Await db call within a Task? 是否可以在调用Where的地方调用named方法? - Is it possible to call named method within a call to Where? 如何从Cake构建任务将Tag推送到Bamboo中的Bitbucket Git存储库中? - How to push Tag to Bitbucket Git Repository in Bamboo from Cake build task? 从任务中引发事件 - Raise an event from within a task
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM