Skip to content

Format-HostDiskPartition

VMware: Formats a new VMFS on each of the specified host disk partition

#Requires -Version 5.1
#Requires -Modules VMware.VimAutomation.Core
[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string]$VIServer,
    [Parameter(Mandatory = $true)]
    [pscredential]$VICredential,
    [Parameter(Mandatory = $true)]
    [string]$Id,
    [string]$VolumeName
)
Process {
    $vmServer = $null
    try {
        $vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
        $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
        if ([System.String]::IsNullOrWhiteSpace($VolumeName)) {
            $result = Get-VMHostDiskPartition -Server $vmServer -Id $Id | Format-VMHostDiskPartition -Confirm:$false -ErrorAction Stop | Select-Object *
        }
        else {
            $result = Get-VMHostDiskPartition -Server $vmServer -Id $Id | Format-VMHostDiskPartition -Confirm:$false -VolumeName $VolumeName -ErrorAction Stop | Select-Object *
        }
        foreach ($item in $result) {
            $item | Add-Member -NotePropertyName 'Timestamp' -NotePropertyValue $timestamp -Force
            Write-Output $item
        }
    }
    catch { throw }
    finally { if ($null -ne $vmServer) { Disconnect-VIServer -Server $vmServer -Force -Confirm:$false -ErrorAction SilentlyContinue } }
}

IP address or DNS name of the vSphere server

PSCredential object for authenticating with the server

Disk partition on which to format a new VMFS

Name for the new VMFS volume

An interactive directory of PowerShell scripts.