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: Convert Between Various SSL Certificate Formats

# Install Choco (look for instructions in this blog)# Install openssl.lightchoco install openssl.light -y #…

PowerShell: Check Servers on Domain to Locate A Domain Account Being Set to Run Services and Scheduled Tasks

# Obtain the name of the default domain Administrator account (this account is expected to…

Docker DRUPAL Container

# Preseed drupal files with persitent storagemkdir /var/www/html/kimconnect/{modules,profiles,sites,themes}docker run --rm drupal tar -cC /var/www/html/sites .…