Go to All Forums

SchedulateTask

Good morning,

I have a problem with the integration of a powershell plugin.
I wanted to integrate a scheduled task but site24x7 returned this as an error:

Execution Error :: schtasks : Error :: The syntax of the filename, directory or volume name is incorrect.Au caractère C:\Program Files (x86)\Site24x7\WinAgent\monitoring\Plugins\ScheduledTask\ScheduledTask. ps1:65: 20+ $jobDetails = schtasks /QUERY /FO LIST /V /TN $jobName+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo: NotSpecified: (Error: The syn...is incorrect.:String) [], RemoteExc

Yet the location of my scheduled tasks is good.

Here is my code:


Function GetErrorMessage
([int]$errorcode)
{
$msg = ""
switch($errorcode)
{
0 { $msg="The operation completed successfully";break}
1 { $msg="Incorrect function called or unknown function called. (did you use the correct start in folder and/or environment path for the bat/exe?)";break}
2 { $msg="File not found.";break}
10 { $msg="The environment is incorrect.";break}
267008 { $msg="Task is ready to run at its next scheduled time.";break}
267009 { $msg="Task is currently running.";break}
267010 { $msg="Task is disabled.";break}
267011 { $msg="Task has not yet run.";break}
267012 { $msg="There are no more runs scheduled for this task.";break}
267014 { $msg="Task is terminated.";break}
2147750671 { $msg="Credentials became corrupted (*)";break}
2147750687 { $msg="An instance of this task is already running.";break}
2147942402 { $msg="Basically something like file not available (2147942402)";break}
2147942667 { $msg="Action 'start in' directory can not be found.";break}
2147943645 { $msg="The service is not available (is 'Run only when an user is logged on' checked?)";break}
3221225786 { $msg="The application terminated as a result of a CTRL+C.";break}
3228369022 { $msg="Unknown software exception.";break}
default {"Something else happened"; break}
}
return $msg
}

Function Get-ScheduledJobDetails($jobName)
{
$ret = New-Object -TypeName PSObject
$atributeList = @("TaskName","Author","Scheduled Task State","Start Date","Next Run Time","Status","Last Run Time","Last Result")
$jobDetails = schtasks /QUERY /FO LIST /V /TN $jobName
foreach($atribute in $atributeList)
{
$temp = ($jobDetails | Select-String -Pattern $atribute| Select-Object -Last 1).ToString()
$key,$value = $temp.Split(':',[StringSplitOptions]"None")
$key = ($key.trim()).Replace(' ',"_");
$value = ($value -join ':').trim()
$ret | Add-Member -Type NoteProperty -Name $key -Value $value
}
return $ret
}


$taskName = "C:\Program Files (x86)\Cegid\Cegid Business\CegidFinance\Task Scheduler\Framework\CbpReportGuardian.exe" # Raplace your taskname to be monitored


#data collection
$data = @{}


$task = Get-ScheduledJobDetails $taskName
$author = $task.Author
$data.Add("author",$author)
$Start_Date = $task.Start_Date
$data.Add("Start_Date",$Start_Date)
$statestr = $task.Status
$data.Add("Status",$statestr.ToString())
$lastRunTime = $task.Last_Run_Time
$data.Add("lastRunTime",$lastRunTime)
$lastTaskResult = $task.Last_Result
$data.Add("errorCode",$lastTaskResult)
$timenow = Get-Date
$timespan = NEW-TIMESPAN –Start $lastRunTime –End $timenow

$timediff = $timespan.Days.ToString() + " Days "+ $timespan.Hours.ToString() + " Hours " + $timespan.Minutes.ToString() + " Minutes " + $timespan.Seconds.ToString() + " Seconds "
$data.Add("lastRunBefore",$timediff)

#Site24x7 Plugin Metrics

$version = "1"

$displayname = "OL-XRP " + $taskName

$heartbeat = "True"

$mainJson = @{}

$mainJson.Add("version",$version)
$mainJson.Add("displayname",$displayname)
$mainJson.Add("heartbeat",$heartbeat)
$mainJson.Add("data",$data)
if($lastTaskResult -ge 0)
{
$msg = GetErrorMessage($lastTaskResult)
$mainJson.Add("msg",$msg)
}
$mainJson | ConvertTo-Json

 

Thanks to you.

Cordially,

 

Jeremy Kebir 

Like (3) Reply
Replies (12)

Hi,

Is there is any task with the name "C:\Program Files (x86)\Cegid\Cegid Business\CegidFinance\Task Scheduler\Framework\CbpReportGuardian.exe" in your server?

If there is no such task present in your server, please get the task name that you want to monitor from the task scheduler and update it in the script and try again. Hope this helps.

 

Regards,

Hisham Thorakkal

 

Like (0) Reply

Hi, 

Yes a scheduled task has this name in my server with this path.

Is it necessary to simply put the task name written in hard copy or to write the precise path of the task?

Thanks to you.

Cordially,

Jeremy Kebir

Like (0) Reply

Hi, 

Please share the screenshot of the task scheduler which contains the name and location of the task you want to monitor. That will help us to debug your case further. 

 

Regards,

Hisham Thorakkal

Like (0) Reply

Hi,

 

Here are the screenshots of the task (in attachment).

Thanks to you.

 

Cordially, 

 

Jeremy Kebir

Attachments
Capture1.PNG
Size: 10.02 KB
capture2.PNG
Size: 116.14 KB
Like (0) Reply

I can't upload my third screenshot but you can see it on the right side of the path :

Folders of the task \Cegid


Cordially,

Jeremy Kebir

Like (0) Reply

Hi,

Thank you for sharing the details.

We request you to provide the 'path with the task name' in the script.

For example,

In screenshot task1, the name is 'Adobe Acrobat Update Task' and path is '\'. Provide the task name in the script as 'Adobe Acrobat Update Task'.

Note: If the location is just '/', providing only the task name is sufficient.

Another example,

In screenshot task2, the name is 'Firefox Default Browser Agent E7CF176E110C211B' and path is '\Mozilla'. Give the task name in the script as '\Mozilla\Firefox Default Browser Agent E7CF176E110C211B'.

Hope this helps. Let us know for further queries, if any, in the below thread.

 

Regards,

Hisham Thorakkal

Attachments
task1.JPG
Size: 101.1 KB
task2.JPG
Size: 65.98 KB
Like (0) Reply

Hi,

I still have a problem.

I specify that my file and my powershell script each have the same name and that the path is well referenced.

here is the PluginDetails that I get Site24x7 :

 

 

{"Cegidfinance":{"displayname":"Cegidfinance-OL-XRP.orientis.fr","pluginkey":"NULL","JsonCount":"0","status":"2","pluginName":"Cegidfinance","heartbeat":"True","error_msg":"Execution Error :: Impossible d'appeler une m\u201athode dans une expression Null.Au caract\u0160re C:\\Program Files (x86)\\Site24x7\\WinAgent\\monitoring\\Plugins\\Cegidfinance\\Cegidfinance.ps1:68 : 9+ $temp = ($jobDetails | Select-String -Pattern $atribute| Sele ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation : (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Impossible d'appeler une m\u201athode dans une expression Null.Au caract\u0160re C:\\Program Files (x86)\\Site24x7\\WinAgent\\monitoring\\Plugins\\Cegidfinance\\Cegidfinance.ps1:69 : 9+ $key,$value = $temp.Split(':',[StringSplitOptions]\"None\")+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation : (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Impossible d'appeler une m\u201athode dans une expression Null.Au caract\u0160re C:\\Program Files (x86)\\Site24x7\\WinAgent\\monitoring\\Plugins\\Cegidfinance\\Cegidfinance.ps1:70 : 9+ $key = ($key.trim()).Replace(' ',\"_\");+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation : (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Add-Member : Impossible de lier l'argument au param\u0160tre \u00ae\u00ffName\u00ff\u00af, car il a la valeur Null.Au caract\u0160re C:\\Program Files (x86)\\Site24x7\\WinAgent\\monitoring\\Plugins\\Cegidfinance\\Cegidfinance.ps1:72 : 52+ $ret | Add-Member -Type NoteProperty -Name $key -Value $value+ ~~~~ + CategoryInfo : InvalidData : (:) [Add-Member], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCo mmand Impossible d'appeler une m\u201athode dans une expression Null.Au caract\u0160re C:\\Program Files (x86)\\Site24x7\\WinAgent\\monitoring\\Plugins\\Cegidfinance\\Cegidfinance.ps1:68 : 9+ $temp = ($jobDetails | Select-String -Pattern $atribute| Sele ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation : (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Impossible d'appeler une m\u201athode dans une expression Null.Au caract\u0160re C:\\Program Files (x86)\\Site24x7\\WinAgent\\monitoring\\Plugins\\Cegidfinance\\Cegidfinance.ps1:69 : 9+ $key,$value = $temp.Split(':',[StringSplitOptions]\"None\")+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation : (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Impossible d'appeler une m\u201athode dans une expression Null.Au caract\u0160re C:\\Program Files (x86)\\Site24x7\\WinAgent\\monitoring\\Plugins\\Cegidfinance\\Cegidfinance.ps1:70 : 9+ $key = ($key.trim()).Replace(' ',\"_\");+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation : (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Add-Member : Impossible de lier l'argument au param\u0160tre \u00ae\u00ffName\u00ff\u00af, car il a la valeur Null.Au caract\u0160re C:\\Program Files (x86)\\Site24x7\\WinAgent\\monitoring\\Plugins\\Cegidfinance\\Cegidfinance.ps1:72 : 52+ $ret | Add-Member -Type NoteProperty -Name $key -Value $value+ ~~~~ + CategoryInfo : InvalidData : (:) [Add-Member], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCo mmand Impossible d'appeler une m\u201athode dans une expression Null.Au caract\u0160re C:\\Program Files (x86)\\Site24x7\\WinAgent\\monitoring\\Plugins\\Cegidfinance\\Cegidfinance.ps1:68 : 9+ $temp = ($jobDetails | Select-String -Pattern $atribute| Sele ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~","timeout":120,"dcinterval":"300","version":"1"}}

 

 

 

Cordially,

 

Jeremy Kebir 

Attachments
schedulatetaskscreen.PNG
Size: 188.33 KB
Like (0) Reply

Hi,

 We could see that the system language is not English, is it possible to share the system language details?

Also, the script is created for the OS with system language English. We will edit the script and give you, to work with your system language. For that, please execute the below command and share the output:

schtasks /QUERY /FO LIST /V /TN "\Cegid\CegidFinance (Task Scheduler)"

Thanks!

 

Regards,

Hisham

Like (0) Reply

Hello,

The language of our system is French.

I tried your order but it was not successful.

The subject becomes a little urgent from our side, if it is possible for you to do what is necessary quickly enough.

Thanks to you.

With kind regards,

Jeremy Kebir - ALFUN

Like (0) Reply

Hi,

Can you please share the output of the above command with us? Or, we can have a session to resolve the issue. Please contact support@site24x7.com for further analysis.

Regards,
Hisham

Like (0) Reply

Hello,

I have contacted your support by email directly to arrange a session.

Ticket Number: [## 1058453 ##]

I have attached the result of the order.

Thanks to you.

Jeremy Kebir - Alfun

Attachments
schedulateTask.PNG
Size: 94.54 KB
Like (0) Reply

Hi,

The script contains schtasks command and the output of this command is based on the OS language. The script that you have used only works in English.

We tried to update the script based on the command output, but that did not work. This may be because the plugin script with schtasks mainly works for older versions of Windows like Windows 2008 R2.

When we checked in your server, the PowerShell commands Get-ScheduledTask and Get-ScheduledTaskInfo are working.

We have shared the plugin script with Get-ScheduledTask and Get-ScheduledTaskInfo commands (similar script already shared in https://www.site24x7.com/community/monitor-windows-scheduled-tasks, minor changes made to support the task path) to monitor the scheduled task.

Hope this helps. Let us know for further queries, if any, in the below thread. 

 

Regards,

Hisham

Attachments
ScheduledTask.zip
Size: 1.72 KB
Like (0) Reply

Was this post helpful?