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

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

相关推荐
m0_465215793 小时前
TCP & UDP Service Model
服务器·网络·tcp/ip
chian-ocean6 小时前
从理论到实践:Linux 进程替换与 exec 系列函数
linux·运维·服务器
敖行客 Allthinker6 小时前
从 UTC 日期时间字符串获取 Unix 时间戳:C 和 C++ 中的挑战与解决方案
linux·运维·服务器·c++
norsd8 小时前
MongoDb user自定义 role 添加 action(collStats, EstimateDocumentCount)
服务器·数据库·mongodb
_Eden_9 小时前
Keepalived高可用集群企业应用实例一
运维·服务器
画船听雨眠aa9 小时前
gitlab云服务器配置
服务器·git·elasticsearch·gitlab
s_little_monster11 小时前
【Linux】从硬件到软件了解进程
linux·运维·服务器·经验分享·笔记·学习·学习方法
hhmy12345611 小时前
表格结构标签
java·服务器·前端
慕雪华年15 小时前
【Linux】CentOS8虚拟机的基本环境配置
linux·运维·服务器
Allen_LVyingbo15 小时前
三甲医院大型生信服务器多配置方案剖析与应用(2024版)
运维·服务器·数据库