From 90c7c092e13c568d12dba0892168bee5352d45b9 Mon Sep 17 00:00:00 2001 From: RealStickman Date: Fri, 13 Nov 2020 11:59:25 +0100 Subject: [PATCH] Add notes on remoting --- .../programming/powershell-scripting.md | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/arch-config/Dokumente/programming/powershell-scripting.md b/arch-config/Dokumente/programming/powershell-scripting.md index 3b27194b..057ef3ba 100644 --- a/arch-config/Dokumente/programming/powershell-scripting.md +++ b/arch-config/Dokumente/programming/powershell-scripting.md @@ -12,3 +12,54 @@ Use PowerShell ISE to develop PowerShell scripts | -ge | greater or equals to | | -lt | less than | | -le | less or equals to | + +## Remoting + +### Allow recieving remote commands +Run as Administrator +IMPORTANT: Network must not be set to public +``` +Enable-PSRemoting +``` + +### Add to trusted list +Clients have to be added to the trusted list if there are no other authentication methods used. +Multiple clients can be added when separated by commas. +*Note: The command below overwrites every other value set in "trustedhosts".* +``` +Set-Item WSMan:localhost\client\trustedhosts -value '(ip address/hostname)' +``` + +Example: +``` +Set-Item WSMan:localhost\client\trustedhosts -value '192.168.1.117,win10-2-lin,192.168.1.118,win10-3-lin' +``` + +### Run command on multiple remote pcs + +``` +Invoke-Command -ComputerName (pc1), (pc2) -ScriptBlock {(command)} +``` + +``` +Invoke-Command -ComputerName (pc1), (pc2) -ScriptBlock {(command1) +(command2)} +``` + +Example for issuing multiple commands after each other: +">>" is added automatically on newline +``` +Invoke-Command -ComputerName win10-2-lin, win10-3-lin -ScriptBlock {cd c:\Users\admin +>> New-Item "test.txt" -ItemType File} +``` + +### Run script on multiple remote pcs + +``` +Invoke-Command -ComputerName (pc1), (pc2) -FilePath 'path\to\script' +``` + + + + +