跨平台PowerShell如何远程管理Linux/Mac/Windows?

简介: 跨平台PowerShell如何远程管理Linux/Mac/Windows?首先,在要管理的机器上安装跨平台PowerShell:https://github.


跨平台PowerShell如何远程管理Linux/Mac/Windows?


首先,在要管理的机器上安装跨平台PowerShell:https://github.com/PowerShell/PowerShell/releases

如何安装呢?看Instructions:

Platform Downloads How to Install
Windows 10 / Server 2016 .msi Instructions
Windows 8.1 / Server 2012 R2 .msi Instructions
Ubuntu 16.04 .deb Instructions
Ubuntu 14.04 .deb Instructions
CentOS 7 .rpm Instructions
OS X 10.11 .pkg Instructions
Docker   Instructions

然后,安装OMI和PSRP:

OMI:https://github.com/Microsoft/omi

PSRP:https://github.com/PowerShell/psl-omi-provider

Platform Releases Link
Linux Debian psrp-1.0.0-0.universal.x64.deb
Linux RPM psrp-1.0.0-0.universal.x64.rpm

最后,在windows端运行下列命令来管理Linux/Mac/Windows机器:

$User = "root"
$PWord = convertto-securestring "密码" -asplaintext -force
$cred = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $PWord
$mySession = New-PSSession  -ComputerName 机器名 -Credential $cred -Authentication basic -UseSSL -SessionOption (New-PSSessionOption -SkipCACheck -SkipRevocationCheck -SkipCNCheck)
Invoke-Command -Session $mySession {Get-Host} 

如果你想把本地的脚本在被管理的机器上运行:

$script1='get-host';
$path1='/root/test.ps1';
Invoke-Command -Session $mySession {echo $args[0]>$args[1];. $args[1]} -Args $script1,$path1

读取本地的文件,然后在被管理的机器上运行:

$script1 = Get-Content "d:\test.txt"
$path1='/root/test.ps1';
Invoke-Command -Session $mySession {echo $args[0]>$args[1];. $args[1]} -Args $script1,$path1


目录
相关文章
|
1月前
|
Linux Shell Windows
通过Linux挂载Windows端NFS服务实现板端Linux传输文件到PC
通过Linux挂载Windows端NFS服务实现板端Linux传输文件到PC
|
4天前
|
SQL 监控 安全
Linux&Windows 日志分析 陇剑杯 CTF
Linux&Windows 日志分析 陇剑杯 CTF
29 0
|
7天前
|
Linux Windows
Windows、Mac、Linux解决端口被占用的问题
Windows、Mac、Linux解决端口被占用的问题
8 1
|
14天前
|
安全 Ubuntu Linux
Linux远程访问Windows实现步骤
在Windows上启用远程桌面连接并获取IP地址后,Linux用户需安装SSH客户端( Debian系:`sudo apt-get update; sudo apt-get install openssh-client`,RPM系:`sudo yum install openssh-clients`)。然后使用命令`ssh 用户名@Windows_IP地址`连接,其中`用户名`和`Windows_IP地址`按实际情况填写。
14 4
|
29天前
|
Linux 数据安全/隐私保护 Docker
linux和windows中安装emqx消息服务器
linux和windows中安装emqx消息服务器
27 0
|
1月前
|
Linux iOS开发 MacOS
|
3月前
|
存储 Ubuntu Linux
windows可以安装Ubuntu,ubuntu上也可以安装Powershell
powerhsell除了可以在windows上使用外,还可以在Ubuntu上部署开发环境。下面介绍Ubuntu上安装powershell的方法。
48 0
|
5月前
|
Shell Linux 开发工具
windows中cmd和PowerShell批处理命令
之前在 Git 批量删除本地分支,有用到 Linux 或 MacOS 下的批处理命令,这个命令中的 grep、xargs 本身是 Shell script,在 windows 中的 cmd 和 PowerShell 中是不能用的
51 0
|
8月前
|
JavaScript Windows
[Vue]解决 Windows PowerShell 不识别 vue 命令的问题
[Vue]解决 Windows PowerShell 不识别 vue 命令的问题
|
8月前
|
Windows
使用PowerShell获取Windows当前锁屏壁纸
使用PowerShell获取Windows当前锁屏壁纸 如果原始图片丢了,用这段代码就可以提取当前锁屏壁纸了!
98 0