Format

Formats the volume.

Formats the volume.

Example

Do not run below example code just to see what happens next. Many methods seriously affect your system. Always make sure you actually understand what the method and the code do.

# define the arguments you want to submit to the method
# remove values that you do not want to submit
# make sure you replace values with meaningful content before running the code
# see section "Parameters" below for a description of each argument.
$arguments = @{
    ClusterSize     = [UInt32](12345)  # replace 12345 with a meaningful value
    EnableCompression = [Boolean](12345)  # replace 12345 with a meaningful value
    FileSystem      = 'someText'  # replace 'someText' with meaningful text
    Label           = 'someText'  # replace 'someText' with meaningful text
    QuickFormat     = [Boolean](12345)  # replace 12345 with a meaningful value
    Version         = [UInt32](12345)  # replace 12345 with a meaningful value
}


# select the instance(s) for which you want to invoke the method
# you can use "Get-CimInstance -Query (ADD FILTER CLAUSE HERE!)" to safely play with filter clauses
# if you want to apply the method to ALL instances, remove "Where...." clause altogether.
$query = 'Select * From Win32_Volume Where (ADD FILTER CLAUSE HERE!)'
Invoke-CimMethod -Query $query -Namespace Root/CIMV2 -MethodName Format -Arguments $arguments |
Add-Member -MemberType ScriptProperty -Name ReturnValueFriendly -Passthru -Value {
  switch ([int]$this.ReturnValue)
  {
        0        {'Success'}
        default  {'Unknown Error '}
    }
}

To run this method on one or more remote systems, use New-CimSession:

$ComputerName = 'server12','server14'  # adjust to your server names
$Credential   = Get-Credential         # submit a user account with proper permissions

# define the arguments you want to submit to the method
# remove values that you do not want to submit
# make sure you replace values with meaningful content before running the code
# see section "Parameters" below for a description of each argument.
$arguments = @{
    ClusterSize     = [UInt32](12345)  # replace 12345 with a meaningful value
    EnableCompression = [Boolean](12345)  # replace 12345 with a meaningful value
    FileSystem      = 'someText'  # replace 'someText' with meaningful text
    Label           = 'someText'  # replace 'someText' with meaningful text
    QuickFormat     = [Boolean](12345)  # replace 12345 with a meaningful value
    Version         = [UInt32](12345)  # replace 12345 with a meaningful value
}


$session = New-CimSession -ComputerName $ComputerName -Credential $Credential

# select the instance(s) for which you want to invoke the method
# you can use "Get-CimInstance -Query (ADD FILTER CLAUSE HERE!)" to safely play with filter clauses
$query = 'Select * From Win32_Volume Where (ADD FILTER CLAUSE HERE!)'
Invoke-CimMethod -Query $query -Namespace Root/CIMV2 -MethodName Format -Arguments $arguments -CimSession $session |
Add-Member -MemberType ScriptProperty -Name ReturnValueFriendly -Passthru -Value {
  switch ([int]$this.ReturnValue)
  {
        0        {'Success'}
        default  {'Unknown Error '}
    }
}


Remove-CimSession -CimSession $session

Learn more about Invoke-CimMethod and invoking WMI methods.

Syntax

uint32 Format(
  [in] string FileSystem = "NTFS",
  [in] boolean QuickFormat,
  [in] uint32 ClusterSize = 4096,
  [in] string Label = "",
  [in] boolean EnableCompression = false
);

Parameters

Name Type Description
ClusterSize UInt32 Specifies the disk allocation unit size or cluster size. All file systems used by this version of Windows organize your hard disk based on cluster size, which represents the smallest amount of disk space that can be allocated to hold a file. The smaller the cluster size you use, the more efficiently your disk stores information. If no cluster size is specified during format, Windows picks defaults based on the size of the volume. These defaults have been selected to reduce the amount of space lost and to reduce the amount of fragmentation on the volume. For general use, default setting (zero) are strongly recommended.
EnableCompression Boolean Indicates if the volume should be enabled for compression
FileSystem String The file system format to use for the volume.
Label String The label to use for the new volume. The volume label can contain up to 11 characters for FAT and FAT32 volumes or up to 32 characters for NTFS volumes.
QuickFormat Boolean Specifies whether to perform a quick format by removing files from the disk without scanning the disk for bad sectors. Use this option only if this disk has been previously formatted and you are sure the disk is not damaged.
Version UInt32 Version number of the specified file system. This is currently only valid for UDF. The default value (zero) will cause the format engine to select the version.

Return Value

Returns a value of type UInt32. Return values:

$returnValues = @{
    0    = 'Success'
}

Requirements

To use Win32_Volume, the following requirements apply:

PowerShell

Get-CimInstance was introduced with PowerShell Version 3.0, which in turn was introduced on clients with Windows 8 and on servers with Windows Server 2012.

If necessary, update Windows PowerShell to Windows PowerShell 5.1, or install PowerShell 7 side-by-side.

Operating System

Win32_Volume was introduced on clients with None supported and on servers with Windows Server 2003.

Namespace

Win32_Volume lives in the Namespace Root/CIMV2. This is the default namespace. There is no need to use the -Namespace parameter in Get-CimInstance.

Implementation

Win32_Volume is implemented in Vdswmi.dll and defined in Vds.mof. Both files are located in the folder C:\Windows\system32\wbem:

explorer $env:windir\system32\wbem
notepad $env:windir\system32\wbem\Vds.mof