共用方式為


DefragAnalysis method of the Win32_Volume class

The DefragAnalysis method generates a fragmentation analysis for a volume.

This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.

Syntax

uint32 DefragAnalysis(
  [out] boolean DefragRecommended,
  [out] object DefragAnalysis
);

Parameters

DefragRecommended [out]

If true, defragmentation of the volume is recommended.

On Windows Vista, this value will be true if the file fragmentation on the volume exceeds 10%. On earlier versions of Windows, this value will be true if the average of the percent file fragmentation and percent free space fragmentation of the volume exceeds 10%.

DefragAnalysis [out]

Embedded instance of a Win32_DefragAnalysis containing the properties that describe the extent to which the volume is fragmented.

Return value

Return code Description
0
Success
1
Access Denied
2
Not Supported
3
Volume Dirty Bit Is Set
4
Not Enough Free Space
5
Corrupt Master File Table Detected
6
Call Canceled
7
Call Cancellation Request Too Late
8
Defrag Engine Is Already Running
9
Unable To Connect To Defrag Engine
10
Defrag Engine Error
11
Unknown Error

Examples

The following PowerShell code sample uses DefragAnalysis to analyze the C drive.

Win32_Volume Class DefragAnalysis sample using PowerShell 

# get volumes on local system
$v = get-wmiobject win32_volume

# Display Number of volumes
"Number of volumes {0}: " -f $v.length

# Now get the C:\ volume
$v1=$v | where {$_.name -eq "C:\"}

# Perform a defrag analysis on the C: drive
"Performing Defrag Analysis"
$dfa = $v1.DefragAnalysis().DefragAnalysis

# Display results
"";"Defrag Results - defrag of C:"
"-----------------------------"

"Average File Size (KB) : {0} KB" -f ($dfa.AverageFileSize/1kb)
"Average Fragments per File : {0} " -f $dfa.averageFragmentsPerfile
"Average Free Space per Extent : {0} " -f $dfa.AverageFreeSpacePerExtent
"Cluster Size (KB) : {0} " -f ($dfa.clustersize/1KB)
"Excess Folder Fragments : {0} " -f $dfa.ExcessFolderFragments
"File Percent Fragementation : {0} " -f $dfa.FilePercentFragementation
"Fragmented folders : {0} " -f $dfa.FragmentedFolders
"Free Space (GB) : {0} GB" -f ($dfa.FreeSpace/1gb)
"Free Space Percent : {0} " -f $dfa.FreeSpacePercent
"Free Space Percent Fragementation : {0} " -f $dfa.FreeSpacePercentFragementaion
"Largest free Space Extent : {0} " -f $dfa.LargestFreeSpaceExtent
"MFT Percent In Use : {0} " -f $dfa.MFTPercentInUse
"MFT Record count : {0} " -f $dfa.MFTRecordCount
"Page File Size : {0} " -f $dfa.PageFileSize
"Total Excess Fragements : {0} " -f $dfa.TotalExcessFragements
"Total Files : {0} " -f $dfa.TotalFiles
"Total Folders : {0} " -f $dfa.TotalFolders
"Total Fragmented Files : {0} " -f $dfa.TotalFragmentedFiles
"Total Free Space Extents : {0} " -f $dfa.TotalFreeSpaceExtents
"Total MFT Fragments : {0} " -f $dfa.TotalMftFragments
"Total MFT Size : {0} " -f $dfa.TotalMftSize
"Total Page File Fragements : {0} " -f $dfa.TotalPageFileFragements
"Total Percent Fragementation : {0} " -f $dfa.TotalPercentFragementation
"Total Unmovable Files : {0} " -f $dfa.TotalUnmovableFiles
"Used Space (GB) : {0} GB" -f ($dfa.UsedSpace/1gb)
"Volume Name : {0} " -f $dfa.VolumeName
"Volume Size (GB) : {0} GB" -f ($dfa.VolumeSize/1gb)

The previous sample displays the following information:

Number of volumes 2:
Performing Defrag Analysis

## Defrag Results - defrag of C:

Average File Size (KB) : 194.904296875 KB
Average Fragments per File : 1.04
Average Free Space per Extent : 66928900
Cluster Size (KB) : 4
Excess Folder Fragments : 0
File Percent Fragementation :
Fragmented folders : 1
Free Space (GB) : 55.9121589660645 GB
Free Space Percent : 87
Free Space Percent Fragementation :
Largest free Space Extent : 34251751424
MFT Percent In Use : 91
MFT Record count : 45363
Page File Size : 0
Total Excess Fragements :
Total Files : 37044
Total Folders : 8223
Total Fragmented Files : 14
Total Free Space Extents : 897
Total MFT Fragments : 2
Total MFT Size : 50790400
Total Page File Fragements :
Total Percent Fragementation :
Total Unmovable Files : 24
Used Space (GB) : 8.08490753173828 GB
Volume Name :
Volume Size (GB) : 63.9970664978027 GB

Requirements

Minimum supported client
None supported
Minimum supported server
Windows Server 2003
Namespace
Root\CIMV2
MOF
Vds.mof
DLL
Vdswmi.dll

See also

Win32_Volume