本机和远程机都要执行
Enable-PSRemoting -Force
远程端关闭公用网络
Get-NetConnectionProfile
Set-NetConnectionProfile -Name "未识别的网络" -NetworkCategory Private
本机和远程机都要执行
winrm quickconfig
将远程机ip加入信任列表
cd WSMan::localhost\Client
Get-ChildItem
Set-Item .\TrustedHosts -value "192.168.1.1,192.168.1.2,192.168.1.3"
配置完毕,在本机编写脚本在远程执行
$UserName = 'Administrator'
$Password = '123'
$Pass = ConvertTo-SecureString $Password -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList UserName,Pass
$Server="192.168.1.1"
invoke-command -Credential $Credential -ComputerName $Server -ScriptBlock{set-location d:\;new-item -type File 123.txt -value "this is remove value";}
如有多个服务器需要维护,可减少远程桌面操作次数。