Skip to content

Instantly share code, notes, and snippets.

@meoso
Last active July 6, 2017 13:14
Show Gist options
  • Save meoso/85189e1b33f777c35ae22d896ef2cf2a to your computer and use it in GitHub Desktop.
Save meoso/85189e1b33f777c35ae22d896ef2cf2a to your computer and use it in GitHub Desktop.
VMWare SAN SSD UNMAP script
[CmdletBinding()]
param(
[Parameter(Mandatory=$True,Position=0,HelpMessage="vCenter Server")]
[string]$vCenter
)
# Also Accepts "-Verbose" Flag
Write-Host "UNMAPping all volumes on: $vCenter"
Import-Module VMware.VimAutomation.Core | Out-Null
Disconnect-VIServer * -Confirm:$false -Force | Out-Null #Disconnect all previously connected vcenter servers
Connect-VIServer -Server $vCenter -Protocol https -Force | Out-Null
$datastores = Get-Datastore | where{$_.Type -eq 'VMFS'}
Write-Verbose "VMFS Datastores: $datastores"
foreach ($ds in $datastores) {
$esx = Get-VMHost -Datastore $ds | Get-Random -Count 1
$esxcli = Get-EsxCli -VMHost $esx
Write-Host "Using $esx to unmap $ds"
$esxcli.storage.vmfs.unmap($null,$ds,$null) | Out-Null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment