Powershell New-PSDrive from remote computer

Powershell New-PSDrive from remote computer

I'm here again with one more question.

As stated here, I sucessfully connected two servers to copy a lot of files. But the copy won't worked at all. It returns a lot of errors on files and folders wich already exist on destination server.

What I did was create a PSSession as described on the given link above. I can sucessfully see the files from source server with Invoke-Command -ScriptBlock { Get-ChildItem -Path "d:\" } -Session $source_server. Then, started the copy with:

copy-item -path "d:\folder_on_source_server\*" -destination "d:\folder_on_destination_server" -FromSession $source_server -recurse -exclude "*dfsrprivate*",".dropbox.cache"

Source and destination folder names are the same. In fact, both servers have same folder structure. But, as stated, I received a lot of errors on files and folders already present on destination. And I mean A LOT. Only new files was copied, updated files don't. I know -force option will work, but it will copy everything again.

My aim now is to copy all new AND updated files from source, but copy-item don't have such function. So, I tried use robocopy. The problem is I don't know how to tell robocopy to use the remote server folder as source. I know robocopy can use UNC paths, but I don't have ideas to parse the remote UNC path to it. Something like robocopy remote_source_folder local_destination_folder /mir and setting up exclusions.

I tried to create a PSDrive, but is created on source server only. Local robocopy can't see it: Invoke-Command -session $vms -ScriptBlock { New-PSDrive -name "S" -PSProvider "FileSystem" -Root "\remote_server_ip\d$" }. If I remove -session, the drive is created somewhere wich I don't know .

I tried also some other commands like net use, created a variable with get-childitem on source, and others, all with and without invoke-command and with and without -session, but none worked.

So, can you help me to get these files? I think is a simple thing, but i'm not seeing it. Also, if you can point me a way to start the pssession without have to type user and password, will be nice.

Thanks in advice!

관련 정보