0
votes

I am copying an .MSI file to a remote PC. The copy-item is not retaining the filename or extension at the remote destination. I thought copy-item would copy the file as is?

The script:

net use Q: \\remotePC\C$\Temp /user:USERID PSWD
copy-item C:\TEMP\installation.msi -Destination Q:\Temp
dir Q:\
net use Q: /delete

What the destination directory contains after the copy, a file called "Temp" with no extension.

    Directory: Q:\


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---          8/8/2012   3:57 PM   18900480 Temp

If I try to literally specify the filename in the destination of the copy-item cmd I get the following error:

net use Q: \\remotePC\C$\Temp /user:USERID PSWD
copy-item C:\TEMP\installation.msi -Destination Q:\Temp\installation.msi
dir Q:\
net use Q: /delete

Error:

Copy-Item : Could not find a part of the path 'Q:\Temp\installation.msi'.
At P:\Powershell\CopyInstallFile\copyinstall.ps1:10 char:10
+ copy-item <<<<  C:\TEMP\installation.msi -Destination Q:\Temp\installation.msi
    + CategoryInfo          : NotSpecified: (:) [Copy-Item], DirectoryNotFound
   Exception
    + FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,Microsoft.P
   owerShell.Commands.CopyItemCommand

================================================================ EDIT - If I specify the full network path it copies the file correctly. Apparently the copy-item doesn't like to use drives created by net use

copy-item C:\TEMP\installation.msi \\remotePC\C$\Temp
2

2 Answers

2
votes

You've mapped Q: to the c:\Temp folder on the other machine. That means that Q:\ points to the temp directory already. Just just copy to Q:\ instead of Q:\Temp and it should work.

copy-item C:\TEMP\installation.msi -Destination Q:\
1
votes

It looks like Q:\Temp doesn't exist. Try creating the the Temp folder first, then copy the file.