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

Window Update Via PowerShell

Set Proxy netsh winhttp set proxy proxy-server="hqproxy:80" bypass-list="*.kimconnect.com;192.168.*.*;"[Microsoft.Win32.Registry]::SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU","UseWUServer",0,[Microsoft.Win32.RegistryValueKind]::DWord)restart-service wuauserv Enable Windows Update Repository: Set-ExecutionPolicy RemoteSigned…

PowerShell: Special Parameter datatype [switch]

# Demo of a simple function to turn lights on and offfunction setLight{ param( [switch]$on,…

Kubernetes Container Deployment with NFS Persistent Volumes

Introduction: Update: we have provided a practical application of the knowledge conveyed in this article…