Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
WMI tasks for disks and file systems obtain information about disk drive hardware state and logical volumes. For other examples, see the TechNet ScriptCenter at https://www.microsoft.com/technet.
The script examples shown in this topic obtain data only from the local computer. For more information about how to use the script to obtain data from remote computers, see Connecting to WMI on a Remote Computer.
The following procedure describes how to run a script.
To run a script
- Copy the code and save it in a file with a .vbs extension, such as filename.vbs. Ensure that your text editor does not add a .txt extension to the file.
- Open a command prompt window and navigate to the directory where you saved the file.
- Type cscript filename.vbs at the command prompt.
- If you cannot access an event log, check to see if you are running from an Elevated command prompt. Some Event Log, such as the Security Event Log, may be protected by User Access Controls (UAC).
Note
By default, cscript displays the output of a script in the command prompt window. Because WMI scripts can produce large amounts of output, you might want to redirect the output to a file. Type cscript filename.vbs > outfile.txt at the command prompt to redirect the output of the filename.vbs script to outfile.txt.
The following table lists script examples that can be used to obtain various types of data from the local computer.
How do I... | WMI classes or methods | ||||
---|---|---|---|---|---|
...find out how much disk space each user is currently using on a computer? | If you are using disk quotas, then use the Win32_DiskQuota class and retrieve the values of the User and DiskSpaceUsed properties.
|
||||
...determine when a removable drive has been added to or removed from a computer? | Use a monitoring script that queries the Win32_VolumeChangeEvent class.
|
||||
...determine if a CD is in a CD-ROM drive? | Use the Win32_CDROMDrive class and the MediaLoaded property.
|
||||
...determine if a disk is in the floppy drive? | Use the Win32_LogicalDisk class and check the FreeSpace property. If the value is Null, then no disk is in the drive.
|
||||
...distinguish between a fixed hard disk and a removable hard disk? | Use the Win32_LogicalDisk class and check the value of the DriveType property.
|
||||
...determine what file system is in use on a drive? | Use the Win32_LogicalDisk class and the FileSystem property.
|
||||
...determine how much free space is available on a drive? | Use the Win32_LogicalDisk class and the FreeSpace property.
|
||||
...determine the size of a drive? | Use the Win32_LogicalDisk class, and the Size property.
|
||||
...find out what drives are mapped on a computer? | Use the Win32_MappedLogicalDisk class.
|
||||
...defragment a hard disk? | Use the Win32_Volume class and the Defrag method.
|
||||
...detect which drive letter is associated with a logical disk partition? |
|
Related topics
`