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

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

相关推荐
jinxinyuuuus2 分钟前
局域网文件传输:P2P架构中的带宽测量与高效率文件分块传输
服务器·架构·p2p
Evan芙3 分钟前
Rocky Linux 9 双网卡 bond0 绑定
linux·服务器·网络
『 时光荏苒 』11 分钟前
生产服务器log日志文件很多-精准查询问题
运维·服务器·生产服务器问题查询·日志过滤
Arva .16 分钟前
谈谈 HTTP 的缓存机制,服务器如何判断缓存是否过期?
服务器·http·缓存
咕噜签名-铁蛋19 分钟前
物理服务器和云服务器区别
运维·服务器
咕噜签名-铁蛋20 分钟前
如何挑选服务器
运维·服务器
麦麦鸡腿堡21 分钟前
Java_网络上传文件与netstat指令
java·服务器·网络
TangGeeA28 分钟前
Linux CFS(完全公平调度器)全面总结
java·linux·服务器
灵魂学者29 分钟前
Vue3.x —— router 路由配置
服务器·前端·vue.js·路由
列逍30 分钟前
操作系统初识:从硬件架构到核心原理
运维·服务器·操作系统·硬件架构