【问题标题】:Azure/PowerShell : How do I query disk state? (Azure Managed Disks)Azure/PowerShell:如何查询磁盘状态? (Azure 托管磁盘)
【发布时间】:2019-02-02 15:28:15
【问题描述】:

在 Azure 门户中,在磁盘(托管磁盘)边栏选项卡下,有一个名为“磁盘状态”的列标题

这显示为附加未附加。

我想运行一个脚本来显示我订阅中的所有未附加磁盘,以便我可以删除它们。

运行 cmdlet

get-azurermdisk

这给了我所有的磁盘,但是我如何获得显示磁盘状态的参数?

Get-member 显示一堆属性,但不显示磁盘状态。

TypeName: Microsoft.Azure.Commands.Compute.Automation.Models.PSDiskList
Name               MemberType Definition
----               ---------- ----------
Equals             Method     bool Equals(System.Object obj)
GetHashCode        Method     int GetHashCode()
GetType            Method     type GetType()
ToPSDisk           Method     Microsoft.Azure.Commands.Compute.Automation.Models.PSDisk ToPSDisk()
ToString           Method     string ToString()
Validate           Method     void Validate()
CreationData       Property   Microsoft.Azure.Management.Compute.Models.CreationData CreationData {get;set;}
DiskSizeGB         Property   System.Nullable[int] DiskSizeGB {get;set;}
EncryptionSettings Property   Microsoft.Azure.Management.Compute.Models.EncryptionSettings EncryptionSettings {get;set;}
Id                 Property   string Id {get;}
Location           Property   string Location {get;set;}
ManagedBy          Property   string ManagedBy {get;}
Name               Property   string Name {get;}
OsType             Property   System.Nullable[Microsoft.Azure.Management.Compute.Models.OperatingSystemTypes] OsType {get;set;}
ProvisioningState  Property   string ProvisioningState {get;}
ResourceGroupName  Property   string ResourceGroupName {get;}
Sku                Property   Microsoft.Azure.Management.Compute.Models.DiskSku Sku {get;set;}
Tags               Property   System.Collections.Generic.IDictionary[string,string] Tags {get;set;}
TimeCreated        Property   System.Nullable[datetime] TimeCreated {get;}
Type               Property   string Type {get;}
Zones              Property   System.Collections.Generic.IList[string] Zones {get;set;}

【问题讨论】:

    标签: azure powershell


    【解决方案1】:

    根据https://docs.microsoft.com/en-us/azure/virtual-machines/windows/find-unattached-disks 未附加磁盘上的文档,Get-AzureRmDisk 的 ManagedBy 属性设置为 $null

    这意味着

    Get-AzureRmDisk | Where-Object ManagedBy -ne $null
    

    应该显示所有附加磁盘和

    Get-AzureRmDisk | Where-Object ManagedBy -eq $null
    

    应该显示所有未附加磁盘

    【讨论】:

      【解决方案2】:

      尝试使用

      Get-AzureRmDisk | Where-Object DiskState -eq "Unattached"
      

      【讨论】:

        猜你喜欢
        • 2019-04-07
        • 2019-07-03
        • 2017-11-14
        • 2013-03-01
        • 2017-07-12
        • 2017-07-08
        • 2021-09-22
        • 2017-07-26
        • 2020-03-17
        相关资源
        最近更新 更多