Sign in to follow this  
Followers 0
cmattb

Detect what controller drives are on

1 post in this topic

I've been trying to a get a script working that will output specific information about all the harddrives installed in a system. At the moment, I'm hung up on detecting what controller the drive is on. I've found how to detect all the drives, and how to detect all the controllers but I haven't been able to connect the two. Any help would be greatly appreciated.

Code so far:

$oWMISvc = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")

;~ Get all harddrives
$colDiskDrives = $oWMISvc.ExecQuery("SELECT * FROM Win32_DiskDrive where MediaType='Fixed hard disk media' or MediaType='Fixed hard disk'")
$i = 0
For $oDiskDrive In $colDiskDrives
    $i = $i+1
ConsoleWrite("<HardDrive"&$i&">"&@CRLF)
    $HDSize = ""
    $HDSize=$oDiskDrive.Size / (1000^3)
    $HDSize=Round($HDSize,0)&"GB"
    ConsoleWrite("<Model>"&$oDiskDrive.Model&"</Model>"&@CRLF)
    ConsoleWrite("<Size>"&$HDSize&"</Size>"&@CRLF)
;~  Get partition information for each drive
    $colPartitions = $oWMISvc.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" & $oDiskDrive.DeviceId & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition")
    For $oPartition In $colPartitions
        $colLogicalDisks = $oWMISvc.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & $oPartition.DeviceId & "'} WHERE AssocClass = Win32_LogicalDiskToPartition")
        For $oLogicalDisk In $colLogicalDisks
            ConsoleWrite("<Disknum>Disk #"&$oPartition.DiskIndex &"</Disknum>"& @CRLF)
            $sLogSize = ""
            $sLogSize=$oLogicalDisk.Size / (1000^3)
            $sLogSize=Round($sLogSize,0)&"GB"
            ConsoleWrite("<Drive>"&$oLogicalDisk.DeviceId&"</Drive>"& @CRLF)
            ConsoleWrite("<Size>"&$sLogSize&"</Size>"& @CRLF)
        Next
    Next
ConsoleWrite("</HardDrive"&$i&">"&@CRLF&@CRLF)
Next

;~ Get all IDE controllers
$colcont = $oWMISvc.ExecQuery("select * from Win32_IDEController")
$i = 0
For $objcont in $colcont
    $i = $i+1
    ConsoleWrite( "<"&$i&">"&@CRLF)
    ConsoleWrite("<Description>"&$objcont.Description&"</Description>"&@CRLF)
    ConsoleWrite("<Name>"&$objcont.Name&"</Name>"&@CRLF)
    ConsoleWrite("<Manufacturer>"&$objcont.Manufacturer &"</Manufacturer>"&@CRLF)
    ConsoleWrite("</"&$i&">"&@CRLF&@CRLF)
Next

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0