PowerShell: Inter-Domain SMB Shares Mounting

# interDomainFileCopy.ps1
# Note: this is a quick and dirty method. Password security must be handled to substitute the $plainTextPassword variable.


    # 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
    throw $_

Leave a Reply

Your email address will not be published. Required fields are marked *