# Auto-map a windows drive

**URL:** <https://forum.ansible.com/t/auto-map-a-windows-drive/16870>\
**Category:** Ansible Developer\
**Tags:** windows\
**Created:** [November 25, 2014, 1:27am UTC](https://forum.ansible.com/t/auto-map-a-windows-drive/16870 "2014-11-25T01:27:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joey](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@Joey](https://forum.ansible.com/u/Joey)\
**Post date:** [November 25, 2014, 1:27am UTC](https://forum.ansible.com/t/auto-map-a-windows-drive/16870/1 "2014-11-25T01:27:03Z")

</div>

I’m trying to figure out how to use Ansible to have windows clients automatically map a network drive. If I use the script module and either powershell or “net use”, I get an “Access Denied” error. Apparently, trying to map a drive falls under the second hop credentials area of problems. All the suggestions online are to use CredSSP to get around second hop issues, but I don’t think there’s any way to do that with ansible. Any ideas?

---

<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 25, 2014, 10:18pm UTC](https://forum.ansible.com/t/auto-map-a-windows-drive/16870/2 "2014-11-25T22:18:00Z")

</div>

Can you avoid the problem by fetching whatever you need via the win\_get\_url module perhaps? Obviously you need some way of serving the files you need?

Jon

---

<div class="post-metadata">

**Author:** ![Joey](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@Joey](https://forum.ansible.com/u/Joey)\
**Post date:** [November 26, 2014, 3:09am UTC](https://forum.ansible.com/t/auto-map-a-windows-drive/16870/3 "2014-11-26T03:09:31Z")

</div>

Unfortunately, I’m not actually trying to map the drive so I can get to files. I’m trying to auto-map the drive so it is available for users. It’s just a drive that we want permanently mapped, and I don’t have access to AD Group Policies to do so. I was hoping to use Ansible to map the drive, but it needs “second hop” credentials to confirm that the share can be accessed.

---

<div class="post-metadata">

**Author:** ![Chris\_Church1](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Church1](https://forum.ansible.com/u/Chris_Church1)\
**Post date:** [November 26, 2014, 4:00am UTC](https://forum.ansible.com/t/auto-map-a-windows-drive/16870/4 "2014-11-26T04:00:16Z")

</div>

I'm not sure we'll have support for CredSSP for awhile (in fact, I haven't  
found any winrm/wsman client that supports it aside from what's built into  
Windows).

Do you have an example of how you'd do the drive mapping using PowerShell  
from one Windows machine to another?

---

<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 26, 2014, 10:53am UTC](https://forum.ansible.com/t/auto-map-a-windows-drive/16870/5 "2014-11-26T10:53:24Z")

</div>

Something like this? (Not that I have tried via ansible)

`$net = New-Object -ComObject WScript.Network $net.mapnetworkdrive("B:","\\someserver\someshare")`

Jon

---

<div class="post-metadata">

**Author:** ![Timothy\_Vandenbrande](https://avatars.discourse-cdn.com/v4/letter/t/7ab992/32.png) [@Timothy\_Vandenbrande](https://forum.ansible.com/u/Timothy_Vandenbrande)\
**Post date:** [March 17, 2015, 9:49am UTC](https://forum.ansible.com/t/auto-map-a-windows-drive/16870/6 "2015-03-17T09:49:09Z")

</div>

The main issue with that, is since windows 6.x (vista/7/8/2008/2012) you can’t access drives mounted by an administrative user.  
After running that code through ansible and you check the client machine, you’re getting drive unavailable.

(btw, you get the same issue by using the ‘NET USE’ cmd)
