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

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

相关推荐
gwjcloud28 分钟前
Frp内网穿透
linux·运维·服务器
bIo7lyA8v38 分钟前
如何用SSH访问远程服务器上的内网服务(如:MySQL、Redis、Kafka)?
服务器·mysql·ssh
小邓睡不饱耶1 小时前
花店花品信息管理系统开发实战:Python实现简易门店管理系统
服务器·python·microsoft
white-persist1 小时前
【vulhub weblogic CVE-2017-10271漏洞复现】vulhub weblogic CVE-2017-10271漏洞复现详细解析
java·运维·服务器·网络·数据库·算法·安全
TON_G-T2 小时前
useEffect为什么会触发死循环
java·服务器·前端
tHeya06II2 小时前
涵盖 Cursor、Claude Code、Skills
java·服务器
maosheng11463 小时前
Linux的第二次作业
linux·运维·服务器
maosheng11463 小时前
Linux
linux·运维·服务器
sR916Mecz3 小时前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
java·linux·服务器
0xDevNull4 小时前
Linux服务器日志查看完全指南
linux·运维·服务器