Copy-Item Not Working in Powershell Script

I have a Powershell script that contains the lines [masked out actual directory and server name]:

Copy-item C:\ProgramData\dir1\dir2\abc_config.xml \\server2\c$\ProgramData\dir1\dir2\abc_config.xml -force -passThru
Copy-item C:\Users\All Users\dir1\dir2\abc_config.xml \\server2\c$\Users\All Users\dir1\dir2\abc_config.xml -force -passThru

Execution of the script in ISE will display the above lines, and the $? will return TRUE as if all went fine.  When I check server2, the file has not been updated.

Now, if I copy/paste the above lines in ISE, it works.  Server2 willl show the updated file.  It is the same account in ISE that I am using to run the script, and copy/paste the commmand.  Do I need to do something to get the script working?

May 22nd, 2015 1:21pm

Resolved my issue, had to issue Set-ExecutionPolicy Unrestricted
Free Windows Admin Tool Kit Click here and download it now
May 22nd, 2015 1:33pm

You may also want to put single quotes around your source and destination paths, in the second command, since there's a space in the path (All Users).
  • Proposed as answer by jrv 12 hours 0 minutes ago
May 22nd, 2015 1:38pm

Resolved my issue, had to issue Set-ExecutionPolicy Unrestricted
Free Windows Admin Tool Kit Click here and download it now
May 22nd, 2015 5:26pm

You may also want to put single quotes around your source and destination paths, in the second command, since there's a space in the path (All Users).
  • Proposed as answer by jrv Friday, May 22, 2015 7:08 PM
May 22nd, 2015 5:30pm

You may also want to put single quotes around your source and destination paths, in the second command, since there's a space in the path (All Users).
Free Windows Admin Tool Kit Click here and download it now
May 22nd, 2015 5:30pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics