是否有一些工具/命令可以从 powershell 运行 azcli 文件?

Tom*_*son 5 powershell azure azure-cli

我正在使用 VS Code,为了在编写 azure cli 脚本时获得一些智能感知,我将所有内容都放在一个.azcli文件中。我现在的问题是如何从 powershell 终端执行该文件?此外,是否可以在这样的脚本中使用参数,例如:

az servicebus topic create -g $resourceGroup -n $topicName --namespace-name $namespace
Run Code Online (Sandbox Code Playgroud)

是否可以调用一个azcli类似于上面的文件并$resourceGroup, $topicName, $namespace从 powershell 提供 as 参数?

Roa*_*ner 4

我不知道在 PowerShell 中执行此操作的简单方法。如果有人知道,我也想知道。

如果安装了适用于 Linux 的 Windows 子系统,则可以从 PowerShell 运行 WSL 中的.azcli文件,就像运行 shell 脚本一样。.shWSL 还需要安装 Azure CLI,因此根据您选择的发行版(Ubuntu 或 Debian 通常是安全的),您需要按照安装 Azure CLI中的说明进行操作。

要从 PowerShell 终端在 WSL 中运行脚本:

bash -c "./file.azcli"
Run Code Online (Sandbox Code Playgroud)

或者直接在 WSL 终端中:

./file.azcli
Run Code Online (Sandbox Code Playgroud)

.azcli您可以像shell 脚本一样在文件中使用参数.sh

resourceGroup=MyRG
topicName=MyTopicName
namespace=myNameSpaceName

az servicebus topic create -g $resourceGroup -n $topicName --namespace-name $namespace
Run Code Online (Sandbox Code Playgroud)

您还可以创建一个.vscode/tasks.json类似于此GitHub 问题建议的 。