@@ -237,8 +237,8 @@ function _Get-sqmHardwareData
237237 $physDisks = _CIM ' Win32_DiskDrive'
238238 $netAdapt = _CIM ' Win32_NetworkAdapterConfiguration' ' IPEnabled=True'
239239 $sqlSvcs = _CIM ' Win32_Service' " Name LIKE 'MSSQL%'"
240- $disk2Part = _CIM ' Win32_DiskDriveToDiskPartition '
241- $part2Log = _CIM ' Win32_LogicalDiskToPartition '
240+ $part2Log = _CIM ' Win32_LogicalDiskToPartition '
241+ $diskPartitions = _CIM ' Win32_DiskPartition '
242242
243243 # Optionaler SSD-Check (nur Win8+ / Server 2012+, kann fehlen)
244244 $physDiskTypes = @ {}
@@ -254,26 +254,30 @@ function _Get-sqmHardwareData
254254 }
255255 catch { }
256256
257- # Disk → Laufwerksbuchstaben Mapping (fuer Partitions-Erkennung im Report)
257+ # Disk → Laufwerksbuchstaben Mapping über Win32_DiskPartition.DiskIndex
258+ # (Win32_DiskDriveToDiskPartition-Assoziationsklasse liefert .DeviceID auf manchen Systemen als $null)
258259 $diskToLetters = @ {}
259260 try
260261 {
261262 $partToLetters = @ {}
262263 foreach ($assoc in $part2Log )
263264 {
264- $partId = $assoc.Antecedent.DeviceID
265- $letter = $assoc.Dependent.DeviceID
266- if (-not $partToLetters.ContainsKey ($partId )) { $partToLetters [$partId ] = [System.Collections.Generic.List [string ]]::new() }
267- $partToLetters [$partId ].Add($letter )
265+ $partId = [string ]$assoc.Antecedent.DeviceID
266+ $letter = [string ]$assoc.Dependent.DeviceID
267+ if ($partId -and $letter )
268+ {
269+ if (-not $partToLetters.ContainsKey ($partId )) { $partToLetters [$partId ] = [System.Collections.Generic.List [string ]]::new() }
270+ $partToLetters [$partId ].Add($letter )
271+ }
268272 }
269- foreach ($assoc in $disk2Part )
273+ foreach ($part in $diskPartitions )
270274 {
271- $diskId = $assoc.Antecedent.DeviceID
272- $partId = $assoc.Dependent.DeviceID
273- if (-not $diskToLetters.ContainsKey ($diskId )) { $diskToLetters [$diskId ] = [System.Collections.Generic.List [string ]]::new() }
274- if ($partToLetters.ContainsKey ($partId ))
275+ $partId = [string ]$part.DeviceID
276+ $diskIdx = [string ]$part.DiskIndex
277+ if ($partId -and $diskIdx -ne $null -and $partToLetters.ContainsKey ($partId ))
275278 {
276- foreach ($letter in $partToLetters [$partId ]) { $diskToLetters [$diskId ].Add($letter ) }
279+ if (-not $diskToLetters.ContainsKey ($diskIdx )) { $diskToLetters [$diskIdx ] = [System.Collections.Generic.List [string ]]::new() }
280+ foreach ($letter in $partToLetters [$partId ]) { $diskToLetters [$diskIdx ].Add($letter ) }
277281 }
278282 }
279283 }
@@ -500,16 +504,16 @@ function _Build-sqmHardwareReportHtml
500504 $pdIface = if ($pd.InterfaceType ){ [string ]$pd.InterfaceType } else { ' ' }
501505 $pdDevId = if ($pd.DeviceID ) { [string ]$pd.DeviceID } else { ' ' }
502506 $pdDevNum = $pdDevId -replace ' ^\\\\\.\\PHYSICALDRIVE' , ' '
503- $pdIndex = if ($pd.Index ) { [string ]$pd.Index } else { ' n/a' }
507+ $pdIndex = if ($pd.Index -ne $null ) { [string ]$pd.Index } else { ' n/a' }
504508 $pdSerial = if ($pd.SerialNumber ) { [string ]$pd.SerialNumber } else { ' n/a' }
505509 # SSD-Info aus MSFT_PhysicalDisk wenn verfuegbar
506510 $ssdType = if ($d.PhysicalDiskTypes.ContainsKey ($pdDevNum )) { $d.PhysicalDiskTypes [$pdDevNum ] } else { ' ' }
507511 $typeDisp = if ($ssdType ) { $ssdType } elseif ($pdMedia -match ' SSD|Solid' ) { ' SSD' } else { $pdMedia }
508512 $parts = if ($pd.Partitions ) { [string ]$pd.Partitions } else { ' n/a' }
509513
510- # Laufwerksbuchstaben und Geteilt-Badge
511- $pdLetters = if ($d.DiskToLetters -and $d.DiskToLetters.ContainsKey ($pdDevId )) {
512- @ ($d.DiskToLetters [$pdDevId ] | Sort-Object )
514+ # Laufwerksbuchstaben und Geteilt-Badge (Schlüssel = DiskIndex, wie im Mapping gebaut)
515+ $pdLetters = if ($pdIndex -ne ' n/a ' -and $ d.DiskToLetters -and $d.DiskToLetters.ContainsKey ($pdIndex )) {
516+ @ ($d.DiskToLetters [$pdIndex ] | Sort-Object )
513517 } else { @ () }
514518 $letterStr = if ($pdLetters.Count -gt 0 ) { $pdLetters -join ' , ' } else { ' –' }
515519 $sharedBadge = if ($pdLetters.Count -gt 1 ) {
@@ -923,16 +927,15 @@ function _Build-sqmHardwareReportTxt
923927 $lines += " [PHYSIKALISCHE DISKS]"
924928 foreach ($pd in ($Data.PhysicalDisks | Sort-Object Index))
925929 {
926- $pdIndex = if ($pd.Index ) { [string ]$pd.Index } else { ' n/a' }
930+ $pdIndex = if ($pd.Index -ne $null ) { [string ]$pd.Index } else { ' n/a' }
927931 $pdModel = if ($pd.Model ) { [string ]$pd.Model } else { ' n/a' }
928932 $pdSize = if ($pd.Size ) { ' {0:N0}' -f ([double ]$pd.Size / 1 GB ) + ' GB' } else { ' n/a' }
929933 $pdSerial = if ($pd.SerialNumber ) { [string ]$pd.SerialNumber } else { ' n/a' }
930- $pdDevId = if ($pd.DeviceID ) { [string ]$pd.DeviceID } else { ' ' }
931- $pdLetters = if ($Data.DiskToLetters -and $Data.DiskToLetters.ContainsKey ($pdDevId )) {
932- ($Data.DiskToLetters [$pdDevId ] | Sort-Object ) -join ' , '
934+ $pdLetters = if ($pdIndex -ne ' n/a' -and $Data.DiskToLetters -and $Data.DiskToLetters.ContainsKey ($pdIndex )) {
935+ ($Data.DiskToLetters [$pdIndex ] | Sort-Object ) -join ' , '
933936 } else { ' (keine)' }
934- $sharedTag = if ($Data.DiskToLetters -and $Data.DiskToLetters.ContainsKey ($pdDevId ) -and
935- $Data.DiskToLetters [$pdDevId ].Count -gt 1 ) { ' [GETEILT]' } else { ' ' }
937+ $sharedTag = if ($pdIndex -ne ' n/a ' -and $ Data.DiskToLetters -and $Data.DiskToLetters.ContainsKey ($pdIndex ) -and
938+ $Data.DiskToLetters [$pdIndex ].Count -gt 1 ) { ' [GETEILT]' } else { ' ' }
936939 $lines += " Disk $pdIndex : $pdModel ($pdSize , S/N: $pdSerial , Laufwerke: $pdLetters )$sharedTag "
937940 }
938941 }
0 commit comments