Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 197835

Re: clean up my html

$
0
0

In this case you don't need a separate foreach loop, since the complate virtualmachine object is available in $snap.VM.

Just call Get-Datastore with the VM as a parameter.

 

$HTML="yes"$FileHTML=New-Item-typefile"E:\Scripts\vm-info\VMInfo_$datefile.html"-Force:$true
Function
Create-HTMLTableparam([array]$Array$arrHTML=$Array|ConvertTo-Html
  $arrHTML[-1] =$arrHTML[-1].ToString().Replace(‘</body></html>’,""Return$arrHTML[5..2000] }$output=@()$output+='<html><head></head><body>'$output+='<style>table{border-style:solid;border-width:1px;font-size:8pt;background-color:#ccc;width:100%;}th{text-align:left;}td{background-color:#fff;width:20%;border-style:solid;border-width:1px;}body{font-family:verdana;font-size:12pt;}h1{font-size:12pt;}h2{font-size:10pt;}</style>'#$Report = @()$Report=New-Object-TypeNamesystem.collections.arraylistforeach ($snapin (Get-ClusterCLUSTER1,CLUSTER2|Get-VM|Get-Snapshot)) {  $reportedvm=""|Select-ObjectVM,Name,Description,SizeGB,DSFreeGB
  $reportedvm.VM=$snap.vm.Name
  $reportedvm.Name=$snap.Name
  $reportedvm.Description=$snap.Description
  $reportedvm.SizeGB=[math]::Round($snap.SizeGB,0$reportedvm.DSFreeGB=[math]::Round((Get-Datastore-VM$snap.VM|Select-ExpandPropertyFreeSpaceGB),0$report.add($reportedvm)|out-null
}if ($HTML-eq"yes") {  $output+='<p>'  $output+='<p>'  $output+=Create-HTMLTable$report  $output+='</p>'  $output+='</body></html>'  $output|Add-Content$FileHTML
}

 

Note that if you have VMs that are stored on multiple datastores, or where the snapshots are stored on a separate datastore, the logic becomes a bit more complicated.


Viewing all articles
Browse latest Browse all 197835

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>