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

来源:互联网 发布:云豹直播完整源码 编辑:程序博客网 时间:2024/05/22 12:10


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


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

如何安装呢?看Instructions:

PlatformDownloadsHow to InstallWindows 10 / Server 2016.msiInstructionsWindows 8.1 / Server 2012 R2.msiInstructionsUbuntu 16.04.debInstructionsUbuntu 14.04.debInstructionsCentOS 7.rpmInstructionsOS X 10.11.pkgInstructionsDocker Instructions

然后,安装OMI和PSRP:

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

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

PlatformReleasesLinkLinuxDebianpsrp-1.0.0-0.universal.x64.debLinuxRPMpsrp-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


0 0
原创粉丝点击