# Win\_service name option contains non permitted characters and doesn't allow escaping

**URL:** <https://forum.ansible.com/t/win-service-name-option-contains-non-permitted-characters-and-doesnt-allow-escaping/27040>\
**Category:** Ansible Project\
**Created:** [March 19, 2018, 2:43pm UTC](https://forum.ansible.com/t/win-service-name-option-contains-non-permitted-characters-and-doesnt-allow-escaping/27040 "2018-03-19T14:43:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bob1](https://avatars.discourse-cdn.com/v4/letter/b/c37758/32.png) [@bob1](https://forum.ansible.com/u/bob1)\
**Post date:** [March 19, 2018, 2:43pm UTC](https://forum.ansible.com/t/win-service-name-option-contains-non-permitted-characters-and-doesnt-allow-escaping/27040/1 "2018-03-19T14:43:20Z")

</div>

Hi All

I am trying to use thw win\_service module to start a service.

My issue is the service name contains non-valid characters and I dont seem to be able escape the name correctly.

The service name is this:- “SAS [config-Lev1] SASMeta - Metadata Server”.

Any regexp or normal escaping of characters fails.

task code is:

- name: Start Metadata Server

win\_service:

name: “SAS [config-Lev1] SASMeta - Metadata Server”

state: started

Any ideas or is it a bug?

Bob

---

<div class="post-metadata">

**Author:** ![Mike\_Klebolt](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Klebolt](https://forum.ansible.com/u/Mike_Klebolt)\
**Post date:** [March 19, 2018, 4:24pm UTC](https://forum.ansible.com/t/win-service-name-option-contains-non-permitted-characters-and-doesnt-allow-escaping/27040/2 "2018-03-19T16:24:13Z")

</div>

Have you tried using the service name rather than the Display Name?

---

<div class="post-metadata">

**Author:** ![bob1](https://avatars.discourse-cdn.com/v4/letter/b/c37758/32.png) [@bob1](https://forum.ansible.com/u/bob1)\
**Post date:** [March 19, 2018, 5:37pm UTC](https://forum.ansible.com/t/win-service-name-option-contains-non-permitted-characters-and-doesnt-allow-escaping/27040/3 "2018-03-19T17:37:35Z")

</div>

This is the service name. They happen to match.

---

<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:** [March 19, 2018, 8:20pm UTC](https://forum.ansible.com/t/win-service-name-option-contains-non-permitted-characters-and-doesnt-allow-escaping/27040/4 "2018-03-19T20:20:26Z")

</div>

Looks like an issue with the Get-Service cmdlet which in turn affects the win\_service Ansible module. I’ve raised a bug for this [https://github.com/ansible/ansible/issues/37621](https://github.com/ansible/ansible/issues/37621).

You can test it out by just trying to run in PowerShell manually

`Get-Service -Name 'SAS [config-Lev1] SASMeta - Metadata Server'`

This shouldn’t return anything as that cmdlet is interpreting the chars as a string modifier instead of a string literal.

To get the stat side of win\_service working you just need to change the lines

[https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/windows/win\_service.ps1#L60](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/windows/win_service.ps1#L60)  
[https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/windows/win\_service.ps1#L389](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/windows/win_service.ps1#L389)

to

`$svc = Get-Service | Where-Object { $_.Name -eq $name }`

It looks like this will allow you to get the service details back but it will probably fail when trying to stop and start it as I see some other _\*-Service_ cmdlets being used with the _-Name_ parameter. The foolproof way to get it all working is to no work with a service with those chars but that may be hard to do in your environment.

Hopefully we should have a fix in soon for this.

Thanks

Jordan
