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: Function to Execute Function Remotely

Function this function that - this quick snippet is to invoke those func things remotely...…

PowerShell: Export Event Logs by a Certain Date Range

# User defined variables $daysLimit=7 $startdate=(get-date).adddays(-$daysLimit) $computername=$env:computername $logName='Application' $filterTypes='Error','Warning' $logPath="c:\temp\eventlogs-from-$($startdate.tostring('yyyy-MM-dd'))-to-$((get-date).tostring('yyyy-MM-dd')).csv" # Get the event logs…

PowerShell: Invoke CRM Services Maintenance

Version 4: # invokeCrmServersMaintenance.ps1 # Version 0.0.4 # This script is a processes watcher on…