![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | 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) | ||||||||||||
| Guest | Re: Associating WMI disk classes
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) | ||||||||||||
| Guest | RE: Associating WMI disk classes "Thomas Makro" wrote:
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) | ||||||||||||
| Guest | 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
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #5 (permalink) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Guest | Re: Associating WMI disk classes On Jan 29, 10:05*pm, urkec <ur...@xxxxxx> wrote:
$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) | ||||||||||||||||||||||||
| Guest | 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:
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #7 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | 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:
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #8 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Associating WMI disk classes With Identing ;-) http://thepowershellguy.com/blogs/po...owershell.aspx "/\/\o\/\/ [MVP]" wrote:
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #9 (permalink) | ||||||||||||
| Guest | Re: Associating WMI disk classes On Jan 30, 12:07 am, /\/\o\/\/ [MVP] <o...@xxxxxx> wrote:
Keep up the good work. | ||||||||||||
My System Specs![]() | |||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Associating several email accounts to Messenger new mail notification | mjs | Live Messenger | 1 | 08-31-2008 09:20 PM |
| Vista not associating with "B" mode wireless access points???? | Steve in Abbotsford | Vista General | 1 | 03-27-2007 08:18 PM |
| how to load .net classes | IT Staff | PowerShell | 3 | 01-22-2007 11:42 AM |
| Associating an Animation::Completed event with an object | John Dunn | Avalon | 8 | 12-08-2006 12:45 PM |
| RC1 and WMI - mising classes? | DewBoy3d | Vista performance & maintenance | 1 | 09-18-2006 06:05 AM |