VMware Cloud Community
SuperVirtual
Contributor
Contributor
Jump to solution

VMware Disk Snapshot & Conoslidation Report

Hi Folks, I am using a script to display VM names which has snapshots present which works fine, but I want to use the NeedsConsolidation field incorporated in that too

How can I achieve that? Please review the attached script which I am using and suggest

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something along these lines

foreach($vm in Get-VM){

    if($vm.ExtensionData.Runtime.ConsolidationNeeded){

        $Snap = "" | Select VM,Name,Created,Description,Host,NeedsConsolidation

        $Snap.VM = $vm.Name

          $snap.NeedsConsolidation = $true

          $Report += $Snap

    }

    else{

        Get-Snapshot -VM $vm | %{

            $Snap = "" | Select VM,Name,Created,Description,Host,NeedsConsolidation

              $Snap.VM = $vm.name

              $Snap.Name = $_.name

              $Snap.Created = $_.created

              $Snap.Description = $_.description

              $Snap.Host = $_.vm.host.name

              $snap.NeedsConsolidation = $false

              $Report += $Snap

        }

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
18 Replies
LucD
Leadership
Leadership
Jump to solution

The HTML report produced by that script already has a column, called NeedsConsolidation, that displays that value.

Not sure what you are asking ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
SuperVirtual
Contributor
Contributor
Jump to solution

Thanks Luc, I added that field onto the HTML report but that recalls nothing which is why I need expert help :slightly_smiling_face:

If you can have a look at the script and advise what I need to add in order to get that field populated onto the report then it would be very nice

Reply
0 Kudos
Wh33ly
Hot Shot
Hot Shot
Jump to solution

get-vm  | get-snapshot | %{             
$Snap = {} | Select VM,Name,Created,Description,Host,NeedsConsolidation             
$Snap.VM = $_.vm.name            
$Snap.Name = $_.name             
$Snap.Created = $_.created             
$Snap.Description = $_.description            
 $Snap.Host = $_.vm.host.name            
 $snap.NeedsConsolidation = (get-vm $_.vm).ExtensionData.Runtime.consolidationNeeded             
$Report += $Snap                               
 }                                  
       }

Add the BOLD parts

And change the line :

Write-Output "<td>$($snapshot.vm)</td><td>$($snapshot.name)</td><td>$($snapshot.created)</td><td>$($snapshot.description)</td><td>$($snapshot.host)</td><td>$($snapshot.NeedsConsolidation)</td><tr> "    }

1) The <td>  before snapshot had a "/" in it which needs to be removed

2) $snapshot.consolidationNeeded needs to be changed to NeedsConsolidation because that is what's in $Snap

LucD
Leadership
Leadership
Jump to solution

You were nearly there (and there is no need to do another Get-VM).

Replace the commented out line

$snap.NeedsConsolidation = $_.ExtensionData.Runtime.consolidationNeeded

by

$snap.NeedsConsolidation = $_.Vm.ExtensionData.Runtime.consolidationNeeded

and add the new property on the Select line

$Snap = {} | Select VM,Name,Created,Description,Host,NeedsConsolidation

and finally correct the propertyname on the output line

Write-Output "<td>$($snapshot.vm)</td><td>$($snapshotname)</td><td>$($snapshot.created)</td><td>$($snapshot.description)</td><td>$($snapshot.host)</td></td>$($snapshot.NeedsConsolidation)</td><tr> "


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Wh33ly
Hot Shot
Hot Shot
Jump to solution

Ah good to know Smiley Happy

Reply
0 Kudos
SuperVirtual
Contributor
Contributor
Jump to solution

Thanks Wh33ly Smiley Happy

Reply
0 Kudos
SuperVirtual
Contributor
Contributor
Jump to solution

Thanks a lot LucD, worked like a charm Heart

Now just waiting for it to populate the filed with 'Yes' when consolidation is required for any VM, fingers crossed

Reply
0 Kudos
SuperVirtual
Contributor
Contributor
Jump to solution

Hi LucD, sorry I am re opening this thread

the script is working fine except the fact that the NeedsConsloidation column is not displaying me with a Yes
if a VM needs a consolidation . It does show on the vsphere but not via the script

Any ideas?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Would you mind attaching the version you are currently using ?

There were several changes suggested, and I don't know what you are actually using now.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
SuperVirtual
Contributor
Contributor
Jump to solution

Sure, please find the attached

I am using powercli version 5.5 update 1 and we have ESXi version 5.1

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are you sure you have VMs with a snapshot, and that need consolidation ?

I use the following to find VMs that need consolidation.

$splatVM = @{

    ViewType = "VirtualMachine"

    Property = "Name","Runtime.ConsolidationNeeded"

    Filter = @{"Runtime.ConsolidationNeeded"="True"}

}

Get-View @splatVM | Select Name


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
SuperVirtual
Contributor
Contributor
Jump to solution

Yes, we have few VM's which shows needs consolidation in vsphere but not when the script is run, it shows every field but without the Consolidation one

Where do I add these lines in the code to get it populated on the report?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Your original report will only show VMs that have at least 1 snapshot.

The VMs requiring consolidation most probably do not have any snapshots, that is probably the reason you do not see any value in that column.

Did my previous short script show any VMs requiring consolidation ?

Do any of these VMs have snapshots ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
SuperVirtual
Contributor
Contributor
Jump to solution

Ok i see

I am not very much concerned about the snapshot but no harm having it

I use get-vm | where {$_.ExnetnsionData.Runtime.consolidationNeeded}| Select Name snippet to list the VM's which needs consolidation and it does show me few VM's which needs manual intervention but the only thing is that its not showing on the report.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is because you are doing

get-vm | get-snapshot | %{

Only VMs that have a snapshot will get through.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
SuperVirtual
Contributor
Contributor
Jump to solution

So you have suggestions for me on how to get that populated into the report?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something along these lines

foreach($vm in Get-VM){

    if($vm.ExtensionData.Runtime.ConsolidationNeeded){

        $Snap = "" | Select VM,Name,Created,Description,Host,NeedsConsolidation

        $Snap.VM = $vm.Name

          $snap.NeedsConsolidation = $true

          $Report += $Snap

    }

    else{

        Get-Snapshot -VM $vm | %{

            $Snap = "" | Select VM,Name,Created,Description,Host,NeedsConsolidation

              $Snap.VM = $vm.name

              $Snap.Name = $_.name

              $Snap.Created = $_.created

              $Snap.Description = $_.description

              $Snap.Host = $_.vm.host.name

              $snap.NeedsConsolidation = $false

              $Report += $Snap

        }

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
SuperVirtual
Contributor
Contributor
Jump to solution

Wow, worked flawlessly :slightly_smiling_face:

Thanks a lot Sir, you rock

Reply
0 Kudos