I am needing to perform a robocopy to move user accounts home directories in a powershell form. I got it working but it pauses the form until the copy is finished. My desired outcome would be to have the script kickoff the robocopy in the background on the remote server and release the powershell form so we can continue to perform other tasks in the form while the copy is in progress. I do not need any job information on the copy either.
I have enabled WINRM on all our services via GPO and that is working well.
My first try at the background script was the following:
$credential = Get-Credential
$sesh = new-pssession -computername $server -credential $credential -authentication Credssp
$scriptblock = $ExecutionContext.InvokeCommand.NewScriptBlock("robocopy /e /move $oldhomedir $newhomedir")
invoke-command -session $sesh -scriptblock $scriptblock -AsJob
Remove-pssession $sesh
#----------------------------------------------
This unfortunately copies the first file and stops. I believe the pssession is being cancelled before the copy can complete.
I tried the next script and its doing nothing. Any pointers? It won't let me add -Authentication Credssp on the invoke-wmimethod command. I'm guessing authentication is failing.
$credential = Get-Credential
$server = serverA.domain.local
$oldhomedir = serverA.domain.local\home\folderA
$newhomedir = serverB.domain.local\home\folderB
(Invoke-WmiMethod Win32_Process Create "robocopy.exe /e /move $oldhomedir $newhomedir" -computername $server -credential $credential).ReturnValue -eq 0
Remove PSSession $sesh
#--------------------------------
I appreciate any help!