Is there a way to get information like that provided with vdf from VITK-W?
Are there API calls to the SDK that can be used to get these details?
Had a ESX host run out of log space and it took it down. I have created a script to archive the logs but would like to take a more proactive approach to monitoring the Hosts usage.
You can move the ConvertTo-Html cmdlet outside the loop and feed it an array ($report) that holds all the custom objects ($line).
That way you get a nice table with all the entries for a specific host.
$report = @() foreach ($dfl in $esx_df) { $dcnter += 1 if ($dcnter -gt 1) { $cnter = 0 $dfa = $dfl.split("",[StringSplitOptions]::RemoveEmptyEntries) $line = "" | select FileSystem, Size, Used, Available, UsedPerc, MountPoint, Warning foreach ($dfal in $dfa) { $cnter += 1 if ($cnter -eq 1) { Write-Host "FileSystem:" $dfal $line.FileSystem = $dfal } elseif ($cnter -eq 2) { Write-Host "Size:" $dfal $line.Size = $dfal } elseif ($cnter -eq 3) { Write-Host "Used:" $dfal $line.Used = $dfal } elseif ($cnter -eq 4) { Write-Host "Avail:" $dfal $line.Available = $dfal } elseif ($cnter -eq 5) { Write-Host "Used%:" $dfal $line.UsedPerc = $dfal if ([Int]$dfal.Trim("%") -gt 75) { Write-Host "Usage over 75%" $line.Warning = "Warning Storage Usage is above 75%" } } elseif ($cnter -eq 6) { Write-Host "Mount Point:" $dfal $line.MountPoint = $dfal } } $report += $line } } $report | ConvertTo-Html –title "VMware VI3 Server Storage ... type='text/css'></![CDATA[>" | Out-File -Append $filelocation
As a side remark, the ConvertTo-Html cmdlet is rather limited and cumbersome for producing fancy web pages.
Have a look at this Windows PowerShell Tip of the Week to see how this can be ameliorated.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Access to ESX filesystem, the datastores excluded, is not possible with the VITK nor with any of the SDK methods that I know of.
In Hal's blog there an article that describes how to do this with the help of plink.exe
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok,
So I have the code to gather the information and also to maintain the volumes.
What I would like to do with the data is output it into a HTML document and mail it to the team which monitors it daily.
The issue I am having is that its not a .NET object so the ConvertTo-HTML does not work and converts my output to a set of numbers.
Can anyone help with making this possible?
Here is the code: (Formatting is a bit off so I have attached the code also.)
$vcserver="localhost"
Add-PSsnapin VMware.VimAutomation.Core
Initialize-VIToolkitEnvironment.ps1
connect-VIServer $vcserver
$filelocation="C:\Scripts\VI3_SSI.html"
$smtpServer = "xxx.xxx.xxx.xxx"
$mailfrom = "ESX Storage <XXXXXX@XXXXXXXX.XXX>"
$mailto = "XXXXXX@XXXXXXXX.XXX"
ConvertTo-Html –title "VI3 Server Storage Information " –body "<H1>VI3 Server Storage Information</H1>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File $filelocation
ConvertTo-Html –title " VI3 Server Storage Information " –body "<H4>Date and time</H4>",$date -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
VMware ESX Volume Information
get-vmhost | sort-object -unique | ForEach-Object -process {
$esx_df = & "C:\Program Files\Veeam\Veeam Backup and FastSCP\Putty\plink" -pw XXXXXXXX root@$_ df -h
$dcnter = 0
$_.Name | ConvertTo-Html –title "VMware VI3 Server Storage Configuration" –body "<H2>VMware VI3 Server Storage Configuration.</H2>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
foreach ($dfl in $esx_df)
{
$dcnter += 1
if ($dcnter -gt 1)
{
$cnter = 0
$dfa = $dfl.split("",[StringSplitOptions]::RemoveEmptyEntries)
foreach ($dfal in $dfa)
{
$cnter += 1
if ($cnter -eq 1)
{ Write-Host "FileSystem:" $dfal
$dfal | ConvertTo-Html –title "VMware VI3 Server Storage Configuration" –body "<H2>VMware VI3 Server Storage Configuration.</H2>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
}
ElseIf ($cnter -eq 2)
{ Write-Host "Size:" $dfal
$dfal | ConvertTo-Html –title "VMware VI3 Server Storage Configuration" –body "<H2>VMware VI3 Server Storage Configuration.</H2>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
}
ElseIf ($cnter -eq 3)
{ Write-Host "Used:" $dfal
$dfal | ConvertTo-Html –title "VMware VI3 Server Storage Configuration" –body "<H2>VMware VI3 Server Storage Configuration.</H2>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
}
ElseIf ($cnter -eq 4)
{ Write-Host "Avail:" $dfal
$dfal | ConvertTo-Html –title "VMware VI3 Server Storage Configuration" –body "<H2>VMware VI3 Server Storage Configuration.</H2>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
}
ElseIf ($cnter -eq 5)
{ Write-Host "Used%:" $dfal
$dfal | ConvertTo-Html –title "VMware VI3 Server Storage Configuration" –body "<H2>VMware VI3 Server Storage Configuration.</H2>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
{Write-Host "Usage over 75%"
"Warning Storage Usage is above 75%" | ConvertTo-Html –title "VMware VI3 Server Storage Configuration" –body "<H2>VMware VI3 Server Storage Configuration.</H2>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
}
}
ElseIf ($cnter -eq 6)
{ Write-Host "Mount Point:" $dfal
$dfal | ConvertTo-Html –title "VMware VI3 Server Storage Configuration" –body "<H2>VMware VI3 Server Storage Configuration.</H2>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
}
}
}
}
}
E-mail HTML output
$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($filelocation)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = $mailfrom
$msg.To.Add($mailto)
$msg.Subject = “VMware Healthscript”
$msg.Body = “VMware healthscript”
$msg.Attachments.Add($att)
$smtp.Send($msg)
Disconnect session from VC #
disconnect-viserver -confirm:$false
The easiest way is to create a custom PSObject and feed that to the ConvertTo-Html cmdlet.
The following shows how you can do this for the output of the 'df -h' command
... foreach ($dfl in $esx_df) { $dcnter += 1 if ($dcnter -gt 1) { $cnter = 0 $dfa = $dfl.split("",[StringSplitOptions]::RemoveEmptyEntries) $line = "" | select FileSystem, Size, Used, Available, UsedPerc, MountPoint, Warning foreach ($dfal in $dfa) { $cnter += 1 if ($cnter -eq 1) { Write-Host "FileSystem:" $dfal $line.FileSystem = $dfal } elseif ($cnter -eq 2) { Write-Host "Size:" $dfal $line.Size = $dfal } elseif ($cnter -eq 3) { Write-Host "Used:" $dfal $line.Used = $dfal } elseif ($cnter -eq 4) { Write-Host "Avail:" $dfal $line.Available = $dfal } elseif ($cnter -eq 5) { Write-Host "Used%:" $dfal $line.UsedPerc = $dfal if ([Int]$dfal.Trim("%") -gt 75) { Write-Host "Usage over 75%" $line.Warning = "Warning Storage Usage is above 75%" } } elseif ($cnter -eq 6) { Write-Host "Mount Point:" $dfal $line.MountPoint = $dfal } } $line | ConvertTo-Html | Out-File -Append $filelocation } } ...
To make it easier to see the logic I simplified the ConvertTo-Html cmdlet at the end.
Attached your updated script.
The other lines with ConvertTo-Html can be done in a similar way.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Thank you for the sound advice(And code)!
When I use your example though it places the html output into seperate tables for each foreach statement.
How would I avoid this and have a single table with all entires for a single server?
I have added a column to the dataset which contains the server/hostname to tell which server is being viewed.
You can move the ConvertTo-Html cmdlet outside the loop and feed it an array ($report) that holds all the custom objects ($line).
That way you get a nice table with all the entries for a specific host.
$report = @() foreach ($dfl in $esx_df) { $dcnter += 1 if ($dcnter -gt 1) { $cnter = 0 $dfa = $dfl.split("",[StringSplitOptions]::RemoveEmptyEntries) $line = "" | select FileSystem, Size, Used, Available, UsedPerc, MountPoint, Warning foreach ($dfal in $dfa) { $cnter += 1 if ($cnter -eq 1) { Write-Host "FileSystem:" $dfal $line.FileSystem = $dfal } elseif ($cnter -eq 2) { Write-Host "Size:" $dfal $line.Size = $dfal } elseif ($cnter -eq 3) { Write-Host "Used:" $dfal $line.Used = $dfal } elseif ($cnter -eq 4) { Write-Host "Avail:" $dfal $line.Available = $dfal } elseif ($cnter -eq 5) { Write-Host "Used%:" $dfal $line.UsedPerc = $dfal if ([Int]$dfal.Trim("%") -gt 75) { Write-Host "Usage over 75%" $line.Warning = "Warning Storage Usage is above 75%" } } elseif ($cnter -eq 6) { Write-Host "Mount Point:" $dfal $line.MountPoint = $dfal } } $report += $line } } $report | ConvertTo-Html –title "VMware VI3 Server Storage ... type='text/css'></![CDATA[>" | Out-File -Append $filelocation
As a side remark, the ConvertTo-Html cmdlet is rather limited and cumbersome for producing fancy web pages.
Have a look at this Windows PowerShell Tip of the Week to see how this can be ameliorated.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Thank you!
below is the final code for the script;
I will also post this as an alteration to the VMware HealthCheck.ps1 which I have altered and added to...
Being that the formating is off I have also attached the code.
-
*
ConvertTo-Html -title "VMware ESX Server Volume Information." -body "<H2>VMware ESX Server Volume Information.</H2>" -head $a | Out-File -Append $filelocation
*
$report = @()
get-vmhost | sort-object -unique | ForEach-Object -process {
$esx_df = & "C:\Program Files\Veeam\Veeam Backup and FastSCP\Putty\plink" -pw Asd123 root@$_ df -h
$dcnter = 0
foreach ($dfl in $esx_df)
{
$dcnter += 1
if ($dcnter -gt 1)
{ $cnter = 0
$dfa = $dfl.split("",[StringSplitOptions]::RemoveEmptyEntries)
$line = "" | select ESXHost, FileSystem, VolumeSize, VolumeUsed, Available, UsedPercent, MountPoint, VolumeWarning
foreach ($dfal in $dfa)
{ $cnter += 1
$line.ESXHost = $_.Name
if ($cnter -eq 1)
{ $line.FileSystem = $dfal }
elseif ($cnter -eq 2)
{ $line.VolumeSize = $dfal }
elseif ($cnter -eq 3)
{ $line.VolumeUsed = $dfal }
elseif ($cnter -eq 4)
{ $line.Available = $dfal }
elseif ($cnter -eq 5)
{ $line.UsedPercent = $dfal
{ $line.VolumeWarning = "Warning Volume Usage is above 75%" }
}
elseif ($cnter -eq 6)
{ $line.MountPoint = $dfal }
}
$report += $line
}
}
}
$report | ConvertTo-Html -head $a | Out-File -Append $filelocation
-