首页 > 解决方案 > 有没有办法在 azure 中使用 typescript 列出所有 VM?

问题描述

我正在尝试从我的 azure 资源组中获取所有 VM 的列表。我正在使用如下的 armcompute。在这里,我没有得到 VM 的列表。并且长度没有给我正确的虚拟机数量。我不确定我是否走在正确的道路上。

var computeClient = new armCompute.ComputeManagementClient(credentials, subscriptionId);       
const virtualMachines: any = computeClient.virtualMachines.list;
 console.log(`Found ${virtualMachines.length} virtual machines:`);```


标签: azureazure-pipelines-build-task

解决方案


你可以这样做,

  msRestAzure.loginWithAppServiceMSI()
        .then(credentials => {
            computeClient = new computeManagementClient(credentials, subscriptionId);
            return computeClient.virtualMachines.listAll();
        })
        .then(vms => {
            done(context, 200, {vms: vms});
        })
        .catch(err => {
            doneWithError(context, err);
        });

SAMPLE CODE


推荐阅读