使用 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

全部清空:

Clear-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 (生活在底层的低级码农)博客园 (低级码农),欢迎读者转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接!请读者/爬虫们尊重版权

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值