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?
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.
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! 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.