使用Microsoft.Azure.Management.Fluent获取与Azure VM相关的详细信息

时间:2020-06-14 14:09:06

标签: azure azure-cli

我正在尝试使用Microsoft.Azure.Management.Fluent和相关的软件包集,

我需要在订阅中提供有关ALL azure VM的以下详细信息:

创建VM的人,VM的区域,VmSize,VM的当前状态(如已停止/正在运行/已释放等),

我也需要
关于VM的历史记录,以该VM在过去x个月/周内的正常运行时间为准。

使用Microsoft.Azure.Management.Fluent软件包是否有可能?

1 个答案:

答案 0 :(得分:1)

如果您想知道VM的启动和停止时间,我们可以从Azure活动日志中获取它。关于如何检索活动日志,我们可以使用Microsoft.Azure.Management.Monitor.Fluent程序包。

例如

  1. 创建服务主体并将Azure RABC角色分配给sp(我使用Azure CLI)
f;
a=6;
f

enter image description here

  1. 安装软件包
az login
#it will create a service principal and assign contributor role to the sp
az ad sp create-for-rbac -n "jonsp2"
  1. 代码
// for more details about the package, please refer to https://www.nuget.org/packages/Microsoft.Azure.Management.Fluent/
Install-Package Microsoft.Azure.Management.Fluent -Version 1.34.0