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

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

相关推荐
柳鲲鹏1 小时前
交叉编译:strip: Unable to recognise the format of the input file xx.c.o
linux·运维·服务器
Le1Yu1 小时前
微服务拆分以及注册中心
linux·运维·服务器
moxiaoran57532 小时前
nginx中proxy_pass配置
运维·服务器·nginx
weixin_379880922 小时前
.Net Core WebApi集成Swagger
java·服务器·.netcore
她说彩礼65万2 小时前
Asp.net core Kestrel服务器详解
服务器·后端·asp.net
ZLRRLZ3 小时前
【Linux操作系统】进程控制
linux·运维·服务器
qq762118224 小时前
Linux c 在内存中创建zip,最后写入测试
linux·运维·服务器
jayxuyj4 小时前
MySQL8.0新特性探秘深入解析窗口函数的性能优化策略
服务器
华纳云IDC服务商4 小时前
网站服务器频繁掉线的主要原因是什么
运维·服务器
小黄人软件4 小时前
【部署python网站】宝塔面板 小目标2:实时搜索网上资源文件网站放在服务器上 用AI做一个作品,不断迭代。
运维·服务器