跨服务器执行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";}

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

相关推荐
树℡独8 小时前
ns-3仿真之应用层(五)
服务器·网络·tcp/ip·ns3
a41324479 小时前
ubuntu 25 安装vllm
linux·服务器·ubuntu·vllm
Configure-Handler9 小时前
buildroot System configuration
java·服务器·数据库
津津有味道9 小时前
易语言TCP服务端接收刷卡数据并向客户端读卡器发送指令
服务器·网络协议·tcp·易语言
Fᴏʀ ʏ꯭ᴏ꯭ᴜ꯭.10 小时前
Keepalived VIP迁移邮件告警配置指南
运维·服务器·笔记
Genie cloud10 小时前
1Panel SSL证书申请完整教程
服务器·网络协议·云计算·ssl
!chen11 小时前
linux服务器静默安装Oracle26ai
linux·运维·服务器
莫大33011 小时前
2核2G云服务器PHP8.5+MySQL9.0+Nginx(LNMP)安装WordPress网站详细教程
运维·服务器·nginx
2501_9277730712 小时前
imx6驱动
linux·运维·服务器
hy____12312 小时前
Linux_进程间通信
linux·运维·服务器