考虑:
(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/