PowerShell for Windows Admins

Jan 23 2010   6:54AM GMT

Disk Methods Part 1

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

 

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

Name
—-
Chkdsk
Reset
SetPowerState

Get-WmiObject -Class Win32_DiskPartition | Get-Member -MemberType method

Name
—-
Reset
SetPowerState

Get-WmiObject -Class Win32_DiskDrive | Get-Member -MemberType method

Name
—-
Reset
SetPowerState

 

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.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: