Posted On May 26, 2020

PowerShell: Inter-Domain SMB Shares Mounting

kimconnect 0 comments
blog.KimConnect.com >> Codes >> 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.

$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 $_
    }

Leave a Reply

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

Related Post

“Simon” Piano Game JavaScript Code

Demo: https://blog.kimconnect.com/wp-content/projects/pianogame.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head>…

Basic HTML and HTML5: Make Dead Links Using the Hash Symbol

<h2>CatPhotoApp</h2><main> <p>Click here to view more <a href="http://freecatphotoapp.com" target="_blank">cat photos</a>.</p> <img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange…

Notable Features of C#

This language is part of the .NET framework that can be used to build applications…