$ComputerInfo = Get-ComputerInfo $cv = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' # クラスター構成を確認 $cluster = $false try { $cluster = Get-Cluster -ErrorAction Stop } catch { $cluster = $false } # HA VM の一覧 $haVMNames = @() if ($cluster) { $haVMNames = @( Get-ClusterGroup | Where-Object GroupType -eq 'VirtualMachine' | Select-Object -ExpandProperty Name ) $replicaBroker = Get-ClusterGroup | Where-Object GroupType -eq 'VMReplicaBroker' } # VM一覧 $VirtualMachines = @( Get-VM | ForEach-Object { $vm = $_ $vm | Select-Object *, @{ Name = 'HA' Expression = { $_.Name -in $haVMNames } }, @{ Name = 'VCPU' Expression = { Get-VMProcessor -VM $_ } }, @{ Name = 'VRAM' Expression = { Get-VMMemory -VM $_ } }, @{ Name = 'VMFirmware' Expression = { if ($_.Generation -eq 2) { Get-VMFirmware -VM $_ } } }, @{ Name = 'VMSecurity' Expression = { Get-VMSecurity -VM $_ } }, @{ Name = 'VNIC' Expression = { @(Get-VMNetworkAdapter -VM $_) } }, @{ Name = 'VHD' Expression = { @(Get-VMHardDiskDrive -VM $_) } }, @{ Name = 'VMSnapshot' Expression = { @(Get-VMSnapshot -VM $_ -ErrorAction SilentlyContinue) } } } ) # Hyper-V / Cluster 関連サービス $services = @( 'vmms' 'vmcompute' 'hvhost' 'clussvc' ) $HyperVServices = @( Get-Service -Name $services -ErrorAction SilentlyContinue ) # Hyper-V関連のイベントログ(重大/エラー/警告) $start = (Get-Date).AddHours(-24) $HyperVLogs = @( 'System' 'Application' 'Security' Get-WinEvent -ListLog 'Microsoft-Windows-Hyper-V-*' | Where-Object { $_.IsEnabled -and $_.RecordCount -gt 0 } | Select-Object -ExpandProperty LogName if ($cluster) { Get-WinEvent -ListLog 'Microsoft-Windows-FailoverClustering-*' | Where-Object { $_.IsEnabled -and $_.RecordCount -gt 0 } | Select-Object -ExpandProperty LogName } ) $HyperVEvents = foreach ($log in $HyperVLogs) { Get-WinEvent -FilterHashtable @{ LogName = $log StartTime = $start Level = 1, 2, 3 # Critical, Error, Warning } -ErrorAction SilentlyContinue } $inventory = [pscustomobject]@{ CollectedAt = Get-Date OSInfo = [pscustomobject]@{ ComputerName = $env:COMPUTERNAME OperatingSystem = $ComputerInfo.OSName OSBuild = "$($cv.CurrentBuild).$($cv.UBR)" isCluster = if ($cluster) { $true } else { $false } ClusterName = if ($cluster) { $cluster.Name } else { $null } HotFix = @(Get-HotFix) WindowsFeatures = @(Get-WindowsFeature) } ComputerInfo = $ComputerInfo HyperV = [pscustomobject]@{ Services = $HyperVServices NumaNodes = @(Get-VMHostNumaNode) VMHost = Get-VMHost VMReplicationServer = if($cluster) { if ($replicaBroker) { Get-VMReplicationServer -ComputerName $replicaBroker.Name } else { $null } } else { Get-VMReplicationServer } VMReplication = @(Get-VMReplication) } Network = [pscustomobject]@{ NetAdapters = @( Get-NetAdapter ) VMSwitches = @( Get-VMSwitch ) NetNats = @( Get-NetNat ) NetNatStaticMappings = @( Get-NetNatStaticMapping ) ManagementOSAdapters = @( Get-VMNetworkAdapter -ManagementOS ) IPAddresses = @( Get-NetIPConfiguration ) FirewallRules = @( Get-NetFirewallRule -PolicyStore ActiveStore ) } VirtualMachines = @( $VirtualMachines ) Storage = [pscustomobject]@{ PhysicalDisks = @( Get-PhysicalDisk ) Volumes = @( Get-Volume ) ClusterSharedVolumes = @( if ($cluster) { Get-ClusterSharedVolume } ) S2D = if ($cluster) { $s2dPool = @(Get-StoragePool -FriendlyName 'S2D*' -ErrorAction SilentlyContinue) if ($s2dPool) { [pscustomobject]@{ StoragePools = $s2dPool PhysicalDisks = @( Get-StorageSubsystem -FriendlyName 'Cluster*' | Get-PhysicalDisk ) VirtualDisks = @( $s2dPool | Get-VirtualDisk ) } } else { $null } } else { $null } } HyperVEvents = @( $HyperVEvents | Sort-Object TimeCreated | Select-Object TimeCreated, LogName, Id, Level, LevelDisplayName, Message ) } $timestamp = Get-Date -Format 'yyyyMMdd-HHmmss' $inventory | Export-Clixml ".\HyperVHost-Inventory-$env:COMPUTERNAME-$timestamp.xml" & .\get-hypervhostsummary.ps1 ".\HyperVHost-Inventory-$env:COMPUTERNAME-$timestamp.xml" Write-Host "`nOutput to: .\HyperVHost-Inventory-$env:COMPUTERNAME-$timestamp.xml"