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

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

相关推荐
张太行_5 小时前
Linux静态库:多模块高效管理
linux·运维·服务器
ID_180079054735 小时前
YouTube item_get_video接口认证方式:API密钥与OAuth2.0的选择与应用
服务器·windows·microsoft
wgl6665205 小时前
Linux---基础IO!
linux·运维·服务器
Ancelin安心6 小时前
kali-dirsearch的使用
linux·运维·服务器·python·计算机网络·web安全·网络安全
jun_bai6 小时前
python+Java的网盘程序升级版。无感知备份文档,保护数据资产利器。
运维·服务器
上海云盾-高防顾问6 小时前
筑牢网络防线:境外恶意网址与IP防范指南
服务器·网络·安全
weixin_516023078 小时前
VESTA在Linux下的安装
linux·运维·服务器
热心市民R先生8 小时前
IGH EtherCAT 主站核心文件体系全解析:构成、区别与运维实践
运维·服务器·网络
耶耶耶耶耶~9 小时前
arch linux 安装
linux·运维·服务器
ashcn20019 小时前
linux 制作一个自解压文件
linux·运维·服务器