使用 cmd 中的参数调用 PowerShell 命令
Call PowerShell command with parameters from cmd
我想从 cmd
调用 PowerShell
命令。例如,设为 get-content
.
好的,我的情况会是
powershell -command <string> [<CommandParameters>]
在我的例子中它看起来像
powershell -command "& {get-content <???>}" <filepath>
但它不起作用。我不明白如何将 cmd
arg <filepath>
传递到命令字符串 "& {get-content <???>}"
.
根据@Abraham Zinala 的说法,您可以使用以下内容编写 cmd 文件 test.cmd
:
powershell -command "Get-Content 'c:\tmp\toto.txt' "
如果你想写:
.\test.cmd c:\tmp\toto.txt
你可以在你的cmd文件中输入:
powershell -command "Get-Content '%1' "
我想从 cmd
调用 PowerShell
命令。例如,设为 get-content
.
好的,我的情况会是
powershell -command <string> [<CommandParameters>]
在我的例子中它看起来像
powershell -command "& {get-content <???>}" <filepath>
但它不起作用。我不明白如何将 cmd
arg <filepath>
传递到命令字符串 "& {get-content <???>}"
.
根据@Abraham Zinala 的说法,您可以使用以下内容编写 cmd 文件 test.cmd
:
powershell -command "Get-Content 'c:\tmp\toto.txt' "
如果你想写:
.\test.cmd c:\tmp\toto.txt
你可以在你的cmd文件中输入:
powershell -command "Get-Content '%1' "