powershell - 从 Windows CMD 运行 PowerShell 命令的命令

标签 powershell cmd

考虑:

(Get-Content Rel_DDL.SQL) | ForEach-Object { 
  $_ -replace "SWIFT [\d\.]+", "SWIFT 2.4.0" 
} | Set-Content Rel_DDL.SQL

上述 PowerShell 代码将 SQL 文件中的 SWIFT 2.3.0 替换为 SWIFT 2.4.0,当我通过 PowerShell 运行时,它工作正常。

我想通过 Windows CMD 运行 PowerShell 命令,但出现错误。

最佳答案

您可以在 CMD Windows 中使用带有 -command 参数的 Powershell.exe 命令。你尝试过吗?

-命令

Executes the specified commands (and any parameters) as though they were
typed at the Windows PowerShell command prompt, and then exits, unless
NoExit is specified. The value of Command can be "-", a string. or a
script block.

如果 Command 的值为“-”,则从标准输入读取命令文本。 如果 Command 的值为脚本 block ,则脚本 block 必须用大括号 ({}) 括起来。

仅当在 Windows PowerShell 中运行 PowerShell.exe 时才能指定脚本 block 。脚本 block 的结果作为反序列化的 XML 对象而不是事件对象返回到父 shell。

如果 Command 的值是字符串,则 Command 必须是命令中的最后一个参数,因为在命令之后键入的任何字符都会被解释为命令参数。

要编写运行 Windows PowerShell 命令的字符串,请使用格式:“& {}”,其中引号表示字符串,调用运算符 (&) 会导致执行该命令。

关于powershell - 从 Windows CMD 运行 PowerShell 命令的命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46538149/

相关文章:

java - Maven 构建失败并显示 "mvn install"命令

node.js - 错误 : Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js' when trying to run npm

powershell - 为什么从 powershell 调用批处理文件时插入符会消失?

powershell - 在powershell中将字符串转换为数字

Powershell WebAdministration 迭代给定 IIS 站点的应用程序/虚拟目录

c - 如何使用全新的 Windows 副本在 C 语言中编译程序?无外部软件

linux - Windows 上文件扩展名的问题

r - 比较在线文件的 md5sum 和本地下载的文件

.net - System.Net.HttpWebRequest::GetResponse() 中的错误处理

python - pyproj 不适用于 ipython(但适用于 CLI)