Quantcast
Viewing all articles
Browse latest Browse all 175326

Datastore report generating using script.

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   MSSI\xxxx

Send-MailMessage : The operation has timed out.

At C:\Scripts1\New 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


Viewing all articles
Browse latest Browse all 175326

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>