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

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

相关推荐
不会写DN7 分钟前
处理 TCP 流中的消息分片
服务器·网络·tcp/ip
木下~learning17 分钟前
Linux 驱动:RK3399 从零手写 GT911 电容触摸屏驱动(完整可运行)
linux·运维·服务器
叫我刘同学30 分钟前
腾讯云 Ubuntu 服务器部署 Hermes Agent 详细安装教程
服务器·ubuntu·腾讯云
wanhengidc1 小时前
流量清洗的作用是什么?
运维·服务器·网络·安全·web安全·智能手机
@LuckY BoY1 小时前
Linux Mint 上开启 VNC 远程桌面
linux·运维·服务器
ywgcsxue1 小时前
在麒麟V10上源码编译安装Nginx
linux·运维·服务器·nginx
满天星83035772 小时前
【MySQL】索引
linux·服务器·数据库·mysql
T0uken2 小时前
【Linux】耗时任务执行并邮件通知
linux·运维·服务器
网络安全许木3 小时前
自学渗透测试第16天(Linux文本处理进阶)
linux·运维·服务器·网络安全·渗透测试
路由侠内网穿透3 小时前
本地部署开源发票管理系统 Invoice Ninja 并实现外部访问
运维·服务器·数据库·物联网·开源