跨服务器执行PowerShell脚本

本机和远程机都要执行

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";}

如有多个服务器需要维护,可减少远程桌面操作次数。

相关推荐
不能跑的代码不是好代码7 小时前
Linux系统常用命令中文速查表
linux·运维·服务器
石一峰6998 小时前
深入理解 Linux 中断三层机制与 1-Wire 时序锁原理
linux·运维·服务器
无限码农8 小时前
Linux上通过cmake编译uchardet
linux·运维·服务器
ACP广源盛1392462567310 小时前
IX8024@ACP# 搭配此芯 AI 服务器 + 爱芯元智产品完整方案
大数据·运维·服务器·人工智能·分布式·嵌入式硬件
Hiyajo pray11 小时前
SDN 访问控制性能调优方法
服务器·网络·网络安全
huainingning13 小时前
交换机通过ftp下载文件或者传输文件到ftp服务器
运维·服务器·网络
小池先生14 小时前
Windows服务器如何备份
运维·服务器
运维大师15 小时前
【Linux运维极简教程】05-软件包管理
linux·运维·服务器
sramdram16 小时前
数字温度传感器应用于服务器系统热管理方案的优势
服务器·温度传感器·数字温度传感器
hehelm16 小时前
IO 多路复用 — Reactor
linux·服务器·网络·数据库·c++