Get-ScheduledTask does not work properly with SCCM


When running the application "with administrative right's" the function Get-ScheduledTask does not work for some reason. The script is unable to delete the scheduled task in the end, leaving the scheduled task in Windows forever. If we run it again the script will hang, because it is unable to detect that the scheduled task already exists and it will try to create a new task with the same name withouth the /force flag.

If we run the application in SCCM "with user's rights" everything works fine, but this is obviously never desirable.

Can anyone confirm this problem?
Closed Oct 5, 2013 at 2:01 PM by PowerSheller
Fixed in v3.0.6


jockebr wrote Oct 1, 2013 at 11:10 AM

I have found the problem, and a solution.
When using another Windows language than English the script will fail, because it searches after the scheduled task in the column called "TaskName" (see for example line 1884). The problem is, this column name is language specific and will have a different name in every language.

The simple solution is this. In AppDeployToolkitMain.ps1, change line 1843 from:

SchTasks.exe /Query /FO CSV | ConvertFrom-Csv


SchTasks.exe /Query /FO CSV | ConvertFrom-Csv –Header “TaskName”

That way the header of the first column in the CSV-output from schtasks.exe will always be called "TaskName" and the script will work perfect.

PowerSheller wrote Oct 5, 2013 at 2:01 PM

Thanks for raising this issue and nice job on the solution! We'll add this to v3.0.6.


Hermann wrote Apr 14, 2015 at 3:15 PM

Bug found in Version 3.6.2 Line 4284 Need to be changed:
[psobject[]]$SchtasksResults = $exeSchtasksResults | ConvertFrom-CSV -Header "HostName","TaskName","NextRun","Status","LastRun" -ErrorAction 'Stop'