Hi,
I am trying to find .vmx files which are 0 bytes. I am using a portion of LucD's script but I am not sure what I am doing :smileyconfused: ..... can someone help? Eventually I would like save all of the file names which are 0 bytes into a file. Basically, even if I skip the loop and just run this against 1 datastore the script seems to never end or return anything.
Thanks!
$ESXHost = Get-Cluster $Cluster | Get-VMHost | select -First 1
$Datastores = Get-Datastore | where {$_.Name -notlike "*local"}
foreach ($Datastore in $Datastores) {
$zerobytes = @{}
Get-VM -Datastore $datastore | %{$_.Extensiondata.LayoutEx.File | where {$_.Name -like "*.vmx"} }
New-PSDrive -Name TgtDS -Location $Datastore -PSProvider VimDatastore -Root '\' | Out-Null
$zerobytes = @(Get-ChildItem -Path TgtDS: -Recurse | where {$_.FolderPath -notmatch ".snapshot" -and $_.Name -like "*.vmx" -and $_.length -eq 0})
PSDrive-NameTgtDS
Try something like this, but note that the datastore psprovider is notr particularly fast.
It might take some time, depending on the number and the size of your datastores.
$clusterName = "MyCluster"
Get-Cluster -Name $clusterName | Get-VMHost | Get-Random | Get-Datastore |
where {$_.Name -notmatch "local" -and $_.Type -eq "VMFS"} | %{
New-PSDrive -Name TgtDS -Location $_ -PSProvider VimDatastore -Root '\' | Out-Null
Get-ChildItem -Path TgtDS:\ -Recurse |
where {$_.ItemType -eq "VmConfigFile" -and $_.Length -eq 0} |
Select DatastoreFullPath
Remove-PSDrive -Name TgtDS -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
I cannot seem to get any output. I know there is a .vmx file with zero bytes in a subdirectory on one datastore... I have even modified the script to just get the datastore and search recursively.... would you please take a second look? Thanks
Just did some tests, and for me the script reports all 0-byte VMX files it finds.
Are you sure that the VMX file actually has a 0-byte length ?
Try running this slightly adapted script, it will show all VMX files and their size.
$clusterName = "MyCluster"
Get-Cluster -Name $clusterName | Get-VMHost | Get-Random | Get-Datastore |
where {$_.Name -notmatch "local" -and $_.Type -eq "VMFS"} | %{
New-PSDrive -Name TgtDS -Location $_ -PSProvider VimDatastore -Root '\' | Out-Null
Get-ChildItem -Path TgtDS:\ -Recurse |
where {$_.ItemType -eq "VmConfigFile"} |
Select DatastoreFullPath,Length
Remove-PSDrive -Name TgtDS -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference