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

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

相关推荐
Lucis__22 分钟前
Linux进程间通信IPC:从管道到共享内存的发展演进
linux·运维·服务器
不想看见4041 小时前
Qt 框架中的信号与槽机制【详解】
服务器·数据库·qt
无籽西瓜a1 小时前
TCP三次握手与四次挥手详解含图解
java·服务器·网络·tcp/ip
千里马-horse1 小时前
Linux 系统中安装 ktlint
linux·运维·服务器
feng_you_ying_li1 小时前
linux攻略计划启动,首先是linux的基本介绍(1)
linux·运维·服务器
不知名。。。。。。。。1 小时前
仿muduo库实现高并发服务器---HttpContext上下文类实现
运维·服务器
从零点1 小时前
ubuntu网络没有WiFi怎么办?网络配置解决步骤
linux·服务器·网络
计算机与认知1 小时前
Linux Device Link机制
java·linux·服务器
Barkamin1 小时前
网络编程套接字
运维·服务器·网络
原来是猿1 小时前
Linux-【ELF文件】
linux·运维·服务器