如何在CMD中运行PowerShell [英] How to run PowerShell in CMD

查看:335
本文介绍了如何在CMD中运行PowerShell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在cmd命令行中运行PowerShell脚本.有人给了我一个例子,它奏效了:

I'm trying to run a PowerShell script inside cmd command line. Someone gave me an example and it worked:

powershell.exe -noexit "& 'c:\Data\ScheduledScripts\ShutdownVM.ps1'"

但是问题是我的PowerShell脚本具有输入参数,因此我尝试了一下,但是它不起作用:

But the problem is my PowerShell script has input parameters, so I tried, but it doesn't work:

powershell.exe -noexit "& 'D:\Work\SQLExecutor.ps1 -gettedServerName "MY-PC" ' "

错误是:

术语'D:\ Work \ SQLExecutor.ps1 -gettedServerName"MY-PC"'不被识别为cmdlet,函数的名称

The term 'D:\Work\SQLExecutor.ps1 -gettedServerName "MY-PC" ' is not recognized as the name of a cmdlet, function,

如何解决此问题?

推荐答案

您需要将参数与文件路径分开:

You need to separate the arguments from the file path:

powershell.exe -noexit "& 'D:\Work\SQLExecutor.ps1 ' -gettedServerName 'MY-PC'"

另一个可以使用File参数和position参数简化语法的选项:

Another option that may ease the syntax using the File parameter and positional parameters:

powershell.exe -noexit -file "D:\Work\SQLExecutor.ps1" "MY-PC"

这篇关于如何在CMD中运行PowerShell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆