# AnsiballZ/PowerShell ParseError when using win\_scheduled\_task

**URL:** <https://forum.ansible.com/t/ansiballz-powershell-parseerror-when-using-win-scheduled-task/44375>\
**Category:** Get Help\
**Tags:** powershell, windows, wsl2, ansiballz, ubuntu\
**Created:** [August 26, 2025, 8:08pm UTC](https://forum.ansible.com/t/ansiballz-powershell-parseerror-when-using-win-scheduled-task/44375 "2025-08-26T20:08:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dustin\_k](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@dustin\_k](https://forum.ansible.com/u/dustin_k)\
**Post date:** [August 26, 2025, 8:08pm UTC](https://forum.ansible.com/t/ansiballz-powershell-parseerror-when-using-win-scheduled-task/44375/1 "2025-08-26T20:08:27Z")

</div>

Hello,

I’m attempting to create a scheduled task using win\_scheduled\_task but getting a ParseError. It looks like in order to execute the ansible task, AnsiballZ generates a Powershell script, but when trying to execute the script, Powershell doesn’t see it as valid.

This happens even with the [example task from win\_scheduled\_task’s docs](https://docs.ansible.com/ansible/latest/collections/community/windows/win_scheduled_task_module.html#examples):

```auto
---
- name: Test win_scheduled_task
  hosts: 127.0.0.1
  connection: local
  tasks:
    - name: Create a task to open 2 command prompts as SYSTEM
      community.windows.win_scheduled_task:
        name: TaskName
        description: open command prompt
        actions:
          - path: cmd.exe
            arguments: /c hostname
          - path: cmd.exe
            arguments: /c whoami
        triggers:
          - type: daily
            start_boundary: '2017-10-09T09:00:00'
        username: SYSTEM
        state: present
        enabled: true

```

Here’s the output:

```auto
___@___ :/mnt/c/Users/___/cuas/cuas-ansible$ ansible-playbook playbooks/install-archiver.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Test win_scheduled_task] ******************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************
ok: [127.0.0.1]

TASK [Create a task to open 2 command prompts as SYSTEM] ****************************************************************************
fatal: [127.0.0.1]: FAILED! => {
    "changed": false,
    "rc": 1
}

MSG:

MODULE FAILURE
See stdout/stderr for the exact error

MODULE_STDERR:

ParserError: /home/___/.ansible/tmp/ansible-tmp-1756236420.9482832-2444818-11025389486272/AnsiballZ_win_scheduled_task.ps1:159
Line |
 159 | {"module_entry": "IyFwb3dlcnNoZWxsCgojIENvcHlyaWdodDogKGMpIDIwMTU …
     | ~
     | unexpected token '', expected 'begin', 'process', 'end', 'clean', or
     | 'dynamicparam'.

PLAY RECAP **************************************************************************************************************************
127.0.0.1 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

```

Relevant software versions:

- OS Name: Microsoft Windows 11 Enterprise
- OS Version 10.0.22631 Build 22631
- WSL: 6.6.87.2-microsoft-standard-WSL2
- Ubuntu: 24.04.2 LTS
- Powershell: PowerShell 7.5.2
- Ansible: [core 2.16.3]
- Python: 3.12.3
- Jinja: 3.1.2
- community.windows: 2.1.0

Any help is appreciated!

---

<div class="post-metadata">

**Author:** ![flowerysong](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/flowerysong/32/2305_2.png) [@flowerysong](https://forum.ansible.com/u/flowerysong)\
**Post date:** [August 27, 2025, 4:09am UTC](https://forum.ansible.com/t/ansiballz-powershell-parseerror-when-using-win-scheduled-task/44375/2 "2025-08-27T04:09:42Z")

</div>

> [@dustin\_k](#):
>
> Ansible: [core 2.16.3]

2.16 is quite old and unsupported, and even within that series there were 11 releases after 2.16.3. While this won’t necessarily be resolved by moving to a newer version, I know there was a pretty major Powershell-related change in 2.18, and it was touched again in 2.19. Testing the newest version would at least rule out it being a known bug that was already addressed.

---

<div class="post-metadata">

**Author:** ![dustin\_k](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@dustin\_k](https://forum.ansible.com/u/dustin_k)\
**Post date:** [August 27, 2025, 4:21pm UTC](https://forum.ansible.com/t/ansiballz-powershell-parseerror-when-using-win-scheduled-task/44375/3 "2025-08-27T16:21:58Z")

</div>

Thanks, I’ll try upgrading when able.

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [September 4, 2025, 3:42am UTC](https://forum.ansible.com/t/ansiballz-powershell-parseerror-when-using-win-scheduled-task/44375/4 "2025-09-04T03:42:04Z")

</div>

You are targeting localhost which is actually the WSL instance. These PowerShell modules need to run on a Windows host. Unfortunately the only way to do that right now with Ansible on a WSL instance is to connect back over WinRM to the Windows side and pretend it is a remote target.
