I am working on a report to my mgmt with some really simple things, I needed Powered on VMs, powered off, and storage free and used numbers. I got most it working but the storage used isn't outputting correctly.
#############################
# Variables #
#############################
$date=Get-Date -format "yyyy-MMM-d"
$datetime=Get-Date
$filelocation="\var\www\Reports\Cloud-$date.htm"
#############################
# Content #
#############################
$On_report = Get-VM | Where-Object `
{$_.PowerState -eq "PoweredOn"} | Measure-Object | Select Count
$Off_report = Get-VM | Where-Object `
{$_.PowerState -eq "PoweredOff"} | Measure-Object | Select Count
#$RDC_Used = Get-DatastoreCluster RDC-iSCSI | select @{N='Used Space TB';E={[math]::Round(($_.CapacityGB-$_.FreespaceGB)/1000,2)}}
$RDC_Used = Get-DatastoreCluster RDC-iSCSI | @{E={[math]::Round(($_.CapacityGB-$_.FreespaceGB)/1000,2)}}
#Get-DatastoreCluster RDC-iSCSI | select @{N='Used Space';E={[math]::Round($_.CapacityGB-$_.FreespaceGB)}}
#############################
# Add Text to the HTML file #
#############################
ConvertTo-Html –title "State of the Cloud Numbers" –body "<H1>State of the Cloud Numbers</H1>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File $filelocation
ConvertTo-Html –title "VMware Hardware Version" –body "<H4>Powered On VMs</H4>",$On_report.Count -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
ConvertTo-Html –title "VMware Hardware Version" –body "<H4>Powered Off VMs</H4>",$Off_report.Count -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
ConvertTo-Html –title "VMware Hardware Version" –body "<H4>RDC Storage Used</H4>",$RDC_Used -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
ConvertTo-Html –title "VMware Hardware Version" –body "<H4>Date and time</H4>",$datetime -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
Try like this
# Variables #
#############################
$date=Get-Date -format "yyyy-MMM-d"
$datetime=Get-Date
$filelocation="\var\www\Reports\Cloud-$date.htm"
#############################
# Content #
#############################
$On_report = Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} | Measure-Object | Select Count
$Off_report = Get-VM | Where-Object {$_.PowerState -eq "PoweredOff"} | Measure-Object | Select Count
$RDC_Used = Get-DatastoreCluster RDC-iSCSI | %{[math]::Round(($_.CapacityGB-$_.FreespaceGB)/1000,2)}
#Get-DatastoreCluster RDC-iSCSI | select @{N='Used Space';E={[math]::Round($_.CapacityGB-$_.FreespaceGB)}}
#############################
# Add Text to the HTML file #
#############################
ConvertTo-Html –title "State of the Cloud Numbers" –body "<H1>State of the Cloud Numbers</H1>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File $filelocation
ConvertTo-Html –title "VMware Hardware Version" –body "<H4>Powered On VMs</H4>",$On_report.Count -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
ConvertTo-Html –title "VMware Hardware Version" –body "<H4>Powered Off VMs</H4>",$Off_report.Count -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
ConvertTo-Html –title "VMware Hardware Version" –body "<H4>RDC Storage Used</H4>",$RDC_Used -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
ConvertTo-Html –title "VMware Hardware Version" –body "<H4>Date and time</H4>",$datetime -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
Invoke-Item -Path $filelocation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference