Jump to content

trying to combine 2 WMI queries


Recommended Posts

The first script grabs disk info like size, serial number, etc. but i was not able to get "Model" from Win32_LogicalDisk.

the second script gets "Model". trying to figure out a way I can reference the correct disk to make sure the second script pulls the model from the corresponding disk in first script. any ideas?

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20

$row = 1
$objWMIService = ObjGet("winmgmts:\\" & $asset & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", _
        $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) Then
    For $objItem In $colItems
        $description = $objItem.Description

        If $description <> "Network Connection" And $description <> "CD-ROM Disc" And $description <> "3 1/2 Inch Floppy Drive" Then
            ConsoleWrite("device_id = " & $objItem.DeviceID)
            ConsoleWrite("free_space = " & $objItem.FreeSpace)
            ConsoleWrite("size = " & $objItem.Size)
            ConsoleWrite("volume_serial_number = " & $objItem.VolumeSerialNumber)
        EndIf
    Next
EndIf

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $asset & "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_DiskDrive")

For $objItem In $colItems
    ConsoleWrite("model = " & $objItem.Model)
Next
Edited by gcue
Link to comment
Share on other sites

The first script grabs disk info like size, serial number, etc. but i was not able to get "Model" from Win32_LogicalDisk.

the second script gets "Model". trying to figure out a way I can reference the correct disk to make sure the second script pulls the model from the corresponding disk in first script. any ideas?

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20

$row = 1
$objWMIService = ObjGet("winmgmts:\\" & $asset & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", _
        $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) Then
    For $objItem In $colItems
        $description = $objItem.Description

        If $description <> "Network Connection" And $description <> "CD-ROM Disc" And $description <> "3 1/2 Inch Floppy Drive" Then
            ConsoleWrite("device_id = " & $objItem.DeviceID)
            ConsoleWrite("free_space = " & $objItem.FreeSpace)
            ConsoleWrite("size = " & $objItem.Size)
            ConsoleWrite("volume_serial_number = " & $objItem.VolumeSerialNumber)
        EndIf
    Next
EndIf

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $asset & "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_DiskDrive")

For $objItem In $colItems
    ConsoleWrite("model = " & $objItem.Model)
Next

Looks like it is pretty tricky.

Converted this from here:http://www.tek-tips.com/viewthread.cfm?qid=1554136&page=1

$asset = "."
$objWMIService = ObjGet("winmgmts:\\" & $asset & "\root\cimv2")

$colDiskDrives = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive")
 
For $objDrive In $colDiskDrives
     _ConsoleWrite("Physical Disk: " & $objDrive.Caption & " -- " & $objDrive.DeviceID)
    $strDeviceID = StringReplace($objDrive.DeviceID, "\", "\\")
    $colPartitions = $objWMIService.ExecQuery _
        ("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
            $strDeviceID & """} WHERE AssocClass = " & _
                "Win32_DiskDriveToDiskPartition")
 
    For $objPartition In $colPartitions
         _ConsoleWrite("Disk Partition: " & $objPartition.DeviceID)
        $colLogicalDisks = $objWMIService.ExecQuery _
            ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
                $objPartition.DeviceID & """} WHERE AssocClass = " & _
                    "Win32_LogicalDiskToPartition")
 
        For $objLogicalDisk In $colLogicalDisks
;            If $objLogicalDisk.VolumeName = "System" Then
            ;_ConsoleWrite("Logical Disk: " & $objLogicalDisk.DeviceID)
            _ConsoleWrite("device_id = " &  $objLogicalDisk.DeviceID)
            _ConsoleWrite("free_space = " &  $objLogicalDisk.FreeSpace)
            _ConsoleWrite("size = " &  $objLogicalDisk.Size)
            _ConsoleWrite("volume_serial_number = " &  $objLogicalDisk.VolumeSerialNumber)
            _ConsoleWrite("model = " & $objDrive.Model)
                 
;            EndIf
        Next
         _ConsoleWrite()
    Next
    _ConsoleWrite()
Next

Func _ConsoleWrite($sMsg="")
    ConsoleWrite($sMsg&@LF)
EndFunc
Link to comment
Share on other sites

hey eltoro...

thanks for your help on this!

it works when i chose remote pc's that don't have solid state drives.. weird.

(4) : ==> Variable must be of type "Object".:

$colDiskDrives = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive")

$colDiskDrives = $objWMIService^ ERROR

Edited by gcue
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...