# Query on connecting remote windows servers from powershell server via ansible.

**URL:** <https://forum.ansible.com/t/query-on-connecting-remote-windows-servers-from-powershell-server-via-ansible/23118>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [November 28, 2016, 10:26am UTC](https://forum.ansible.com/t/query-on-connecting-remote-windows-servers-from-powershell-server-via-ansible/23118 "2016-11-28T10:26:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajesh\_N](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Rajesh\_N](https://forum.ansible.com/u/Rajesh_N)\
**Post date:** [November 28, 2016, 10:26am UTC](https://forum.ansible.com/t/query-on-connecting-remote-windows-servers-from-powershell-server-via-ansible/23118/1 "2016-11-28T10:26:48Z")

</div>

Dear All,  
I have an query/issue.  
If i try the same thing via ansible, i get an error.

Executing just Invoke-command -computer -ScriptBlock {Get-Service}

or

New-PSSession -ComputerName   
Enter-PSSession -ComputerName   
Get-Service  
Invoke-command -computer -ScriptBlock {Get-Service}  
exit

doesn’t work. Get error saying “A specified logon session does not \r\nexist. It may already have been terminated”

win\_ping and kerberos works fine. I have used the same domain user to connect to the powershell server in windows.yml file.  
kindly advise.

Regards,  
Rajesh

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [November 29, 2016, 8:40am UTC](https://forum.ansible.com/t/query-on-connecting-remote-windows-servers-from-powershell-server-via-ansible/23118/2 "2016-11-29T08:40:30Z")

</div>

Hi Rajesh,

You are hitting what is known as the ‘second hop’ problem.

Ansible → Windows host A win\_ping (ok only 2 machines involved)

Windows Host A → invoke command Windows Host B (ok, again only 2 machines involved)

Ansible → Windows Host A → invoke command Windows Host B (disallowed because of second hop to 3rd machine)

Fortunately since you have a domain set up you can use delegation to allow this.

Just set the following in your windows group vars (needs pywinrm 0.2.0 or later)

ansible\_winrm\_kerberos\_delegation: yes

Hope this ehlps,

Jon

---

<div class="post-metadata">

**Author:** ![Rajesh\_N](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Rajesh\_N](https://forum.ansible.com/u/Rajesh_N)\
**Post date:** [November 29, 2016, 11:52am UTC](https://forum.ansible.com/t/query-on-connecting-remote-windows-servers-from-powershell-server-via-ansible/23118/3 "2016-11-29T11:52:16Z")

</div>

Hi Jon,  
I had a demo in 4 hours to showcase ansible and your reply below saved my day.  
Thank you so much.  
Any way to give you points???

Regards,  
Rajesh

---

<div class="post-metadata">

**Author:** ![Rajat\_Bhasin](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@Rajat\_Bhasin](https://forum.ansible.com/u/Rajat_Bhasin)\
**Post date:** [June 13, 2017, 6:47am UTC](https://forum.ansible.com/t/query-on-connecting-remote-windows-servers-from-powershell-server-via-ansible/23118/4 "2017-06-13T06:47:27Z")

</div>


