![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Associating WMI disk classes Hi, I'm trying to create a PS script, that enumerates physical disks, and for each, lists logical volumes. So, the output should be something like: \\.\PHYSICALDRIVE0 C: D: E: \\.\PHYSICALDRIVE1 F: G: ...etc... For this, I've used two WMI classes. The first one gets the physical disks, the second one the logical volumes (see below). However, how does these two get linked together? I've tried using Associators of, but with no luck. $strComputer = "." $colWMIDiskDrives = get-wmiobject -class "Win32_DiskDrive" -namespace "root\CIMV2" ´ -computername $strComputer $colWMILogicalDisks = get-wmiobject -class "Win32_LogicalDisk" - namespace "root\CIMV2" ´ -computername $strComputer |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Associating WMI disk classes Quote: > $strComputer = "." > $colWMIDiskDrives = get-wmiobject -class "Win32_DiskDrive" -namespace > "root\CIMV2" ´ > -computername $strComputer > $colWMILogicalDisks = get-wmiobject -class "Win32_LogicalDisk" - > namespace "root\CIMV2" ´ > -computername $strComputer > PSH>gwmi Win32_LogicalDisk|select-object __PATH __PATH ------ \\xxx\root\cimv2:Win32_LogicalDisk.DeviceID="C:" \\xxx\root\cimv2:Win32_LogicalDisk.DeviceID="D:" \\xxx\root\cimv2:Win32_LogicalDisk.DeviceID="E:" I don't have a server to test whether it will handle properly multiple logical disks per physical disk. Marco -- Microsoft MVP - Windows PowerShell http://www.microsoft.com/mvp PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com |
My System Specs![]() |
| | #3 (permalink) |
| | RE: Associating WMI disk classes "Thomas Makro" wrote: Quote: > Hi, I'm trying to create a PS script, that enumerates physical disks, > and for each, lists logical volumes. So, the output should be > something like: > \\.\PHYSICALDRIVE0 > C: D: E: > \\.\PHYSICALDRIVE1 > F: G: > > ...etc... > > For this, I've used two WMI classes. The first one gets the physical > disks, the second one the logical volumes (see below). However, how > does these two get linked together? > I've tried using Associators of, but with no luck. > > $strComputer = "." > $colWMIDiskDrives = get-wmiobject -class "Win32_DiskDrive" -namespace > "root\CIMV2" ´ > -computername $strComputer > $colWMILogicalDisks = get-wmiobject -class "Win32_LogicalDisk" - > namespace "root\CIMV2" ´ > -computername $strComputer > > Win32_DiskDrive with Win32_DiskPartition : ASSOCIATORS OF {Win32_DiskDrive.DeviceID="\\.\PHYSICALDRIVE0"} WHERE AssocClass = Win32_DiskDriveToDiskPartition and then associate results of that query with Win32_LogicalDisk: ASSOCIATORS OF {Win32_DiskPartition.DeviceID="Disk #0, Partition #0"} WHERE AssocClass = Win32_LogicalDiskToPartition You need to execute the second query for each object returned by the first query.I don't have time to test this now, so I'm not sure about double or single quotes. Hope this helps. -- urkec |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Associating WMI disk classes I was able to run this on XP successfully but it fails on Win2003: $DiskDrive = Get-WmiObject Win32_DiskDrive $DiskDrive | foreach {$_.DeviceID} $DiskDrive | foreach { $_.GetRelated("Win32_DiskPartition")} | foreach {$_.GetRelated("Win32_LogicalDisk")} | foreach {$_.DeviceID} \\.\PHYSICALDRIVE0 C: D: Building up on urkec worked on both versions: $DiskDrive = Get-WmiObject Win32_DiskDrive $DiskDrive | foreach { $_.DeviceID $d = gwmi -q "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='$($_.DeviceID)'} WHERE AssocClass = Win32_DiskDriveToDiskPartition" | foreach {$_.name} $d | foreach { gwmi -q "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='$_'} WHERE AssocClass = Win32_LogicalDiskToPartition"} | foreach {$_.DeviceID} } \\.\PHYSICALDRIVE0 C: D: ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Quote: > Hi, I'm trying to create a PS script, that enumerates physical disks, > and for each, lists logical volumes. So, the output should be > something like: > \\.\PHYSICALDRIVE0 > C: D: E: > \\.\PHYSICALDRIVE1 > F: G: > ...etc... > > For this, I've used two WMI classes. The first one gets the physical > disks, the second one the logical volumes (see below). However, how > does these two get linked together? > I've tried using Associators of, but with no luck. > $strComputer = "." > $colWMIDiskDrives = get-wmiobject -class "Win32_DiskDrive" -namespace > "root\CIMV2" ´ > -computername $strComputer > $colWMILogicalDisks = get-wmiobject -class "Win32_LogicalDisk" - > namespace "root\CIMV2" ´ > -computername $strComputer |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Associating WMI disk classes On Jan 29, 10:05*pm, urkec <ur...@xxxxxx> wrote: Quote: > "Thomas Makro" wrote: Quote: > > Hi, I'm trying to create a PS script, that enumerates physical disks, > > and for each, lists logical volumes. So, the output should be > > something like: > > \\.\PHYSICALDRIVE0 > > * * C: D: E: > > \\.\PHYSICALDRIVE1 > > * * F: G: Quote: > > ...etc... Quote: > > For this, I've used two WMI classes. The first one gets the physical > > disks, the second one the logical volumes (see below). However, how > > does these two get linked together? > > I've tried using Associators of, but with no luck. Quote: > > $strComputer = "." > > $colWMIDiskDrives = get-wmiobject -class "Win32_DiskDrive" -namespace > > "root\CIMV2" *´ > > * * -computername $strComputer > > $colWMILogicalDisks = get-wmiobject -class "Win32_LogicalDisk" - > > namespace "root\CIMV2" ´ > > * * -computername $strComputer > You can't associate them directly. You first need to associate > Win32_DiskDrive with Win32_DiskPartition : > > ASSOCIATORS OF {Win32_DiskDrive.DeviceID="\\.\PHYSICALDRIVE0"} WHERE > AssocClass = Win32_DiskDriveToDiskPartition > > and then associate results of that query with Win32_LogicalDisk: > > ASSOCIATORS OF {Win32_DiskPartition.DeviceID="Disk #0, Partition #0"} WHERE > AssocClass = Win32_LogicalDiskToPartition > > You need to execute the second query for each object returned by the first > query.I don't have time to test this now, so I'm not sure about double or > single quotes. > > Hope this helps. > > -- > urkec- Hide quoted text - > > - Show quoted text - $strComputer = "." $colDiskDrives = Get-WmiObject Win32_DiskDrive -ComputerName $strComputer $colDiskDrives | ForEach-Object { "Physical Disk:" + $_.caption + " -- " + $_.deviceid $strDriveDeviceID = $_.deviceid $query1 = "Associators of {Win32_DiskDrive.DeviceID='$strDriveDeviceID'} Where AssocClass=Win32_DiskDriveToDiskPartition" $colPartitions = get-wmiobject -query $query1 $colPartitions | ForEach-Object { "Disk Partition: " + $_.DeviceID $strPartitionDeviceID = $_.DeviceID $query2 = "Associators of {Win32_DiskPartition.DeviceID='$strPartitionDeviceID'} Where AssocClass=Win32_LogicalDiskToPartition" $colLogicalDisks = Get-WmiObject -query $query2 $colLogicalDisks | ForEach-Object { "Logical Disk: " + $_.deviceid } "" } "" } Output looks like this: Physical Disk:SAMSUNG HD080HJ/P -- \\.\PHYSICALDRIVE0 Disk Partition: Disk #0, Partition #0 Logical Disk: Disk Partition: Disk #0, Partition #1 Logical Disk: C: Disk Partition: Disk #0, Partition #2 Logical Disk: D: -aleksandar http://powershellers.blogspot.com PS Thank you /\/\o\/\/. |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Associating WMI disk classes After chatting with Alexandair (his version works for me ctp2 / xp ) I came up woth this version : $drives = Get-WmiObject Win32_DiskDrive -ComputerName $strComputer $s = New-Object System.Management.ManagementObjectSearcher $s2 = New-Object System.Management.ManagementObjectSearcher $qPartition = new System.Management.RelatedObjectQuery $qPartition.RelationshipClass = 'Win32_DiskDriveToDiskPartition' $qLogicalDisk = new System.Management.RelatedObjectQuery $qLogicalDisk.RelationshipClass = 'Win32_LogicalDiskToPartition' $drives |% { $_.Caption $qPartition.SourceObject = $_ $s.Query = $qPartition $s.get() |% { $_.DeviceID $qLogicalDisk.SourceObject = $_ $qLogicalDisk.Query = $q2 $s.get() } } more about this way of working ou can also find here : http://mow001.blogspot.com/2006/10/p...c2-series.html might make a entry on my new blog also later Greetings /\/\o\/\/ "Shay Levi" wrote: Quote: > > I was able to run this on XP successfully but it fails on Win2003: > > $DiskDrive = Get-WmiObject Win32_DiskDrive > $DiskDrive | foreach {$_.DeviceID} > $DiskDrive | foreach { $_.GetRelated("Win32_DiskPartition")} | foreach {$_.GetRelated("Win32_LogicalDisk")} > | foreach {$_.DeviceID} > > \\.\PHYSICALDRIVE0 > C: > D: > > > Building up on urkec worked on both versions: > > $DiskDrive = Get-WmiObject Win32_DiskDrive > $DiskDrive | foreach { > $_.DeviceID > $d = gwmi -q "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='$($_.DeviceID)'} > WHERE AssocClass = Win32_DiskDriveToDiskPartition" | foreach {$_.name} > $d | foreach { gwmi -q "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='$_'} > WHERE AssocClass = Win32_LogicalDiskToPartition"} | foreach {$_.DeviceID} > } > > \\.\PHYSICALDRIVE0 > C: > D: > > ----- > Shay Levi > $cript Fanatic > http://scriptolog.blogspot.com > Quote: > > Hi, I'm trying to create a PS script, that enumerates physical disks, > > and for each, lists logical volumes. So, the output should be > > something like: > > \\.\PHYSICALDRIVE0 > > C: D: E: > > \\.\PHYSICALDRIVE1 > > F: G: > > ...etc... > > > > For this, I've used two WMI classes. The first one gets the physical > > disks, the second one the logical volumes (see below). However, how > > does these two get linked together? > > I've tried using Associators of, but with no luck. > > $strComputer = "." > > $colWMIDiskDrives = get-wmiobject -class "Win32_DiskDrive" -namespace > > "root\CIMV2" ´ > > -computername $strComputer > > $colWMILogicalDisks = get-wmiobject -class "Win32_LogicalDisk" - > > namespace "root\CIMV2" ´ > > -computername $strComputer > > |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Associating WMI disk classes Sorry wrong versoin Correrion on script : $drives = Get-WmiObject Win32_DiskDrive -ComputerName $strComputer $s = New-Object System.Management.ManagementObjectSearcher $s2 = New-Object System.Management.ManagementObjectSearcher $qPartition = new-object System.Management.RelatedObjectQuery $qPartition.RelationshipClass = 'Win32_DiskDriveToDiskPartition' $qLogicalDisk = new-object System.Management.RelatedObjectQuery $qLogicalDisk.RelationshipClass = 'Win32_LogicalDiskToPartition' $drives |% { $_.Caption $qPartition.SourceObject = $_ $s.Query = $qPartition $s.get() |% { $_.DeviceID $qLogicalDisk.SourceObject = $_ $s2.query = $qLogicalDisk $s2.get() } } enjoy, Greetings /\/\o\/\/ "/\/\o\/\/ [MVP]" wrote: Quote: > After chatting with Alexandair (his version works for me ctp2 / xp ) > I came up woth this version : > > $drives = Get-WmiObject Win32_DiskDrive -ComputerName $strComputer > > $s = New-Object System.Management.ManagementObjectSearcher > $s2 = New-Object System.Management.ManagementObjectSearcher > > $qPartition = new System.Management.RelatedObjectQuery > $qPartition.RelationshipClass = 'Win32_DiskDriveToDiskPartition' > > $qLogicalDisk = new System.Management.RelatedObjectQuery > $qLogicalDisk.RelationshipClass = 'Win32_LogicalDiskToPartition' > > $drives |% { > $_.Caption > $qPartition.SourceObject = $_ > $s.Query = $qPartition > $s.get() |% { > $_.DeviceID > $qLogicalDisk.SourceObject = $_ > $qLogicalDisk.Query = $q2 > $s.get() > } > } > > more about this way of working ou can also find here : > http://mow001.blogspot.com/2006/10/p...c2-series.html > > might make a entry on my new blog also later > > Greetings /\/\o\/\/ > > "Shay Levi" wrote: > Quote: > > > > I was able to run this on XP successfully but it fails on Win2003: > > > > $DiskDrive = Get-WmiObject Win32_DiskDrive > > $DiskDrive | foreach {$_.DeviceID} > > $DiskDrive | foreach { $_.GetRelated("Win32_DiskPartition")} | foreach {$_.GetRelated("Win32_LogicalDisk")} > > | foreach {$_.DeviceID} > > > > \\.\PHYSICALDRIVE0 > > C: > > D: > > > > > > Building up on urkec worked on both versions: > > > > $DiskDrive = Get-WmiObject Win32_DiskDrive > > $DiskDrive | foreach { > > $_.DeviceID > > $d = gwmi -q "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='$($_.DeviceID)'} > > WHERE AssocClass = Win32_DiskDriveToDiskPartition" | foreach {$_.name} > > $d | foreach { gwmi -q "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='$_'} > > WHERE AssocClass = Win32_LogicalDiskToPartition"} | foreach {$_.DeviceID} > > } > > > > \\.\PHYSICALDRIVE0 > > C: > > D: > > > > ----- > > Shay Levi > > $cript Fanatic > > http://scriptolog.blogspot.com > > Quote: > > > Hi, I'm trying to create a PS script, that enumerates physical disks, > > > and for each, lists logical volumes. So, the output should be > > > something like: > > > \\.\PHYSICALDRIVE0 > > > C: D: E: > > > \\.\PHYSICALDRIVE1 > > > F: G: > > > ...etc... > > > > > > For this, I've used two WMI classes. The first one gets the physical > > > disks, the second one the logical volumes (see below). However, how > > > does these two get linked together? > > > I've tried using Associators of, but with no luck. > > > $strComputer = "." > > > $colWMIDiskDrives = get-wmiobject -class "Win32_DiskDrive" -namespace > > > "root\CIMV2" ´ > > > -computername $strComputer > > > $colWMILogicalDisks = get-wmiobject -class "Win32_LogicalDisk" - > > > namespace "root\CIMV2" ´ > > > -computername $strComputer > > > > |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Associating WMI disk classes With Identing ;-) http://thepowershellguy.com/blogs/po...owershell.aspx "/\/\o\/\/ [MVP]" wrote: Quote: > Sorry wrong versoin > Correrion on script : > > $drives = Get-WmiObject Win32_DiskDrive -ComputerName $strComputer > > $s = New-Object System.Management.ManagementObjectSearcher > $s2 = New-Object System.Management.ManagementObjectSearcher > > $qPartition = new-object System.Management.RelatedObjectQuery > $qPartition.RelationshipClass = 'Win32_DiskDriveToDiskPartition' > > $qLogicalDisk = new-object System.Management.RelatedObjectQuery > $qLogicalDisk.RelationshipClass = 'Win32_LogicalDiskToPartition' > > $drives |% { > $_.Caption > $qPartition.SourceObject = $_ > $s.Query = $qPartition > $s.get() |% { > $_.DeviceID > $qLogicalDisk.SourceObject = $_ > $s2.query = $qLogicalDisk > $s2.get() > } > } > > enjoy, > > Greetings /\/\o\/\/ > > "/\/\o\/\/ [MVP]" wrote: > Quote: > > After chatting with Alexandair (his version works for me ctp2 / xp ) > > I came up woth this version : > > > > $drives = Get-WmiObject Win32_DiskDrive -ComputerName $strComputer > > > > $s = New-Object System.Management.ManagementObjectSearcher > > $s2 = New-Object System.Management.ManagementObjectSearcher > > > > $qPartition = new System.Management.RelatedObjectQuery > > $qPartition.RelationshipClass = 'Win32_DiskDriveToDiskPartition' > > > > $qLogicalDisk = new System.Management.RelatedObjectQuery > > $qLogicalDisk.RelationshipClass = 'Win32_LogicalDiskToPartition' > > > > $drives |% { > > $_.Caption > > $qPartition.SourceObject = $_ > > $s.Query = $qPartition > > $s.get() |% { > > $_.DeviceID > > $qLogicalDisk.SourceObject = $_ > > $qLogicalDisk.Query = $q2 > > $s.get() > > } > > } > > > > more about this way of working ou can also find here : > > http://mow001.blogspot.com/2006/10/p...c2-series.html > > > > might make a entry on my new blog also later > > > > Greetings /\/\o\/\/ > > > > "Shay Levi" wrote: > > Quote: > > > > > > I was able to run this on XP successfully but it fails on Win2003: > > > > > > $DiskDrive = Get-WmiObject Win32_DiskDrive > > > $DiskDrive | foreach {$_.DeviceID} > > > $DiskDrive | foreach { $_.GetRelated("Win32_DiskPartition")} | foreach {$_.GetRelated("Win32_LogicalDisk")} > > > | foreach {$_.DeviceID} > > > > > > \\.\PHYSICALDRIVE0 > > > C: > > > D: > > > > > > > > > Building up on urkec worked on both versions: > > > > > > $DiskDrive = Get-WmiObject Win32_DiskDrive > > > $DiskDrive | foreach { > > > $_.DeviceID > > > $d = gwmi -q "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='$($_.DeviceID)'} > > > WHERE AssocClass = Win32_DiskDriveToDiskPartition" | foreach {$_.name} > > > $d | foreach { gwmi -q "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='$_'} > > > WHERE AssocClass = Win32_LogicalDiskToPartition"} | foreach {$_.DeviceID} > > > } > > > > > > \\.\PHYSICALDRIVE0 > > > C: > > > D: > > > > > > ----- > > > Shay Levi > > > $cript Fanatic > > > http://scriptolog.blogspot.com > > > > > > > Hi, I'm trying to create a PS script, that enumerates physical disks, > > > > and for each, lists logical volumes. So, the output should be > > > > something like: > > > > \\.\PHYSICALDRIVE0 > > > > C: D: E: > > > > \\.\PHYSICALDRIVE1 > > > > F: G: > > > > ...etc... > > > > > > > > For this, I've used two WMI classes. The first one gets the physical > > > > disks, the second one the logical volumes (see below). However, how > > > > does these two get linked together? > > > > I've tried using Associators of, but with no luck. > > > > $strComputer = "." > > > > $colWMIDiskDrives = get-wmiobject -class "Win32_DiskDrive" -namespace > > > > "root\CIMV2" ´ > > > > -computername $strComputer > > > > $colWMILogicalDisks = get-wmiobject -class "Win32_LogicalDisk" - > > > > namespace "root\CIMV2" ´ > > > > -computername $strComputer > > > > > > > > > |
My System Specs![]() |
| | #9 (permalink) |
| | Re: Associating WMI disk classes On Jan 30, 12:07 am, /\/\o\/\/ [MVP] <o...@xxxxxx> wrote: Quote: > With Identing ;-)http://thepowershellguy.com/blogs/po...29/nested-rela... Keep up the good work. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Associating MDB to MS Access | Microsoft Office | |||
| Associating same extension to multiple programs | General Discussion | |||
| Associating several email accounts to Messenger new mail notification | Live Messenger | |||
| Vista not associating with "B" mode wireless access points???? | Vista General | |||