Posted by: Richard Siddaway
when relevant content is
added and updated.
We have seen how to pull information about our disks – what about working with them. As a quick recap on the objects that PowerShell deals with – properties give us the information and methods enable us to do stuff. So what stuff can we do?
We can find out from the documentation or we can use
Get-WmiObject -Class Win32_LogicalDisk | Get-Member -MemberType method
Get-WmiObject -Class Win32_DiskPartition | Get-Member -MemberType method
Get-WmiObject -Class Win32_DiskDrive | Get-Member -MemberType method
For conciseness I’ve only shown the Name of the method.
In reality the Reset and SetPowerState methods are not available because they are derived from the CIM* parent class. We’ll leave that for another day.
Chkdsk on the Logical Disk sounds familiar – lets have a look at that one
$disk = Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceId=’G:’"
$disk.ChkDsk($false, $true, $true, $false, $false, $false)
- The meaning of the parameters is as follows:
- FixErrors – Indicates what should be done to errors found on the disk. If true, then errors are fixed. The default is false.
- VigorousIndexCheck – If true, a vigorous check of index entries should be performed. The default is true.
- SkipFolderCycle – If true, the folder cycle checking should be skipped. The default is true.
- ForceDismount – If true, the drive should be forced to dismount before checking. The default is false.
- RecoverBadSectors -If true, the bad sectors should be located and the readable information should be recovered from these sectors. The default is false.
- OKToRunAtBootUp – If true, the chkdsk operation should be performed at next boot up time, in case the operation could not be performed because the disk is locked at time this method is called. The default is false.
Now we have seen how to run this manually we need to turn it into a script.