please provide the powercli script to remove Empty Folders in vmfs(vSAN,VMFS) Datastores
Have a look at Re: Script for Deleting a Folder with its contents from a Datastore (vSAN or VMFS )
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Have a look at Re: Script for Deleting a Folder with its contents from a Datastore (vSAN or VMFS )
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
we have issue with vsphere replication. we are vsphere replication and when cleanup the replication , it is deleting files inside folder and leaving empty folders. we need to cleanup those empty folders in datastores. does the above script will do that?. we need to cleanup only empty folders in DS.
Yes, it deletes a folder, empty or not.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Great, sorry for confusion we need to delete only empty folders from DS and should not touch any other folders with the content in them.
we are performing vsphere replication when we unconfigure replication it is deleting the every file in folder and leaving the folder in DS. so please check once and give me script to delet ONLY empty folders from DS
So you also want code to find empty folders?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Can you check if this actually finds all your empty folders on a datastore?
$ds = Get-Datastore -Name $dsName
$dsBrowser = Get-View -Id $ds.ExtensionData.Browser
$spec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$details = New-Object VMware.Vim.FileQueryFlags
$details.FileOwner = $true
$details.FileSize = $true
$details.FileType = $true
$details.Modification = $true
$spec.Details = $details
$query = New-Object VMware.Vim.FolderFileQuery
$spec.Query += $query
$path = "[$($ds.Name)]"
$dsBrowser.SearchDatastoreSubFolders($path, $spec) |
ForEach-Object -Process {
$folder = $_.FolderPath
if ($folder -match "]$") {
$folder += ' '
}
$_.File | where {$_.Path -notmatch '^\.' -and $_.FileSize -eq 280} |
ForEach-Object -Process {
Write-Host "Empty folder: $($folder)$($_.Path)"
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference