使用 PowerShell 遠程管理


要求

  1. PowerShell 版本要求至少是2.0版本以上,目前PowerShell 2.0 支持最低的操作系統版本為Windows XP。本次操作使用的是 PowerShell 5.1
  2. 請使用管理員身份操作PowerShell

服務端

Enable-PSRemoting

就是如此簡單。

客戶端

1. 設置服務端為可信主機,如果讀者的計算機與服務器在同一個域中,請忽略此步驟

Set-Item wsman:localhost\Client\TrustedHosts -value <IP或計算機名稱>

2. 連接服務端

如果讀者的計算機在域中,請將$User = "test"替換成$User = "domain\test"

$User = "test"
$PWord = ConvertTo-SecureString -String "test" -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord

Enter-PSSession -ComputerName 192.168.236.128 -Credential $Credential

至此連接完成

3. 斷開服務端

可選步驟,PowerShell 會"智能"識別讀者的行為,自動斷開連接。比如直接關閉PowerShell窗口的時候。

Exit-PSSession

4. 刪除TrustedHosts

全部清空:

CleSar-Item WSMan:\localhost\Client\TrustedHosts

指定刪除:
參考Github

Remove-TrustedHost.md https://github.com/BornToBeRoot/PowerShell

Remove-TrustedHost.ps1 https://github.com/BornToBeRoot/PowerShell

參考

遠程管理WinRM,Enter-PSSession
PowerTip: Use PowerShell to View Trusted Hosts
PowerShell - remove wsman trustedhosts value
PowerShell: Configure WinRM and enable PSRemoting
Get-Credential

聲明

本文采用知識共享署名-非商業性使用-相同方式共享 2.5 中國大陸許可協議進行許可,發表在CSDN (生活在底層的低級碼農)博客園 (低級碼農),歡迎讀者轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接!請讀者/爬蟲們尊重版權


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM