Skip to content

Josh's IT-Blog

Information Technology, and other interesting things …

  • Home
  • About
  • Contact
  • Links
  • Home
  • About
  • Contact
  • Links

reclaime diskspace on zero detection storage when deletening vmware vm

  1. Home   »  
  2. reclaime diskspace on zero detection storage when deletening vmware vm

reclaime diskspace on zero detection storage when deletening vmware vm

22. October 201820. October 2020 Burkard JoshGeneral

some time ago, i had the problem that my 3Par storage was getting full. in this time i removed a lot of test vm’s from this storage, but nothing happens. the storage was still full. the reason was the mechanisme how vmware deletes files from a DataStore and the activated zero-detection feature on the storage. if you delete a virtual disk file on the vmware datastore, it will only marked as deleted, but the datas are still there in the same format. to get the storage’s zero detection work, we have to zero out the deleted part of the datastore manually.

you can do this with this script:

$vCenterName   = "vcenter.domain.fqdn"
$vCenterCreds  = New-Object System.Management.Automation.PSCredential ( "username", ( ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force ) )

& 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'

Connect-VIServer -Server $vCenterName -Credential $vCenterCreds -WarningAction SilentlyContinue
Set-PowerCLIConfiguration -Scope Session -WebOperationTimeoutSeconds -1  -Confirm:$false

$VMHost = ( Get-VMHost )[0]
$EsxCli = Get-EsxCli -VMHost $VMHost.Name

$Datastores = $VMHost | Get-Datastore

foreach ( $Datastore in ( $Datastores | Sort-Object Name ) )
{
    Write-Output $Datastore.Name
    $res = $EsxCli.storage.vmfs.unmap(200, $Datastore.Name, $null)
    Write-Output "   $( $res )"
}

Disconnect-VIServer -confirm:$false

Get-Module | Remove-Module -Force

 

Post navigation

Previous: how to get the correct Virtual Disk for a VMware vm
Next: getting info about users password expiration

About

Author Image
My name is Josh Burkard.
I'm a DevOps Engineer working with one of Europees largest payroll provider. in my work I have a lot to do with Microsoft server operating systems, System Center, VMware, Microsoft Azure Cloud and other software.
On this site I will write some posts about different technology problems and their solutions.
please note also my tweets and retweets from this area.

Categories

  • General (13)
  • Hardware (9)
    • Network (8)
      • Cisco (2)
    • Storage (2)
  • Hiking (1)
  • Home Assistant (5)
  • Microsoft Azure (1)
    • Automation (1)
  • PowerShell (3)
  • Software (1)
    • Excel (1)
  • System Center (18)
    • SCCM (3)
    • SCDPM (1)
    • SCOM (12)
    • SCSM (1)
    • SMA (1)
  • VMware (8)
  • Windows 2008 R2 (10)
    • Active Directory (7)
  • Windows 2012 R2 (1)
  • Windows 2016 (1)
  • Windows 7 (4)
    • BitLocker (1)
  • WordPress (1)
Proudly powered by WordPress | Theme: goldy-mex by inverstheme.