Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save junecastillote/b9b776315bf69081c5650f31175b2bc7 to your computer and use it in GitHub Desktop.
Save junecastillote/b9b776315bf69081c5650f31175b2bc7 to your computer and use it in GitHub Desktop.
#REGION VARIABLES
#// username (domain\username)
$uname = "domain\user"
#password - plain text
$passwd = "p@ssw0rd"
#// remote computer where the files to be copied are hosted
$remoteSourceComputer = "server01"
#// source folder from the remote computer (DO NOT USE UNC PATH)
$remoteSourceFolder = "C:\SourceFolder"
#// destination folder on the local machine
$localDestinationFolder = "C:\DestinationFolder"
#ENDREGION
$secpasswd = ConvertTo-SecureString "$passwd" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($uname, $secpasswd)
$Session = New-PSSession -ComputerName $remoteSourceComputer -Credential $credential
Copy-Item -Path $remoteSourceFolder\*.* -FromSession $Session -Destination $localDestinationFolder -Confirm:$false -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment