I am attempting to list all VMs in an environment that do not have their VMDKs eagerlyzeroed so i can convert said VMDKs to eagerlyzeroed.
The script I have so far is:
get-vm | get-view | %{
$name = $_.name
$_.Config.Hardware.Device | where {$_.GetType().Name -eq "VirtualDisk"} | %{
if(!$_.Backing.eagerlyScrub){
"$name has a lazy zeroed thick provisioned disk" } } }
However, it returns each VMDK has a lazy thick provisioned disk even though I can verify there are a number of VMs that eagerly zeroed disks through the vsphere client.
Any suggestions on scripts that will be able to list VMs without eagerlyzeroed VMDKs?
Thanks
Hello, mmarzotto-
You code worked for me in returning a "vmname has a lazy zeroed..." line for every non-eagerlyzeroed thick disk. You say that this code is saying that every VM in your environment has all non-eagerlyzeroed thick disks?
You could quickly verify whether this code is producing the desired results by having it return items that _are_ eagerly scrubbed -- just remove the negation character (the "!") in the "if" statement (I did not post an example of that -- pretty straight forward).
And, just a suggestion about the speed of the code: to have this run fast like, you could do away with the Get-VM call at the start. So, like:
Get-View -ViewType VirtualMachine -Property Name,Config.Hardware.Device | %{
$name = $_.Name
$_.Config.Hardware.Device | where {$_.GetType().Name -eq "VirtualDisk"} | %{
if(!$_.Backing.EagerlyScrub) {"$name has a lazy zeroed thick provisioned disk"}
} ## end foreach-object
} ## end foreach-object
You could combine a couple of the statements, to make it a bit shorter, and to have it return the VMs that have at least one non-eagerlyzeroed thick disk:
Get-View -ViewType VirtualMachine -Property Name,Config.Hardware.Device | `
?{$_.Config.Hardware.Device | ?{($_ -is [VMware.Vim.VirtualDisk]) -and !$_.Backing.EagerlyScrub}} | `
select Name
Just a couple of suggestions. Do those give the expected results of VMs that have at least one non-eagerlyzeroed thick disk?
Hello, mmarzotto-
You code worked for me in returning a "vmname has a lazy zeroed..." line for every non-eagerlyzeroed thick disk. You say that this code is saying that every VM in your environment has all non-eagerlyzeroed thick disks?
You could quickly verify whether this code is producing the desired results by having it return items that _are_ eagerly scrubbed -- just remove the negation character (the "!") in the "if" statement (I did not post an example of that -- pretty straight forward).
And, just a suggestion about the speed of the code: to have this run fast like, you could do away with the Get-VM call at the start. So, like:
Get-View -ViewType VirtualMachine -Property Name,Config.Hardware.Device | %{
$name = $_.Name
$_.Config.Hardware.Device | where {$_.GetType().Name -eq "VirtualDisk"} | %{
if(!$_.Backing.EagerlyScrub) {"$name has a lazy zeroed thick provisioned disk"}
} ## end foreach-object
} ## end foreach-object
You could combine a couple of the statements, to make it a bit shorter, and to have it return the VMs that have at least one non-eagerlyzeroed thick disk:
Get-View -ViewType VirtualMachine -Property Name,Config.Hardware.Device | `
?{$_.Config.Hardware.Device | ?{($_ -is [VMware.Vim.VirtualDisk]) -and !$_.Backing.EagerlyScrub}} | `
select Name
Just a couple of suggestions. Do those give the expected results of VMs that have at least one non-eagerlyzeroed thick disk?
okay, that worked!
Thanks a lot!