You can't get Get-ScheduledTask
at windows 2008 R2 as it was introduced for Windows 2012 and nobody backported it. For more see the link at github.
The comment that describes the situation the best is:
Hi @dronkoff - This module is supported on PS 4.0. However, the
problem isn't in the version of PowerShell. The issue is that the
ScheduledTasks module, which this resource depends on, is not built
into Windows Server 2008R2. It was first included in Windows Server
2012.
This is the case with many of the PowerShell modules: They are missing
from older versions of Windows (Networking for example). In the odd
occasion there is an easy work around. However in this case converting
the resource over to use schtasks.exe is not possible without a
complete rewrite and would probably result in something really
unstable and buggy (not to mention the problems that would arise with
different localized versions of schtasks). I really can't see this
happening unfortunately (unless someone else from the community has
some ideas on how to do this).
But you are correct, this should be mentioned that Windows Server
2008R2 is not currently supported.
The workaround
The way around it, is to use schtask
with correct switches.
If you have it in the Microsoft
folder as I have it in the example you just need to run:
schtasks /tn \Microsoft\ServiceNow /query /fo LIST
The output:
Folder: \Microsoft
HostName: XXXXXACL06
TaskName: \Microsoft\ServiceNow
Next Run Time: 7/4/2018 8:16:22 AM
Status: Ready
Logon Mode: Interactive only
If you want more details you can use the /v
(verbose) switch:
schtasks /tn \Microsoft\ServiceNow /query /v > service_now_details.txt
Edit - to find a pattern
If you have only pattern to search you have to use some additional tool to search the string. The windows natively supports findstr
(or Select-String
(short sls
) in powershell):
To find the task name you can use then:
schtasks /query /fo LIST | findstr "ServiceNow"
OR even with wild charter
schtasks /query /fo LIST | findstr "ServiceNo*"
OR the powershell
way:
schtasks /query /fo LIST | sls 'ServiceNo*'
The output in all cases will be something like this (since my task is named exactly ServiceNow
):
TaskName: \Microsoft\ServiceNow
Edit2 case sensitivity
If you are searching for case insensitive string then:
for findstr
you have to add /I
to make it insensitive. The powershell's select-string
(sls) is naturally insensitive.
Get-ScheduledTask
. You can check your currently installed version with$PSVersionTable
. – Greenstone