Actually I'm building scripts sequentially and as this function($ergs=(Get-Pool | Select Pool_id,@{N="vdesk";E={$_ | Get-DesktopVM | Measure-Object | Select -ExpandProperty Count}},maximumcount)) is the first real custom code, I haven't much to show yet.
Currently I have only:
<Adding View cmdlets>
$chk=0
$outfile="D:\outtmp.txt"
Connect-VIServer -Server server.domain.net -Force >>null
$ergs=(Get-Pool | Select Pool_id,@{N="vdesk";E={$_ | Get-DesktopVM | Measure-Object | Select -ExpandProperty Count}},maximumcount)
(below is just coded here to see the direction I want to go..(no idea if it works atm))
$lim=$ergs.count
for ($i=0;$i -lt $lim;$i++)
{
[int]$cur=$ergs[$i].maximumCount*0.05
$erg=$ergs[$i].maximumCount-$ergs[$i].vdesk
if ($erg -lt $cur)
{
echo "Pool $ergs[$i].Pool_id is reaching its limit, currently $ergs[$i].vdesk of $ergs[$i].maximumCount in use!" >> $outfile
$chk=1
}
}
(end of firstcode here)
function sendmail($body)
{
$SmtpClient = new-object system.net.mail.smtpClient
$MailMessage = New-Object system.net.mail.mailmessage
$SmtpClient.Host = "server_ip"
$SmtpClient.Port = 25
$mailmessage.from = "test@test.com"
$mailmessage.To.add("test2@test.com")
$mailmessage.Subject = “Pool monitoring”
$MailMessage.IsBodyHtml = $true
$mailmessage.Body = "$body"
$smtpclient.Send($mailmessage)
}
$body=(Get-Content $outfile) -join '<BR>'
if ($chk -eq 1)
{
sendmail $body
}
del null
del $outfile
exit
PS: how the hell can I use the code highlighting here?
cr