OpsaC - Operating as PowerShell code
published: September 15, 2017 author: Tinu tags: Remote Commands categories: PowerShell
Mit PowerShell-Remoting muss nicht mehr über das Clipboard von einem Host zum anderen kopiert werden.
Als erstes muss der Remote-Host lokal in die TrustedHosts aufgenommen werden:
Set-Item WSMan:\localhost\Client\TrustedHosts -Value '192.168.1.1' -Force
Get-Item WSMan:\localhost\Client\TrustedHosts
Danach kann eine PSSession zum Remote-Host erstellt werden:
$remoteHost = New-PSSession -ComputerName '192.168.1.1'
$remoteHost | Format-List *
Mit dem Parameter FromSession kann vom Remote-Host zum lokalen Host kopiert werden:
Copy-Item -FromSession $remoteHost "D:\Work\DSC\RemoteHost" -Recurse -Destination 'C:\Work\'
Mit dem Parameter ToSession kann vom lokalen Host zum Remote-Host kopiert werden:
Copy-Item -ToSession $remoteHost "C:\Work\RemoteHost" -Recurse -Destination 'D:\Work\'
Die TrustedHosts-Liste am Ende wieder leeren:
Clear-Item WSMan:\localhost\Client\TrustedHosts -Force
Get-Item WSMan:\localhost\Client\TrustedHosts