7 Replies Latest reply on Dec 12, 2016 12:39 PM by Eric.Hubbard

    IT Scripts Error

    Eric.Hubbard Rookie

      I am trying to write a script that will send out an email using the shavlik console so we can setup notifications better than what Shavlik can does with what is built it.  I wrote a script that will work just fine when I run it on my local machine but when I try to run from the shavlik console i get a error.

       

      "Error: A command that prompts the user failed because the host program or the command type does not support"

       

      below is the script that i was able to import

       

      <#

          <stScript uid="Scubbed">

              <name>SendEmail</name>

              <version>1.0.0.0</version>

              <author>company name</author>

              <scriptType type="consoleOnly" />

               <options>

                  <option name="OutputMachineResults" value="true" />

                  <option name="OutputRunResults" value="true" />

                  <option name="CombineOutputFiles" value="false" />

                  <option name="DeleteMachineFiles" value="false" />

              </options>

              <description>

                  <category>Email</category>

                  <purpose>Send email notifications</purpose>

                  <inputs>None</inputs>

                  <outputs>None</outputs>

              </description>

              <parameters>

                  <parameter>

                      <name>to</name>

                      <description>The reciptant of the email</description>

                      <default>""</default>

                  </parameter>

                  <parameter>

                      <name>subject</name>

                      <description>The subject of the email</description>

                      <default>""</default>

                  </parameter>

                  <parameter>

                      <name>body</name>

                      <description>The message body of the email</description>

                      <default>""</default>

                  </parameter>

              </parameters>

          </stScript>

      #>

       

      function sendMail{

       

       

          Param (

              [string]$to,

              [string]$subject,

              [string]$body

              )

       

       

           Write-Host "Sending Email"

       

       

           #SMTP server name

           $smtpServer = "SMTPSERVER"

       

       

           #Creating a Mail object

           $msg = new-object Net.Mail.MailMessage

       

       

           #Creating SMTP server object

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

       

       

           #Email structure

           $msg.From = "fromaddress@domain.com"

           $msg.ReplyTo = "replytoaddress@domain.com"

           $msg.To.Add($to)

           $msg.subject = $subject

           $msg.body = $body

         

       

       

           #Sending email

           $smtp.Send($msg)

       

      }

       

       

      Sendmail -to $to -subject $subject -body $body

       

       

       

      Is there something I am doing wrong.  I have tried this several different ways and it simply doesn't seem to work but I can run it from the local windows server just not inside the application of shavlik.

        • 1. Re: IT Scripts Error
          rdavidson SupportEmployee

          Hello,

           

          Write-Host is unfortunately an unsupported command for ITScripts. The following line:

           

          "Write-Host "Sending Email""

           

          Will cause an error.

           

          There are a few commands that are unsupported in the Protect's ITScripts environment. They are:

           

          Out-Host

          Read-Host

          Write-Host

          Out-GridView

          • 2. Re: IT Scripts Error
            Eric.Hubbard Rookie

            I removed that line as it really didn't do anything for me.  I am now getting an error saying  Error: Exception Calling "Send" with "1" argument(s): "Failure Sending mail."

             

            Do you know why I would be getting this or is there some place that I can actually see the powershell output to see what it is actually doing?

            • 3. Re: IT Scripts Error
              rdavidson SupportEmployee

              You can check under C:\ProgramData\Landesk\Shavlik Protect\ITScriptsOutput

               

              There will be folders named by the target (in this case, MyMachine) and the date and time of the operation. Inside of that should be macineError.txt

               

              I was able to get your script to import and successfully send an email, however, I had some issues with using our smtp server here to send an email to an address that isn't our domain. If you weren't already, I'd try making the "to" address one on your domain, or you might get a "5.7.1 Unable to Relay" response.

               

              I also removed the ReplyTo attribute on the mailmessage object, as I didn't have a use for it. This shouldn't impact the send operation though.

              • 4. Re: IT Scripts Error
                rdavidson SupportEmployee

                In the off chance you're trying this on a non business network, like if you're working from home, the operation is almost guaranteed to fail due to most ISP's blocking outbound port 25 on non business lines.

                • 5. Re: IT Scripts Error
                  Eric.Hubbard Rookie

                  So I am doing this on our business network.  The to address is also my business email so everything should be internal so we shouldn't have a port issue. 

                   

                  Does the version of powershell matter?  I developed the script in powershell 5 and right now the server has powershell 4 on it.  wouldn't that have anything to do with it?  I just am not sure how the Shavlik console uses the powershell command prompt?

                  • 6. Re: IT Scripts Error
                    rdavidson SupportEmployee

                    The version shouldn't matter. Your script runs in Powershell 4, so there aren't any command compatibility issues.

                     

                    The error output should give you more information.

                    • 7. Re: IT Scripts Error
                      Eric.Hubbard Rookie

                      Sorry I was sending to the wrong relay server.  I corrected that everything is now working.

                       

                      Thanks for your help with this.  This will really help us in our automation.

                       

                      Thanks,