drivera01
Enthusiast
Enthusiast

Adding HTML to report

Jump to solution

So I would like to see if I can get some advice on what im not doing right.

What I am trying to do is check to see if there is a snapshot for the vm's in $list (this part appears to work. on the IF portion,

but in the ELSE...

my problem is I do not know how to just plug in some html to display something like "NO SNAPSHOT FOUND"

I am using the convertto-html to create a report...

$myreport = @()
$snap = get-vm -name $list |  Get-Snapshot
If ($snap)
{
$vmlist = Get-Content C:\test.txt
get-vm -name $vmlist | % {
$Row = "" | Select-Object VM, "VMWare Tools"
$Row.VM = $_.Name
$Row."VMWare Tools" = $_.toolsversionstatus
$myreport += $Row
     }
}
Else
{
$myreport = @()


NO SNAPSHOTS FOUND   <---- not sure how to add this ($myreport)
$myreport += $Row
     }
}

1 Solution

Accepted Solutions
kunaludapi
Expert
Expert

I will check this and let you know.

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".

View solution in original post

0 Kudos
7 Replies
kunaludapi
Expert
Expert

$myreport = @()

$Vms =  Get-VM -Name $list

foreach ($vm in $Vms) {

    $snap = ($vm | get-snapshot).count

    $snapresult = if ($snap -eq 0) {write-output "No Snapshot found"} else {write-output $snap}

    $row = "" | select Name, "VMware Tools", Snapshots

    $row.Name = $vm.Name

    $row."VMware Tools"= $vm.ExtensionData.Guest.ToolsVersionStatus

    $row.Snapshots = $snapresult

    $myreport += $row

}

$myreport

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
drivera01
Enthusiast
Enthusiast

a little different than I wanted to do but probably doable...the only thing is this line does not appear to be functioning correctly.

$snapresult = if ($snap -eq 0) {write-output "No Snapshot found"} else {write-output $snap}

I tested the code against a vm with no snapshots and it did not write: No Snapshot found , but instead just left field blank.

0 Kudos
kunaludapi
Expert
Expert

I am not sure but it worked at my end, i will check again and let you know.

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
0 Kudos
drivera01
Enthusiast
Enthusiast

I just realized that it only places a count in the snapshot field if there is 2 or more snapshots for a vm... a vm with 1 snapshot it does not place it in there as like a vm with no snapshots..

it is strange... thank you for your help...

0 Kudos
kunaludapi
Expert
Expert

I will check this and let you know.

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
0 Kudos
LucD
Leadership
Leadership

Try changing this line

$snap = ($vm | get-snapshot).count

into this

$snap = (@($vm | get-snapshot)).count

That way you force an array, even if there is only 1 snapshot.


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

drivera01
Enthusiast
Enthusiast

LUCD... that worked...

Thank you both for you help...  this was the one piece I could not figure out from the full script I was making...

thanks!!

0 Kudos