# interDomainFileCopy.ps1
# Note: this is a quick and dirty method. Password security must be handled to substitute the $plainTextPassword variable.
$computerName="SOMESERVER"
$username="RAMBO"
$plainTextPassword="whatpassword?"
$driveLetter="x:"
try{
# wrap powershell around the venerable command 'net use' that is more reliable than the New-PSDrive cmdlet
invoke-expression "net use $driveLetter '\\$computername\$shareName' /user:$userName '$plainTextPassword' /persistent:Yes" -ea Stop
# only proceeds if there're no errors in the previous command
robocopy '$driveLetter\' c:\backups\$computername /E /R:0 /NP
# optional: remove the mount when done
# net use x: /delete
}
catch{
throw $_
}
Categories: