Backup directory on unauthorized remote share

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:

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

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