hi all, i am beginning a script that populates information into a html page. I do not seem to be able to get the ouput correct to the html page. I either end up with multiple entries of the same vmname, or the correct list of vmnames but repeated many times. I wonder of someone could have a glance at the code below and advise where i am going wrong. Many thanks in advance ..
$htmlPRDVMName = "D:\VMwebsite\Vmware\HTML\PRDErrorVMName.html"
$PRDVMName = @()
ConvertTo-Html –title "VMName Check" –body "<H1>VMName Check ($date)</H1><table><tr><td class="menu_item_current"><img src='.\..\images\vmware.gif' ></img><a href='.\..\index.htm' class='a_notlinked' > Home</a></td></tr></table>" -head "<link rel='stylesheet' href='.\..\VmStyle.css' type='text/css' />" | Out-File $htmlPRDVMName
foreach ($datacenter in Get-Datacenter | sort-object Name)
{
write-host "> " $datacenter
ConvertTo-Html –body "<H2>$datacenter</H2>" | Out-File -append $htmlPRDVMName
$vmhosts=$null
$vmhosts= get-vmhost -Location $datacenter | sort-object Name
$cluster = get-cluster -Location $datacenter | Sort-Object Name
$DatacenterTmp = @()
if (($vmhosts | Measure-Object).Count -ne 0) {
foreach($vmhost in $vmhosts) {
$HostTmp = @()
$SnapShotsHost=""
write-host " - " " > " $vmhost.Name
foreach($vmTemp in (get-vm -Location $vmhost | sort-object Name))
{
write-host " - " " - " " > " $vmTemp.Name
Get-View -ViewType virtualmachine -Property name | % {
$ReportRow = "" | Select-Object VMName
$ReportRow.VMName = $_.Name
}
$HostTmp += $ReportRow
}
$DatacenterTmp += $HostTmp
}
$PRDVMName = $DatacenterTmp | sort-object VMName
$PRDVMName | convertto-html -property VMName | Out-File -append $htmlPRDVMName
}
}
$htmlPRDVMName = "D:\VMwebsite\Vmware\HTML\PRDErrorVMName.html"
$PRDVMName = @()
ConvertTo-Html –title "VMName Check" –body "<H1>VMName Check ($date)</H1><table><tr><td class="menu_item_current"><img src='.\..\images\vmware.gif' ></img><a href='.\..\index.htm' class='a_notlinked' > Home</a></td></tr></table>" -head "<link rel='stylesheet' href='.\..\VmStyle.css' type='text/css' />" | Out-File $htmlPRDVMName
foreach ($datacenter in Get-Datacenter | sort-object Name)
{
write-host "> " $datacenter
ConvertTo-Html –body "<H2>$datacenter</H2>" | Out-File -append $htmlPRDVMName
$vmhosts=$null
$vmhosts= get-vmhost -Location $datacenter | sort-object Name
$cluster = get-cluster -Location $datacenter | Sort-Object Name
#$DatacenterTmp = @()
if (($vmhosts | Measure-Object).Count -ne 0) {
foreach($vmhost in $vmhosts) {
$HostTmp = @()
$SnapShotsHost=""
write-host " - " " > " $vmhost.Name
foreach($vmTemp in (get-vm -Location $vmhost | sort-object Name))
{
write-host " - " " - " " > " $vmTemp.Name
$VMname = $vmTemp.name
$ReportRow = New-object PSObject
$ReportRow | Add-Member -MemberType NoteProperty -Name VMName -Value $vmname
$HostTmp += $ReportRow
}
$PRDVMName = $HostTmp | sort-object VMName
$PRDVMName | convertto-html -property VMName | Out-File -append $htmlPRDVMName
}
}
}
Invoke-Item $htmlPRDVMName
hi thanks for the information ... however i have a fairly extensive report that i have stripped down to the bare minimum (which i have attached). I do not want to modify it too much. the script works and gives me all the information i need, however i dont seem to be able to get the display correctly. I have 2 Datacentres attavhed to the vcentre that i am running the script against. At the moment the HTML page that is created lists the vm's in both datacentres, under the title of each datacentre. So i get a list of all the vm's twice. Instead of vm's in datacentre1 appeairng under the datacentre1 title, and vm's in datacentre2 appeairng under the datacentre2 title. Can you advise where i am going wrong ... would be much appreciated. thanks in advance