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

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

相关推荐
2301_794333911 小时前
实验室服务器配置|通过Docker实现Linux系统多用户隔离与安全防控
linux·服务器·docker·实验室
荣光波比2 小时前
Nginx 实战系列(一)—— Web 核心概念、HTTP/HTTPS协议 与 Nginx 安装
linux·运维·服务器·nginx·云计算
武文斌772 小时前
单片机:DS18B20测温度、74HC595扩展芯片、8*8LED矩阵
运维·服务器·单片机·嵌入式硬件
阿sir1983 小时前
ZYNQ 自定义IP
服务器·网络·tcp/ip
工藤新一¹6 小时前
Linux —— 虚拟进程地址空间
linux·运维·服务器·c/c++·虚拟进程地址空间
再难也得平7 小时前
Linux初级篇
linux·运维·服务器
attitude.x8 小时前
Swift 协议扩展与泛型:构建灵活、可维护的代码的艺术
运维·服务器·网络
专注VB编程开发20年8 小时前
rust语言-对象多级访问
服务器·前端·rust
shylyly_8 小时前
Linux->日志的实现
linux·运维·服务器
m0_749299958 小时前
Nginx主配置文件
java·服务器·nginx