Goodness me, I didn't think the act of copying a file was the part of the script I would be debugging!
I'm having a really bizarre issue with Copy-Item. Basically, I have a config file I need to move into Program Files.
Here's my command:
Copy-Item -Path "C:\install\app.exe.config" -Destination "$ProgamFiles\MyApp\bin"
$ProgamFiles will expand in C:\Program Files or C:\Program Files (x86) depending on 32 or 64-bit Windows. However, in both scripts, or simply writing this in Powershell as a solo command, with either using $ProgamFiles or just full out typing C:\Program
Files (x86), app.exe.config becomes a file called bin in the MyApp folder. I must admit I have not tested if I have this issue on 32-bit Windows where the path would be C:\Program Files as right now this will be run on Windows 64-bit 99% of the time.
An example of the dir command looks like this after a copy Item in the MyApp folder:
<DIR> .<DIR> ..<DIR> bin
16 bin<DIR> Assets
And the file called bin has the contents of my old app.exe.config
So, okay, it wants to make a file with the last thing in the Destination string, so I try this:
Copy-Item -Path "C:\install\app.exe.config" -Destination "$ProgamFiles\MyApp\bin\app.exe.config"
But I get the filename, Directory Name, or volume name syntax is incorrect.
So yeah, I'm really scratching my head on this one. I thought maybe the brackets in (x86) might be throwing it off, but escaping them with ` didn't help. I got the exact same outcome. And I have a Test-Path command that looks for something in Program Files
(x86) without issue. It also can't be a permissions issue, because I AM getting a file written to the destination, and the PowerShell is running as administrator. Any thoughts as to why I'm getting this output instead of what I really want?