Mike_Yazbeck
Enthusiast
Enthusiast

This is roughly how my code looks:

[Int64]$HKLM = "2147483650"

[String]$value = "UINumber"

$Reg_Query = Get-WmiObject -List "StdRegProv" -Namespace root\cimv2 -Computername $server -Credential $cred

ForEach ($LogicalDisk in $Win32_LogicalDisk)

{

    $LogicalDiskToPartition = $Win32_LogicalDiskToPartition | Where-Object {$_.Dependent -eq $LogicalDisk.Path}

    if ($LogicalDiskToPartition)

    {

        $DiskDriveToDiskPartition = $Win32_DiskDriveToDiskPartition | Where-Object {$_.Dependent -eq $LogicalDiskToPartition.Antecedent}

        if ($DiskDriveToDiskPartition)

        {

            $DiskDrive = $Win32_DiskDrive | Where-Object {$_.__Path -eq $DiskDriveToDiskPartition.Antecedent}

            if ($DiskDrive)

            {

                $WMI_VirtualDisk = "" | Select DeviceID, SCSIBus, SCSITargetId, Size, WinDisk, VolumeName

                $WMI_VirtualDisk.DeviceID = $LogicalDisk.DeviceID

                #$WMI_VirtualDisk.SCSIBus = $DiskDrive.SCSIBus 'Technically it does work, but only for SCSI controller 0

                $WMI_VirtualDisk.SCSITargetId = $DiskDrive.SCSITargetId

                $WMI_VirtualDisk.Size = [Math]::Round($DiskDrive.Size / 1GB)

                $WMI_VirtualDisk.WinDisk = $DiskDrive.Index

                $WMI_VirtualDisk.VolumeName = $LogicalDisk.VolumeName

               

                #new code - works!

                $PNPDeviceID = $DiskDrive.PNPDeviceID.Split("\")

                $key = "SYSTEM\CurrentControlSet\Enum\$($PNPDeviceID[0])\$($PNPDeviceID[1])\$($PNPDeviceID[2])"

                $SCSI_Controller = ($Reg_Query.GetDWORDValue($HKLM,$key,$value)).uvalue

                Switch ($SCSI_Controller)

                {

                     "32" {$SCSI_Controller = '1';Break}

                    "160" {$SCSI_Controller = '0';Break}

                    "256" {$SCSI_Controller = '1';Break}

                    "161" {$SCSI_Controller = '2';Break}

                    "224" {$SCSI_Controller = '3';Break}

                  Default {$SCSI_Controller = '0';Break}

                }

                $WMI_VirtualDisk.SCSIBus = $SCSI_Controller

                $WMI_DiskArray += $WMI_VirtualDisk

            }

        }

    }

}

Where I work we use a NetApp SAN solution. I dont think that that matters all too much, but I thought I would give you a heads up as you are likely to be using something very different Smiley Happy

The $PNPDeviceID is a property of the $DiskDrive which essentially appears to be a registry key path which if you split, you can access the registry remotely using WMI, which works like a charm :smileygrin:

I literally just got this finished and working the way I want... hope it helps :smileygrin:

View solution in original post