azure - Azure/PowerShell:如何查询磁盘状态?(Azure 托管磁盘)
问题描述
在 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;}
解决方案
根据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
应该显示所有未连接的磁盘
推荐阅读
- r - RStudio Sweave 错误 -> 退出代码 -1073740791
- reporting-services - 如何在 SSRS 中使用 Switch?
- flutter - 删除 ListView 中的顶部填充,放置在没有 appBar 的脚手架内
- c# - 起订量不返回时间结果
- javascript - 警告:来自服务器的额外属性:已禁用
- outlook - Outlook 插件 API displayForwardForm Office JS
- python - 我正在尝试使用 python 为链表实现附加功能,但得到的答案不正确,请帮我解决这个问题
- numpy - 拟合自定义分布 scipy.stats 会溢出
- c# - Linq 组通过提供不正确的统计信息
- electron - 从打包的 asar 应用程序电子访问 extraFiles 电子生成器