Skip to content

Instantly share code, notes, and snippets.

@MartinMiles
Last active July 25, 2019 16:29
Show Gist options
  • Save MartinMiles/32ec39117afb70dcfc58af831de0a0af to your computer and use it in GitHub Desktop.
Save MartinMiles/32ec39117afb70dcfc58af831de0a0af to your computer and use it in GitHub Desktop.
This copies a local file to the remote machine using PowerShell remote session with credentials provided
$pass = ConvertTo-SecureString -AsPlainText '123' -Force # 123 - actual password
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList 'Martin',$pass # Martin - actual username
$Session = New-PSSession -ComputerName 192.168.173.14 -Credential $Cred # IP address of remote machine
$remotePath = Invoke-Command -Session $session -ScriptBlock { New-Item -ItemType Directory -Force -Path Sifon } #Get-Location
Copy-Item -Path "c:\Some\Path\To\Local\Script.ps1" -Destination $remotePath.FullName -ToSession $session
Remove-PSSession $Session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment