0 Replies Latest reply on Jul 11, 2014 6:33 PM by vijayrana968

    Getting Error in Windows Powershell execution.

    vijayrana968 Master
    vExpert

      Hi,

       

      I have Installed. Vmware PowerCli, Activeperl, and Powershell V3. Having vSphere 5.0 environment. Running windows based script

       

      getting below error :

       

      PS C:\scripts> .\report.ps1

      new-object : Exception calling ".ctor" with "1" argument(s): "Could not find file

      'C:\scripts\vmware_health_check20140711.html'."

      At C:\scripts\report.ps1:13 char:8

      + $att = new-object Net.Mail.Attachment($file)

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

          + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException

          + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

       

       

      Exception calling "Add" with "1" argument(s): "Value cannot be null.

       

      report.ps1 content is :

       

      $dt = get-date -format yyyyMMdd

      C:\scripts\vmwareHealthCheck.pl --server vcdevvce01 --username ***** --password ***** --type vcenter --report C:\scripts\vmware_health_check$dt.html -email yes

      $pp = get-process perl

      $pp.waitforexit()

      $file = "C:\scripts\vmware_health_check$dt.html"

      $smtpServer = "YourEmailServerName"

      $msg = new-object Net.Mail.MailMessage

      $smtp = new-object Net.Mail.SmtpClient($smtpServer)

      $msg.From = "vmwarereport@yourcompany.com"

      $msg.To.Add("yourname@yourcompany.com")

      $msg.Subject = "Today's VMWare Health Report"

      $msg.Body = "Enjoy from myvmland.com!"

      $att = new-object Net.Mail.Attachment($file)

      $msg.Attachments.Add($att)

      $smtp.Send($msg)

      $att.Dispose()

      Remove-Item C:\scripts\vmware_health_check$dt.html