Skip to content

Instantly share code, notes, and snippets.

@bradymholt
Created March 6, 2015 01:48
Show Gist options
  • Save bradymholt/77989d60cc212b01752c to your computer and use it in GitHub Desktop.
Save bradymholt/77989d60cc212b01752c to your computer and use it in GitHub Desktop.
Copies a directory remotely, from the context of the remote machine to prevent bumerang style copy
param ($computerName, $username, $password, $sourceDirectory, $targetDirectory)
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PsCredential($username, $securePassword)
Invoke-Command -ComputerName $computerName -Credential $credentials -ScriptBlock { Copy-Item $args[0] $args[1] -recurse } -ArgumentList $sourceDirectory,$targetDirectory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment