Kaseya Community

Need help with new agent procedure executing a Powershell script

This question is not answered

Hey folks,

I've written an agent procedure that that uses an executePowershell statement to run the below .ps1 file on a target server and return the results to #global:psresults#.  The agent procedure runs successfully on about 2/3 of our servers but on the rest it displays the following results. 

I can run the .ps1 script manually from the server and get the desired results and Kaseya reports the script as being successfull.  And there is also no '-f' in the Powershell script either. 

Any help greatly appreciated.   Thank you!

 

Results of #global:psresults#

The term '-f' is not recognized as a cmdlet, function,
operable program, or scr ipt file. Verify the term and try again.

At line:1 char:3

+ -fi <<<< le
c:\working\scripts\.\GetAutoServices.ps1

Contents of GetAutoServices.ps1

# get Auto that not Running:
Get-WmiObject Win32_Service |
Where-Object { $_.StartMode -eq 'Auto' -and $_.State -ne 'Running' } |
# process them; in this example we just show them:
Format-Table -AutoSize @(
    'Name'
    'DisplayName'
    @{ Expression = 'State'; Width = 9 }
    @{ Expression = 'StartMode'; Width = 9 }
    'StartName'
)

Agent Procedure

<?xml version="1.0" encoding="utf-8"?>
<ScriptExport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.kaseya.com/vsa/2008/12/Scripting">
  <Procedure name="Get Auto Stopped Services v.1" treePres="3" id="1619176669" folderId="45221241424563119198119232" treeFullPath="myProcedures - scarroll">
    <Body description="Emails the engineer who ran the procedure a list of services that start automatically but are stopped on the target machine.  Requires GetAutoServices.ps1 on the target machine in c:\working\scripts\.  Use Agent Prodecures&gt;Distribute File to accomplish this.">
      <If description="In order for this to work GetAutoServices.ps1 must be on the target machine in c:\working\scripts\">
        <Condition name="TestFile">
          <Parameter xsi:type="StringParameter" name="Path" value="%windir%\System32\WindowsPowerShell\v1.0\powershell.exe" />
          <Parameter xsi:type="EnumParameter" name="Condition" value="Exists" />
          <Parameter xsi:type="StringParameter" name="Value" value="" />
        </Condition>
        <Then>
          <Statement name="Execute Powershell" continueOnFail="false">
            <Parameter xsi:type="StringParameter" name="Parameter1" value="c:\working\scripts\GetAutoServices.ps1" />
            <Parameter xsi:type="StringParameter" name="Parameter2" value="" />
            <Parameter xsi:type="StringParameter" name="Parameter3" value="True" />
          </Statement>
          <Statement name="PauseScript" continueOnFail="false" osType="Windows">
            <Parameter xsi:type="IntegerParameter" name="Seconds" value="15" />
          </Statement>
          <Statement name="SendEmail" continueOnFail="false" osType="Windows">
            <Parameter xsi:type="StringParameter" name="To" value="#adminDefaults.adminEmail#" />
            <Parameter xsi:type="StringParameter" name="Subject" value="Services Check on #vCollectionMember.Machine_GroupID#" />
            <Parameter xsi:type="MultiLineStringParameter" name="Body" value="This is a list of services on #vCollectionMember.Machine_GroupID# that start automatically but are stopped...&#xA;&#xA;#global:psresult#&#xA;&#xA;#scriptIdTab.scriptName# ran by #adminDefaults.adminName#&#xA;&#xA;Agent Procedure: #scriptIdTab.scriptName#" />
          </Statement>
        </Then>
        <Else>
          <Statement name="SendEmail" continueOnFail="false" osType="Windows">
            <Parameter xsi:type="StringParameter" name="To" value="#adminDefaults.adminEmail#" />
            <Parameter xsi:type="StringParameter" name="Subject" value="Services Check [POWERSHELL NOT INSTALLED] on #vCollectionMember.Machine_GroupID#" />
            <Parameter xsi:type="MultiLineStringParameter" name="Body" value="Please install Powershell on #vCollectionMember.Machine_GroupID# and rerun the ##scriptIdTab.scriptName# agent procedure." />
          </Statement>
          <Statement name="ExecuteShellCommand" continueOnFail="false" osType="2008">
            <Parameter xsi:type="StringParameter" name="Command" value="start ocsetup MicrosoftWindowsPowerShell" />
            <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="User" />
            <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />
          </Statement>
        </Else>
      </If>
    </Body>
  </Procedure>
</ScriptExport>

All Replies
  • I'll message you directly to look into it and send a possible fix.

  • Thanks, Ben.  Much appreciated!

  • I'm seeing the same thing.  We're you two able to find a resolution to this?

  • I am looking into this now as well.. no answers..