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

PowerShell: Create A Shortcut on Everyone’s Desktop

Following is an example of a 'how to create a log-off button on Everyone's desktop'.…

Recommended Skill Set of a Programmer

It's a given that a coder needs to learn how to code... like really well.…

Quick 1-liner: get system model number

# the 1-linerwmic computersystem get model,name,manufacturer,systemtype# Get RAM DIMM Slotswmic memorychip get Capacity /format:list