Author Posts

January 1, 2012 at 12:00 am

by willbs at 2013-03-01 14:18:58

with ps v3, i am trying to copy folders and files from my machine to a remote machine, here is my code:

$move = Get-ChildItem -Path 'C:\Music' -Recurse
invoke-command -scriptblock {Copy-Item $local:move -Destination C:\MusicFiles} -Argumentlist $move -computername $global:uutName -credential $global:Credential

i get this error

Cannot bind argument to parameter 'Path' because it is null.
+ CategoryInfo : InvalidData: (:) [Copy-Item], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CopyItemCommand
+ PSComputerName : 192.168.0.102

thanks in advance

by DonJ at 2013-03-01 15:08:52

Yeah, that won't work. You're asking the remote machine to do the copying FROM your computer. You're giving it paths that are valid on YOUR computer – starting with C:\Music. But the remote machine won't know what that path means. As a note, Get-ChildItem isn't getting the *files* – it's getting *directory entries* that represent the files. Passing those to the remote computer is not copying the files themselves.

There's no need to use remoting for this.

Copy C:\Music\*.* \\Destination\C$\MusicFiles

Or something like that. You need to use a UNC path to do this, just like if you were copying with Explorer. Or a mapped drive (which points to a UNC anyway).

by willbs at 2013-03-01 15:43:10

really, there isn't a way to do this with powershell?

by DonJ at 2013-03-01 15:50:02

LOL... I didn't say that. The Copy command I used is an alias for Copy-Item. It works pretty much the way the old-school Copy command worked. It's pure PowerShell, though.

There isn't a way to do this with *remoting*. Invoke-Command is designed to send commands to remote computers, not to act as a file copy channel.

by willbs at 2013-03-01 16:06:06

i tried this, using the name

Copy C:\Music\*.* \\stg-53\C$\MusicFiles

and got this error

Copy : Access is denied
At line:1 char:1
+ Copy C:\Music\*.* \\stg-53\C$\MusicFiles
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Copy-Item], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.CopyItemCommand

i tried this, using the IP address

Copy C:\Music\*.* \\192.168.0.102\C$\MusicFiles

and got this, same error, different name

Copy : Access is denied
At line:1 char:1
+ Copy C:\Music\*.* \\192.168.0.102\C$\MusicFiles
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Copy-Item], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.CopyItemCommand

by DonJ at 2013-03-01 16:15:10

Well, then access is denied :). The C$ usually requires that you be an Administrator on the remote computer – no different than if you accessed in through Windows Explorer. If the PowerShell window's title bar doesn't say "Administrator" then you did not open the shell with Administrator privileges.

Do me a favor – try to copy just one file from your machine to the other machine, using Windows Explorer. Keep track of how you do that. If you can do it with Explorer, you can do the rest in PowerShell.

That said... are there a LOT of files? Are they BIG? If so, Robocopy might be a better approach. It can survive hiccups and whatnot and resume the operation. A lot more robost (hence the name).

by willbs at 2013-03-04 09:45:09

i went through the network, saw the uut and accessable folders

i was able to get it to work, my code looks like this

Copy-Item C:\Music\* -Destination \\stg-53\Documents -Recurse

this copies all of the folders (and subfolders) and their files in the music folder on the local machine (about 6.5 Gbytes) to the UUT, stg-53, D: drive, Documents folder

now the issue is to try to make it more robust, maybe go out and sense which folder i have acces to

any ideas, i have been playing with the get-children command

thanks for your help so far