strComputer = "." Set objWMIService = GetObject( "winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery ("Select * From Win32_LogicalDisk Where DeviceID = 'A:'")
For Each objItem in colItems
intFreeSpace = objItem.FreeSpace
If IsNull(intFreeSpace) Then
Wscript.Echo "There is no disk in the floppy drive."
Else
Wscript.Echo "There is a disk in the floppy drive."
End If
Next
foreach ($objItem in $colItems)
{
$intFreeSpace = $objItem.FreeSpace
if ($intFreeSpace -eq $null) { "There is no disk in the floppy drive." }
else { "There is a disk in the floppy drive." }
}
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk")
For Each objDisk in colDisks
Wscript.Echo "DeviceID: "& vbTab _
& objDisk.DeviceID
Select Case objDisk.DriveType
Case 1
Wscript.Echo "No root directory. " & "Drive type could not be " & "determined."
Case 2
Wscript.Echo "DriveType: "& vbTab & "Removable drive."
Case 3
Wscript.Echo "DriveType: "& vbTab & "Local hard disk."
Case 4
Wscript.Echo "DriveType: "& vbTab & "Network disk."
Case 5
Wscript.Echo "DriveType: "& vbTab & "Compact disk."
Case 6
Wscript.Echo "DriveType: "& vbTab & "RAM disk."
Case Else
Wscript.Echo "Drive type could not be" & " determined."
End Select
Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk")
For Each objDisk in colDisks
Wscript.Echo "DeviceID: " & objDisk.DeviceID
Wscript.Echo "Free Disk Space: " & objDisk.FreeSpace
Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery ("Select * from Win32_Volume Where Name = 'K:\\'")
For Each objVolume in colVolumes
errResult = objVolume.Defrag()
Next
ComputerName = "." Set wmiServices = GetObject ( _ "winmgmts:{impersonationLevel=Impersonate}!//" & ComputerName) ' Get physical disk drive Set wmiDiskDrives = wmiServices.ExecQuery ( "SELECT Caption, DeviceID FROM Win32_DiskDrive")
For Each wmiDiskDrive In wmiDiskDrives WScript.Echo "Disk drive Caption: " & wmiDiskDrive.Caption & VbNewLine & "DeviceID: " & " (" & wmiDiskDrive.DeviceID & ")"
'Use the disk drive device id to ' find associated partition query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" _ & wmiDiskDrive.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition"
Set wmiDiskPartitions = wmiServices.ExecQuery(query)
For Each wmiDiskPartition In wmiDiskPartitions 'Use partition device id to find logical disk Set wmiLogicalDisks = wmiServices.ExecQuery _ ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" _ & wmiDiskPartition.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition")
For Each wmiLogicalDisk In wmiLogicalDisks
WScript.Echo "Drive letter associated" _
& " with disk drive = " _
& wmiDiskDrive.Caption _
& wmiDiskDrive.DeviceID _
& VbNewLine & " Partition = " _
& wmiDiskPartition.DeviceID _
& VbNewLine & " is " _
& wmiLogicalDisk.DeviceID
Next
Next
Next