差異處
這裏顯示兩個版本的差異處。
下次修改 | 前次修改 | ||
powershell:remotesetting [2014/08/28 16:27] tony 建立 |
powershell:remotesetting [2023/06/25 09:48] (目前版本) |
||
---|---|---|---|
行 3: | 行 3: | ||
===== How to? ====== | ===== How to? ====== | ||
==== Create PS Session ==== | ==== Create PS Session ==== | ||
+ | 對要管理的機器執行以下指令進行連線: | ||
<code> | <code> | ||
Enter-PSSession -ComputerName COMPUTER -Credential USER | Enter-PSSession -ComputerName COMPUTER -Credential USER | ||
</code> | </code> | ||
+ | 如下圖,發現連線有錯誤。我們必須去設定WinRM服務,包含Client與Server:\\ | ||
{{:powershell:pssession_failed.png?600|}}\\ | {{:powershell:pssession_failed.png?600|}}\\ | ||
+ | \\ | ||
+ | 於是接著在Client與Server中輸入以下指令去啟動要遠端管理的相關服務: | ||
+ | <code> | ||
+ | Enable-PSRemoting -Force | ||
+ | </code> | ||
+ | 執行中有錯誤,似乎是網路型態的關係:\\ | ||
{{:powershell:enable_psremote_failed.png?600|}}\\ | {{:powershell:enable_psremote_failed.png?600|}}\\ | ||
+ | \\ | ||
+ | 接著我將網路型態修改為家用網路,再執行一次就會成功:\\ | ||
{{:powershell:psshell_network_type.png?500|}}\\ | {{:powershell:psshell_network_type.png?500|}}\\ | ||
- | {{:powershell:psshell_change_auth.png?500|}} | + | \\ |
+ | 最後是設定權限並重啟WinRM服務:\\ | ||
+ | <code> | ||
+ | Set-Item wsman:\localhost\client\trustedhosts * | ||
+ | Restart-Service WinRM | ||
+ | </code> | ||
+ | {{:powershell:psshell_change_auth.png?500|}}\\ | ||
+ | \\ | ||
+ | 最後終於連線成功:\\ | ||
+ | {{:powershell:psshell_connect_success.png?500|}}\\ | ||
+ | 可以輸入exit離開。\\ | ||
+ | \\ | ||
+ | 友藏內心獨白: 都那該死的RDP才讓我開始用PowerShell。 | ||
===== Reference ====== | ===== Reference ====== | ||
* [[http://www.howtogeek.com/117192/how-to-run-powershell-commands-on-remote-computers/|How to run powershell commands on remote computers?]] | * [[http://www.howtogeek.com/117192/how-to-run-powershell-commands-on-remote-computers/|How to run powershell commands on remote computers?]] |