# Backup directory on unauthorized remote share

**URL:** <https://forum.ansible.com/t/backup-directory-on-unauthorized-remote-share/21664>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [June 3, 2016, 10:26pm UTC](https://forum.ansible.com/t/backup-directory-on-unauthorized-remote-share/21664 "2016-06-03T22:26:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [June 3, 2016, 10:26pm UTC](https://forum.ansible.com/t/backup-directory-on-unauthorized-remote-share/21664/1 "2016-06-03T22:26:25Z")

</div>

Control Node:

- CentOS 7

- Ansible 2.1

- pywinrm version from May 19th, 2016

Remote Node:

- Windows 7

- Powershell 3  
I have to make a copy of directory on a share to another location on that same share. The account I use for connecting does not have access to the share so I am trying to use the rights of another account namely ADS-6999. I wrote the following powershell script which works perfectly.

#copies contents of a share directory to another share directory  
$uncServer=“\10.1.123.123”  
$uncSrc=“\shareName$\dir1\dir2\dir3”  
$uncDest=“\shareName$\dir4\6999”  
$userName=“ADS-6999”  
$password=“p@ssw0rd”  
$uncFullSrc = “$uncServer$uncSrc”  
$uncFullDest = “$uncServer$uncDest”  
net use $uncServer $password /USER:$userName  
Copy-Item $uncFullSrc $uncFullDest -Recurse  
net use $uncServer /delete

So I modified the script above to be called from ansible on the control node and saved it as "copyShare2Share.ps1 shown below:

#copies contents of a share directory to another share directory  
param(  
[string]$uncServer,  
[string]$uncSrc,  
[string]$uncDest,  
[string]$userName,  
[string]$password  
)  
$uncFullSrc = “$uncServer$uncSrc”  
$uncFullDest = “$uncServer$uncDest”  
net use $uncServer $password /USER:$userName  
Copy-Item $uncFullSrc $uncFullDest -Recurse  
net use $uncServer /delete

And I call the script from my ansible playbook as follows:

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [June 6, 2016, 5:30pm UTC](https://forum.ansible.com/t/backup-directory-on-unauthorized-remote-share/21664/2 "2016-06-06T17:30:59Z")

</div>

SOLVED!! Apparently it didn’t like the following lines

$uncFullSrc = “$uncServer$uncSrc”  
$uncFullDest = “$uncServer$uncDest”

because it finally worked after I changed them to

$uncFullSrc = $uncServer + $uncSrc  
$uncFullDest = $uncServer + $uncDest

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [June 6, 2016, 6:12pm UTC](https://forum.ansible.com/t/backup-directory-on-unauthorized-remote-share/21664/3 "2016-06-06T18:12:37Z")

</div>

Oh, and I changed “userName” to “domain\userName”
