azure - 通过 powershell 的 Azure VM 的 Powerstate

标签 azure powershell virtual-machine

我的脚本片段如下所示:

# Collection of data
$VMs = Get-AzureRmVM
$vmOutput = $VMs | ForEach-Object { 
    [PSCustomObject]@{
        "VM Name" = $_.Name
        "VM Type" = $_.StorageProfile.osDisk.osType
        "VM Profile" = $_.HardwareProfile.VmSize
        "Environment" = $_.Tags.Environment
        "Application" = $_.Tags.Application
        "Decommission Date" = $_.Tags.Decomission
        "OS Disk Size" = $_.StorageProfile.OsDisk.DiskSizeGB
        "Data Disks Total Size" = ($_.StorageProfile.DataDisks.DiskSizeGB | Measure -Sum).Sum
        "Data Disks Amount" = ($_.StorageProfile.DataDisks.DiskSizeGB | Measure ).Count
        "Powerstate" = $_.Statuses[1].DisplayStatus
    }
}

$vmOutput | sort "Environment", "VM Type", "VM Profile", "Application" | export-csv VMReport.csv -delimiter ";" -force -notypeinformation 

我想向报告添加电源状态列,但它未包含在 Get-AzureRMVM 属性中。我必须在命令末尾添加 -status 才能显示此数据,但正如我所注意到的,它仅在包含特定资源组名称和虚拟机名称时才有效。

如何更改脚本以将电源状态包含在报告中的最后一列,而不丢弃此脚本并从头开始编写新脚本?

最佳答案

The instance view is the instance level status of the virtual machine. Specify the Status parameter to get only the instance view of a virtual machine.

查看更多详情here 。所以你只需要更改一些命令,如下所示:

$VMs = Get-AzureRmVM -Status

"Powerstate" = $_.PowerState

那么一切都会好起来的。希望这会对您有所帮助。

关于azure - 通过 powershell 的 Azure VM 的 Powerstate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54041814/

相关文章:

azure - 连接到虚拟机上的 SQL Server 的 Azure Web 角色的连接字符串

node.js - 如何将 eventGrid 添加到 NodeJS 中 Azure Functions 中的 http 触发器?

Azure 缓存错误代码 <ERRCA0017> :SubStatus<ES0009> Exeeded Quota Limits for this hour

powershell - 如何在Azure网站上远程运行PowerShell

regex - powershell:删除字符串中的字符

linux - 是否可以将进程从 native 转移到虚拟机?

python - 如何找出我的 Python 安装中有哪个 VM?

azure - 即使我没有使用该应用程序,也可以使用委派权限

powershell - 从 PowerShell Get-ChildItem -match 中排除所有子目录

python - 检查是否虚拟化操作系统的可移植方法