How to check if eide or sata hard drive with powershell

I like to know if there is any win32 class that can determine if the hard drive is eide or sata. Thanks in advance.

+1
source share
2 answers

There is no direct way to find this. However, you can use the caption property for Win32_DiskDrive and analyze it to see if you have an ATA or SCSI drive. On my system, the SATA drive has the signature ST9500420AS ATA Device .

How do you do this:

 Get-WMIObject -Class Win32_DiskDrive | Select Caption, Index 

You can analyze the Caption property to see if it contains ATA or SCSI.

+2
source

As indicated in another answer , the disk header (i.e. model name) may include this information, you can navigate through WMI object associations until you reach the device with a more final name / signature / other property.

Saving devmgmt.msc with an open window | Devices when connected, open during development, will simplify the situation.

The key for navigating the WMI object chart is ASSOCIATORS OF .

So (using lots of aliases and other shortcuts to make this easier: I would avoid this in that I plan to reuse it):

 gwmi win32_DiskDrive | %{gwmi -query "ASSOCIATORS OF {$($_.__RELPATH)} where resultclass = Win32_PnpEntity"} 

will receive Win32_PnpEntity objects for each drive.

Repeating this on the first (for research purposes) disk to another level to find what associations exist:

 gwmi win32_DiskDrive | %{gwmi -query "ASSOCIATORS OF {$($_.__RELPATH)} where resultclass = Win32_PnpEntity" | %{gwmi -query "ASSOCIATORS OF {$($_.__RELPATH)}"}} | fl __CLASS,__RELPATH 

shows a combination of WMI classes:

  __CLASS: Win32_SystemDriver
 __RELPATH: Win32_SystemDriver.Name = "disk"

 __CLASS: Win32_ComputerSystem
 __RELPATH: Win32_ComputerSystem.Name = "hostname"

 __CLASS: Win32_IDEController
 __RELPATH: Win32_IDEController.DeviceID = "PCIIDE \\ IDECHANNEL \\ 4 & 5ECF4F & 0 & 2"

 __CLASS: CIM_DataFile
 __RELPATH: CIM_DataFile.Name = "c: \\ windows \\ system32 \\ drivers \\ disk.sys"

 __CLASS: Win32_DiskDrive
 __RELPATH: Win32_DiskDrive.DeviceID = "\\\\. \\ PHYSICALDRIVE0" 

The last one is just a switch to disk, and each device is connected to a computer system. But the Win32_IDEController object looks interesting.

It had the ProtocolSupported property with values ​​for different buses, but all instances are 37 ("IDE"), and there are instances for both controller channels and controllers:

  PS [64bit] C: \ bin \ PowerShell> gwmi win32_idecontroller |  ft -auto -wrap caption, description

 caption description
 ------- -----------
 ATA Channel 1 IDE Channel
 ATA Channel 0 IDE Channel
 ATA Channel 1 IDE Channel
 Standard AHCI 1.0 Serial ATA Controller Standard AHCI 1.0 Serial ATA Controller
 Standard AHCI 1.0 Serial ATA Controller Standard AHCI 1.0 Serial ATA Controller
 Standard Dual Channel PCI IDE Controller Standard Dual Channel PCI IDE Controller
 ATA Channel 0 IDE Channel
 ATA Channel 1 IDE Channel
 ATA Channel 2 IDE Channel
 ATA Channel 3 IDE Channel
 ATA Channel 4 IDE Channel
 ATA Channel 5 IDE Channel
 ATA Channel 0 IDE Channel 

So it will not be as easy as getting to Win32_IDEController .

Return and extension of Win32_IDEController associated with Win32_PnpDevice for my disk:

 gwmi win32_DiskDrive | %{gwmi -query "ASSOCIATORS OF {$($_.__RELPATH)} where resultclass = Win32_PnpEntity" | %{gwmi -query "ASSOCIATORS OF {$($_.__RELPATH)} where resultclass = Win32_IDEController"}} | fl Caption,Description 
  caption: ATA Channel 2
 description: IDE Channel 

So, what is the SATA channel, will the channel be connected to the controller? And simplification: to exit the foreach-object does not need an internal pipeline:

 gwmi win32_DiskDrive | %{gwmi -query "ASSOCIATORS OF {$($_.__RELPATH)} where resultclass = Win32_PnpEntity"} | %{gwmi -query "ASSOCIATORS OF {$($_.__RELPATH)} where resultclass = Win32_IDEController"} | %{gwmi -query "ASSOCIATORS OF {$($_.__RELPATH)} where resultclass = Win32_IDEController"} | fl __CLASS,__RELPATH.Caption,Description 

This does not find anything, but a little research (capturing __RELPATH from one query to insert into another to keep the pipeline under control) indicates that the following associations:

  DiskDrive -> PnpDevice -> IDEContoller -> PnpDevice -> IDEController 

should get the result. Avoiding the loop (because IDEController has two PnpDevice objects connected) remains as an exercise.

Once a true controller is reached, the header should be parsed.

Bad news

Repeating the request for controllers in another system gave three instances of the Standard Dual Channel PCI IDE Controller , despite the presence of four controllers (1 and times IDE and 3 × SATA), this may be due to non-trivial mapping due to the fact that one works how is raid?

And, of course, SATA has essentially the same logical (software) interface as the IDE, to do hardware work with software (the same goes for PCI and PCI-Express) means that the OS really doesn't need to know.

+9
source

All Articles