locked
Copy-Item Not Working in Powershell Script RRS feed

  • Question

  • 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?

    Friday, May 22, 2015 5:13 PM

Answers

  • Resolved my issue, had to issue Set-ExecutionPolicy Unrestricted
    • Marked as answer by AnnaWY Tuesday, May 26, 2015 8:06 AM
    Friday, May 22, 2015 5:26 PM
  • 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
    • Marked as answer by AnnaWY Tuesday, May 26, 2015 8:06 AM
    Friday, May 22, 2015 5:30 PM

All replies

  • Resolved my issue, had to issue Set-ExecutionPolicy Unrestricted
    • Marked as answer by AnnaWY Tuesday, May 26, 2015 8:06 AM
    Friday, May 22, 2015 5:26 PM
  • 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
    • Marked as answer by AnnaWY Tuesday, May 26, 2015 8:06 AM
    Friday, May 22, 2015 5:30 PM