首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将主机VHDX磁盘与来宾磁盘匹配

将主机VHDX磁盘与来宾磁盘匹配
EN

Server Fault用户
提问于 2018-01-02 13:13:43
回答 1查看 795关注 0票数 0

这是一种简单的方法,可以在集群中的VM磁盘(VHDX)上获得清单,并通过it或其他愚蠢的方式将它们与来宾VM磁盘(如来宾所看到的)匹配吗?

我可以通过以下方式获取虚拟磁盘信息

代码语言:javascript
复制
$vm = get-vm MYVM
get-vhd -VMId $vm.VMId | ft VhdFormat,VhdType,FileSize,Size

我可以得到这样的磁盘空间和使用

代码语言:javascript
复制
get-WmiObject win32_logicaldisk -Computername MYVM  | ft FreeSpace,Size

我对我们所有的VM进行了查询,并根据磁盘大小大致匹配了它们--但是是否有任何磁盘GUIID或类似的磁盘GUIID公开给主机或客户,例如通过集成服务,使它们能够明确匹配?

我要找的是从客户操作系统中看到大小和使用量,并将其与VHDX的空间使用量和最大大小进行比较。

例如,一个空驱动器,最大容量为50 in,在动态VHDX中主机上占用25 in。如果在安装在来宾上的磁盘中有未分配的空间,它甚至可以被调整到最大100 on .

编辑

这永远不会简单的原因可能是因为我希望将<#>逻辑磁盘与“物理”(主机VHDX)磁盘相匹配,而且如果有多个逻辑/分区映射到给来宾的一个磁盘上,这并不总是可能的。但挑战依然存在..。

找到了一个似乎解决了这个问题的脚本,但它的目标是VMWare,而不是Hyper-V:https://4sysops.com/archives/map-vmware-virtual-disks-and-windows-drive-volumes-with-a-powershell-script/

EN

回答 1

Server Fault用户

发布于 2018-01-02 14:41:15

不需要将匹配 vhd到vm,查看get-vm的所有成员

代码语言:javascript
复制
  get-vm | get-member

 TypeName: Microsoft.HyperV.PowerShell.VirtualMachine

Name                                MemberType    Definition                                                                                                       
----                                ----------    ----------                                                                                                       
CheckpointFileLocation              AliasProperty CheckpointFileLocation = SnapshotFileLocation                                                                    
ParentCheckpointId                  AliasProperty ParentCheckpointId = ParentSnapshotId                                                                            
ParentCheckpointName                AliasProperty ParentCheckpointName = ParentSnapshotName                                                                        
VMId                                AliasProperty VMId = Id                                                                                                        
VMName                              AliasProperty VMName = Name                                                                                                    
Equals                              Method        bool Equals(System.Object obj)                                                                                   
GetHashCode                         Method        int GetHashCode()                                                                                                
GetType                             Method        type GetType()                                                                                                   
ToString                            Method        string ToString()                                                                                                
AutomaticCriticalErrorAction        Property      Microsoft.HyperV.PowerShell.CriticalErrorAction AutomaticCriticalErrorAction {get;}                              
AutomaticCriticalErrorActionTimeout Property      int AutomaticCriticalErrorActionTimeout {get;}                                                                   
AutomaticStartAction                Property      Microsoft.HyperV.PowerShell.StartAction AutomaticStartAction {get;}                                              
AutomaticStartDelay                 Property      int AutomaticStartDelay {get;}                                                                                   
AutomaticStopAction                 Property      Microsoft.HyperV.PowerShell.StopAction AutomaticStopAction {get;}                                                
CheckpointType                      Property      Microsoft.HyperV.PowerShell.CheckpointType CheckpointType {get;}                                                 
CimSession                          Property      CimSession CimSession {get;}                                                                                     
ComPort1                            Property      Microsoft.HyperV.PowerShell.VMComPort ComPort1 {get;}                                                            
ComPort2                            Property      Microsoft.HyperV.PowerShell.VMComPort ComPort2 {get;}                                                            
ComputerName                        Property      string ComputerName {get;}                                                                                       
ConfigurationLocation               Property      string ConfigurationLocation {get;}                                                                              
CPUUsage                            Property      int CPUUsage {get;}                                                                                              
CreationTime                        Property      datetime CreationTime {get;}                                                                                     
DVDDrives                           Property      Microsoft.HyperV.PowerShell.DvdDrive[] DVDDrives {get;}                                                          
DynamicMemoryEnabled                Property      bool DynamicMemoryEnabled {get;}                                                                                 
FibreChannelHostBusAdapters         Property      System.Collections.Generic.List[Microsoft.HyperV.PowerShell.VMFibreChannelHba] FibreChannelHostBusAdapters {get;}
FloppyDrive                         Property      Microsoft.HyperV.PowerShell.VMFloppyDiskDrive FloppyDrive {get;}                                                 
Generation                          Property      int Generation {get;}                                                                                            
Groups                              Property      System.Collections.Generic.IReadOnlyList[Microsoft.HyperV.PowerShell.VMGroup] Groups {get;}                      
GuestControlledCacheTypes           Property      bool GuestControlledCacheTypes {get;}                                                                            
HardDrives                          Property      Microsoft.HyperV.PowerShell.HardDiskDrive[] HardDrives {get;}                                                    
Heartbeat                           Property      System.Nullable[Microsoft.HyperV.PowerShell.VMHeartbeatStatus] Heartbeat {get;}                                  
HighMemoryMappedIoSpace             Property      uint64 HighMemoryMappedIoSpace {get;}                                                                            
Id                                  Property      guid Id {get;}                                                                                                   
IntegrationServicesState            Property      string IntegrationServicesState {get;}                                                                           
IntegrationServicesVersion          Property      version IntegrationServicesVersion {get;}                                                                        
IsClustered                         Property      bool IsClustered {get;}                                                                                          
IsDeleted                           Property      bool IsDeleted {get;}                                                                                            
LockOnDisconnect                    Property      System.Nullable[Microsoft.HyperV.PowerShell.OnOffState] LockOnDisconnect {get;}                                  
LowMemoryMappedIoSpace              Property      uint32 LowMemoryMappedIoSpace {get;}                                                                             
MemoryAssigned                      Property      long MemoryAssigned {get;}                                                                                       
MemoryDemand                        Property      long MemoryDemand {get;}                                                                                         
MemoryMaximum                       Property      long MemoryMaximum {get;}                                                                                        
MemoryMinimum                       Property      long MemoryMinimum {get;}                                                                                        
MemoryStartup                       Property      long MemoryStartup {get;}                                                                                        
MemoryStatus                        Property      string MemoryStatus {get;}                                                                                       
Name                                Property      string Name {get;}                                                                                               
NetworkAdapters                     Property      System.Collections.Generic.List[Microsoft.HyperV.PowerShell.VMNetworkAdapter] NetworkAdapters {get;}             
Notes                               Property      string Notes {get;}                                                                                              
NumaAligned                         Property      System.Nullable[bool] NumaAligned {get;}                                                                         
NumaNodesCount                      Property      int NumaNodesCount {get;}                                                                                        
NumaSocketCount                     Property      int NumaSocketCount {get;}                                                                                       
OperationalStatus                   Property      Microsoft.HyperV.PowerShell.VMOperationalStatus[] OperationalStatus {get;}                                       
ParentSnapshotId                    Property      System.Nullable[guid] ParentSnapshotId {get;}                                                                    
ParentSnapshotName                  Property      string ParentSnapshotName {get;}                                                                                 
Path                                Property      string Path {get;}                                                                                               
PrimaryOperationalStatus            Property      System.Nullable[Microsoft.HyperV.PowerShell.VMOperationalStatus] PrimaryOperationalStatus {get;}                 
PrimaryStatusDescription            Property      string PrimaryStatusDescription {get;}                                                                           
ProcessorCount                      Property      long ProcessorCount {get;}                                                                                       
RemoteFxAdapter                     Property      Microsoft.HyperV.PowerShell.VMRemoteFx3DVideoAdapter RemoteFxAdapter {get;}                                      
ReplicationHealth                   Property      Microsoft.HyperV.PowerShell.VMReplicationHealthState ReplicationHealth {get;}                                    
ReplicationMode                     Property      Microsoft.HyperV.PowerShell.VMReplicationMode ReplicationMode {get;}                                             
ReplicationState                    Property      Microsoft.HyperV.PowerShell.VMReplicationState ReplicationState {get;}                                           
ResourceMeteringEnabled             Property      bool ResourceMeteringEnabled {get;}                                                                              
SecondaryOperationalStatus          Property      System.Nullable[Microsoft.HyperV.PowerShell.VMOperationalStatus] SecondaryOperationalStatus {get;}               
SecondaryStatusDescription          Property      string SecondaryStatusDescription {get;}                                                                         
SizeOfSystemFiles                   Property      long SizeOfSystemFiles {get;}                                                                                    
SmartPagingFileInUse                Property      bool SmartPagingFileInUse {get;}                                                                                 
SmartPagingFilePath                 Property      string SmartPagingFilePath {get;}                                                                                
SnapshotFileLocation                Property      string SnapshotFileLocation {get;}                                                                               
State                               Property      Microsoft.HyperV.PowerShell.VMState State {get;}                                                                 
Status                              Property      string Status {get;}                                                                                             
StatusDescriptions                  Property      string[] StatusDescriptions {get;}                                                                               
Uptime                              Property      timespan Uptime {get;}                                                                                           
Version                             Property      string Version {get;}                                                                                            
VirtualMachineSubType               Property      Microsoft.HyperV.PowerShell.VirtualMachineSubType VirtualMachineSubType {get;}                                   
VirtualMachineType                  Property      Microsoft.HyperV.PowerShell.VirtualMachineType VirtualMachineType {get;}                                         
VMIntegrationService                Property      System.Collections.Generic.List[Microsoft.HyperV.PowerShell.VMIntegrationComponent] VMIntegrationService {get;}  

它是广泛的,并包括“硬盘驱动器”作为一个对象属性。

要在行动中看到这一点,请尝试

代码语言:javascript
复制
$vm = get-vm -name name

您可以使用powershell、点符号和intellisense来导航对象的属性,因此.

代码语言:javascript
复制
$vm.harddrives

类似地,您可以通过管道传输所有VM id以获取-vhd。

代码语言:javascript
复制
Get-VM –VMName * | Select-Object VMid | Get-VHD

关于一个好的解决方案,请参阅本文:https://social.technet.microsoft.com/Forums/en-US/8696598e-dbf6-4a47-9873-a490ecf0f737/get-storage-drives-info-for-all-vms-in-a-given-cluster?forum=winserverhyperv

下面是示例中引用的用于Edit 的脚本:

代码语言:javascript
复制
$ClusterVMs = Get-ClusterGroup -Cluster *clustername* | where grouptype -eq 'virtualmachine' | Get-VM
foreach ($vm in $ClusterVMs) { Get-VHD $vm.harddrives.path  | select @{N="Name";E={$VM.Name}},@{N="VHDPath";E={$VM.harddrives.path}},@{N="Capacity(GB)";E={[math]::Round($_.Size/ 1GB)}},@{N="Used Space(GB)";E={[math]::Round($_.FileSize/ 1GB)}}}

只需将上面的内容粘贴到powershell中,将集群名更改为您的超级-v集群的名称。

对于单个主机,请使用以下命令:

代码语言:javascript
复制
$ClusterVMs = get-vm
foreach ($vm in $ClusterVMs) { Get-VHD $vm.harddrives.path  | select @{N="Name";E={$VM.Name}},@{N="VHDPath";E={$VM.harddrives.path}},@{N="Capacity(GB)";E={[math]::Round($_.Size/ 1GB)}},@{N="Used Space(GB)";E={[math]::Round($_.FileSize/ 1GB)}}}
票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/890351

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档