Datastore report generating using script.

This post was originally published on this site

Hi Team,

 

 

I found one of the scripts from the Lucd discussion for generating the report for datastore usages via email 

 

I would like to implement the script for multiple vcenter at once, Can someone help me with this?

 

Attached the script and error statement….

 

#### Script starting#######

 

Get-Module -Name VMware* -ListAvailable | Import-Module

Connect-VIServer -Server ‘10.20.10.8’

$head = @”

<style>

TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}

TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;;background-color:thistle}

TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}

</style>

“@

 

$body = Get-Datastore |

    Select @{N=’Datastore’;E={$_.Name}},

         @{N=’CapacityGB’;E={[math]::Round($_.CapacityGB,1)}},

         @{N=’FreeSpaceGB’;E={[math]::Round($_.FreeSpaceGB,1)}},

         @{N=’UsedPercent’;E={[math]::Round(($_.CapacityGB – $_.FreeSpaceGB)/$_.CapacityGB*100,1)}},

         @{N=’FreePercent’;E={

             $p = [math]::Round((1 – ($_.CapacityGB – $_.FreeSpaceGB)/$_.CapacityGB)*100,1)

             if($p -lt 10){“#br#$($p)”}

             elseif($p -lt 30){“#by#$($p)”}

             else{“#bg#$($p)”}

         }} |

     Sort-Object -Property UsedPercent -Descending |

     ConvertTo-Html -Head $head

 

$body = $body.Replace(‘>#br#’,’ bgcolor=”red”>’).Replace(‘>#by#’,’ bgcolor=”yellow”>’).Replace(‘>#bg#’,’ bgcolor=”green”>’)

 

$sMail = @{

     To = ‘me@domain.com

     From = ‘me@domain.com

     Subject = ‘Datastore Report’

     BodyAsHtml = $true

     Body = $body | Out-String   

     SmtpServer = ‘owa.me.domain.com’

}

Send-MailMessage @sMail

Disconnect-VIServer -Server ‘10.20.10.8’ -Confirm:$false

 

 

###### Error Getting like below #######

Name                           Port  User

—-                           —-  —-

10.20.10.8                     443   MSSIxxxx

Send-MailMessage : The operation has timed out.

At C:Scripts1New Datastore report.ps1:35 char:1

+ Send-MailMessage @sMail

+ ~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:Sm

   tpClient) [Send-MailMessage], SmtpException

    + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.Send

   MailMessage

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.