在 PowerShell 中运行 az 命令

You have an Azure subscription named Subscription1. You sign in to the Azure portal and create a resource group named RG1.

From Azure documentation, you have the following command that creates a virtual machine named VM1. az vm create --resource-group RG1 --name VM1 --image UbuntuLTS --generate-ssh-keys

You need to create VM1 in Subscription1 by using the command.

Solution: From the Azure portal, launch Azure Cloud Shell and select PowerShell. Run the command in Cloud Shell.

Does this meet the goal?

中文答案和解答


这个执行的方案是没有问题,有问题的地方是脚步是 CLI 的脚本。

好的,这是中文的答案和解答。


答案:

是的,这个解决方案满足目标。

解答:

这个方法是完全可行的。原因如下:

  1. Azure Cloud Shell 的设计:Azure Cloud Shell 是一个内置在 Azure 门户中的交互式、已通过身份验证的、可通过浏览器访问的命令行环境。它预装了 Azure CLI (az 命令) 和其他常用工具。
  2. Azure CLI 与 Shell 环境的兼容性:Azure CLI (az 命令) 是一个独立的命令行工具,它可以在多种 Shell 环境中运行,包括 Bash 和 PowerShell。
  3. Cloud Shell 的两种环境:当你启动 Azure Cloud Shell 时,可以选择 Bash 或 PowerShell 作为你的工作环境。无论你选择哪一个,Azure CLI 工具都已经安装好并且在系统路径中。因此,你可以在 PowerShell 提示符下直接运行 az 命令,就像在 Bash 中一样。
  4. 自动身份验证:由于你是在登录 Azure 门户后启动的 Cloud Shell,它会自动使用你当前账户的上下文进行身份验证。这意味着它已经知道你的目标订阅是 Subscription1,所以命令会正确地在该订阅中创建资源。

因此,在 Azure 门户中启动 Cloud Shell,选择 PowerShell,然后运行 az vm create 命令,将会成功地在 Subscription1RG1 资源组中创建名为 VM1 的虚拟机。