PowerCLI script to gather report on virtual machines mounted with CDROM/ISO
#### HTML Output Formatting #######
$a = "<style>"
$a = $a + "BODY{background-color:White ;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:Green}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"
$a = $a + "</style>"
################################################################################################
Remove-Item C:\Temp\CDROM.html
$CurrentDate = Get-Date
$CurrentDate = $CurrentDate.ToString('dd-MMM-yyyy')
Connect-viserver vcenterserver
Get-VM | Get-CDDrive | select @{N="VM";E="Parent"},IsoPath | where {$_.IsoPath -ne $null} | ConvertTo-html -Head $a -Body "<H2> </H2>" >> C:\Temp\CDROM.html
$body = [System.IO.File]::ReadAllText('C:\Temp\CDROM.html')
Send-MailMessage -To ToMailAddress -From FromMailAddress -Subject "Virtual Machine Mounted with CDROM/ISO as on $CurrentDate" -Body $body -SmtpServer SMTPServer -BodyAsHtml
Disconnect-VIServer vcenterserver -Confirm:$False
No comments:
Post a Comment