使用 PowerShell 在 Windows 故障转移群集管理器中获取包含特定卷的群集磁盘

问题描述 投票:0回答:1

我需要获取上面有特定卷的集群磁盘。

假设 Get-ClusterResource 输出多个集群磁盘,我需要找到哪个磁盘具有特定名称的卷。

我需要弄清楚如何获取附加到 ClusterResource 对象的卷。

这必须通过 PowerShell 完成。

windows powershell windows-server failover failovercluster
1个回答
0
投票

微软还没有记录什么

Microsoft.FailoverClusters.PowerShell.ClusterResource
所以我只能推测数据的格式如何,但它会是这样的:

获取磁盘列表,以便您可以看到它们的名称:

Get-ClusterResource

然后,抓住您想要的特定磁盘,并查看它的卷属性:

$Disk = Get-ClusterResource -Name <NameOfDiskGoesHere>

# check what's inside $Disk to see what the data looks like
$Disk # Or $Disk[0]

# Assuming the volumes attribute is called just that, check what it's data is like this:

$Disk.Volumes

或者,将整个列表分配给一个变量并通过索引引用一个变量,按它们出现的顺序逐字指定一个数字。

$Disk = Get-ClusterResource
$Disk[0] # First disk
$Disk[1] # Second disk, etc.

$Disk[0].Volumes

假设卷也是一个列表,并且每个条目都有自己的“Name”属性,您可以像这样列出所有名为“VolumeName”的卷:

$Disk0.Volumes | Where-Object $_.Name -eq "VolumeName"

要获取所有磁盘和所有卷的名称,然后检查哪一个具有您所需的卷,您可以遍历所有列表:

# Name of the volume you want, it will be CaSe SeNsItIvE
$TargetVolume = "VolumeName"

$Disks = Get-ClusterResource

# Empty array to hold our final disks.
$TargetDisks = @()

Foreach ($Disk in $Disks) {    
    # Empty array to hold our volumes.
    $VolumeList = @()

    Foreach ($Volume in $Disk.Volumes) {    
        # Add our volume to the list.
        $VolumeList += $Volume
    }
    # Print some information so far.
    Write-Output "$($Disk.Name) has $($VolumeList.Count) volumes. They are called $($VolumeList -Join ", ")"

    # Check if our Target volume was in this disk.
    If ($VolumeList.Contains($TargetVolume)) {
        $TargetDisks += $Disk.Name
    }    
}

Write-Output "The following disks were found to contain a volume called $($TargetVolume): $($TargetDisks -Join ", ")"
© www.soinside.com 2019 - 2024. All rights reserved.