如何直接在 bash 脚本中 运行 PowerShell 核心命令?

How to run PowerShell core commands in bash script directly?

我主要在 bash 脚本中使用 Az CLI 命令来管理 Azure 资源。有时,我需要使用 PowerShell core 命令,因为 Az CLI 版本不存在。

我想在 bash shell 中同时使用 Az CLIPS core 命令。我的意思是,我想要 only one bash 脚本并在其中执行所有必需的命令。

您知道在 bash 脚本中 运行 PowerShell core 命令 直接 的方法吗?

你不能那样做。但是,您可以将 powershell 用于 linux (pwsh) - https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7

例如从 bash 你可以调用这个程序并传递命令

$ pwsh -c "write-host Hello world"
Hello world

如果需要执行多个命令,通常我会从内部调用 PowerShell 脚本 bash,但如果你只想执行一个,你可以 运行 pwsh -command COMMAND 例子: pwsh - 命令 get-childitem