Get-ScheduledTask not recognized?

12 views
Skip to first unread message

aaldi

unread,
Sep 17, 2018, 2:04:32 PM9/17/18
to Ansible Project
I'm trying to run ansible code to execute code on a windows machine. I do that by scheduling a task as a way of 'elevating' as mentioned in the documentation.
This has worked previously, but now I switched to working with Windows 7 enterprise, and I've had several problems already.

Currently, I upgraded powershell to version 4.0, and when I run my ansible code, I get the following error:

"The term 'Get-ScheduledTask' is not recognized as the name of a cmdlet"
  
Is there a way to fix this? (maybe a windows hotfix) 
Has this happened before to anyone?

Jordan Borean

unread,
Sep 17, 2018, 4:30:58 PM9/17/18
to Ansible Project
Get-ScheduledTask is only available if you are running Windows 8/Server 2012 or newer. It requires some internal components that are not available on older OS' like Windows 7 so even if you have a newer version of PowerShell you won't be able to use it.

Since Ansible 2.5, the win_scheduled_tasks module https://docs.ansible.com/ansible/latest/modules/win_scheduled_task_module.html has moved away from using those cmdlets to the COM API so it supports older hosts and you can use that to define your task.

While you can use scheduled tasks, using become is a lot better and easier way to "elevate" your process. It's not technically elevating in the traditional sense as WinRM runs as admin but become will do something similar to a scheduled task and escape the network limitations placed on a WinRM process. You can have a read about it here https://docs.ansible.com/ansible/latest/user_guide/become.html#become-and-windows.

Thanks

Jordan

aaldi

unread,
Sep 18, 2018, 9:30:37 AM9/18/18
to Ansible Project
Thanks! That helped a ton. This has worked for me previously in another environment. But I switched the environment and didn't realize I was working with ansible 2.4 currently.
Reply all
Reply to author
Forward
0 new messages