Export (0) Print
Expand All

Optimize-Volume

Updated: July 17, 2013

Applies To: Windows Server 2012

Optimize-Volume

Optimizes a volume, performing such tasks as defragmentation and trim.

Syntax

Parameter Set: ByDriveLetter
Optimize-Volume [-DriveLetter] <Char[]> [-Analyze] [-AsJob] [-CimSession <CimSession[]> ] [-Defrag] [-ReTrim] [-SlabConsolidate] [-ThrottleLimit <Int32> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: ById
Optimize-Volume -ObjectId <String[]> [-Analyze] [-AsJob] [-CimSession <CimSession[]> ] [-Defrag] [-ReTrim] [-SlabConsolidate] [-ThrottleLimit <Int32> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: ByLabel
Optimize-Volume -FileSystemLabel <String[]> [-Analyze] [-AsJob] [-CimSession <CimSession[]> ] [-Defrag] [-ReTrim] [-SlabConsolidate] [-ThrottleLimit <Int32> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: ByPaths
Optimize-Volume -Path <String[]> [-Analyze] [-AsJob] [-CimSession <CimSession[]> ] [-Defrag] [-ReTrim] [-SlabConsolidate] [-ThrottleLimit <Int32> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: InputObject (cdxml)
Optimize-Volume -InputObject <CimInstance[]> [-Analyze] [-AsJob] [-CimSession <CimSession[]> ] [-Defrag] [-ReTrim] [-SlabConsolidate] [-ThrottleLimit <Int32> ] [-Confirm] [-WhatIf] [ <CommonParameters>]




Detailed Description

The Optimize-Volume cmdlet optimizes a volume, performing such tasks as defragmentation and trim.

If no parameter is specified, then the default operation will be performed per the drive type as follows.

Defragment (drive type) : HDD
Slab : YES
Consolidation : NO
TRIM : NO

Defragment (drive type) : SSD
Slab : NO
Consolidation : NO
TRIM : YES

Defragment (drive type): VHD
Slab : YES
Consolidation : NO
TRIM : NO

Defragment (drive type): diff VHD
Slab : NO
Consolidation : NO
TRIM : YES

Defragment (drive type): Thinly Provisioned (Storage Spaces, thinly provisioned SAN Virtual Disk, Dynamic VHD)
Slab : NO
Consolidation : YES
TRIM : YES

Parameters

-Analyze

Analyzes the volume specified for defrag or optimize statistics. Performs analysis only and reports the current optimization state of the volume.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-AsJob

Runs the cmdlet as a background job. Use this parameter to run commands that take a long time to complete. The cmdlet immediately returns an object that represents the job and then displays the command prompt. You can continue to work in the session while the job completes. To manage the job, use the *-Job cmdlets. To get the job results, use the Receive-Job cmdlet. For more information about Windows PowerShell® background jobs, see about_Jobs.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-CimSession<CimSession[]>

Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession or Get-CimSession cmdlet. The default is the current session on the local computer.


Aliases

Session

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Defrag

Runs the defragment function on the specified volume, consolidating fragmented files to improve read and write performance.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-DriveLetter<Char[]>

Specifies the drive letter of the volume to optimize.


Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-FileSystemLabel<String[]>

Specifies the file system label of the volume to optimize.


Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-InputObject<CimInstance[]>

Accepts an object from the pipeline as input.


Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByValue)

Accept Wildcard Characters?

false

-ObjectId<String[]>

Specifies the ID of the volume to optimize.


Aliases

Id

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-Path<String[]>

Specifies the path of the volume to optimize.


Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-ReTrim

Generates TRIM and Unmap hints for all previously used sectors of the volume, notifying the underlying storage that the sectors are no longer needed and can be purged. This can recover unused capacity on thinly provisioned drives and on solid state drives (SSDs).


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-SlabConsolidate

Optimizes the volume per the supplied slab size and alignment to reduce the number of slabs on which the volumes is mounted. Perfoms slab consolidation on the storage to optimize slab allocations.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ThrottleLimit<Int32>

Specifies the maximum number of concurrent operations that can be established to run the cmdlet. If this parameter is omitted or a value of 0 is entered, then Windows PowerShell® calculates an optimum throttle limit for the cmdlet based on the number of CIM cmdlets that are running on the computer. The throttle limit applies only to the current cmdlet, not to the session or to the computer.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Confirm

Prompts you for confirmation before running the cmdlet.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see    about_CommonParameters.

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • Microsoft.Management.Infrastructure.CimInstance#ROOT/Microsoft/Windows/Storage/MSFT_Volume

    You can pipe a Volume object to the InputObject parameter.


Notes

  • The Microsoft.Management.Infrastructure.CimInstance object is a wrapper class that displays Windows Management Instrumentation (WMI) objects. The path after the pound sign (#) provides the namespace and class name for the underlying WMI object.

Examples

Example 1: Perform TRIM optimization

This example optimizes drive H by re-sending Trim requests. This is useful on SSD media, and thinly provisioned storage.


PS C:\> Optimize-Volume -DriveLetter H -ReTrim –Verbose

Example 2: Analyze a volume

This example reports only the current optimization state of drive H.


PS C:\> Optimize-Volume -DriveLetter H -Analyze –Verbose

Example 3: Defragment a volume

This example defragments drive H.


PS C:\> Optimize-Volume -DriveLetter H -Defrag –Verbose

Example 4: Perform slab consolidation

This example performs slab consolidation on the storage space backing volume H.


PS C:\> Optimize-Volume -DriveLetter H -SlabConsolidate –Verbose

Related topics

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft