web-dev-qa-db-ja.com

LinuxのPowerShellを介してWindowsにリモート接続する

LinuxマシンのPowerShellを介してWindowsマシンに接続し、システムの情報を取得しようとしていますが、WinRmを使用せずにそれを実現する必要があります。

まず、 ここ の手順に従ってPowerShellをインストールしました。 PowerShellをpwshで起動すると正常に機能しました。

次に、次のコマンドを使用して、WMIを介していくつかの情報を取得しようとしました。

Get-WmiObject -Class Win32_Process -Impersonation 3 -ComputerName IP_ADDRESS

戻り値はGet-WmiObject : The term 'Get-WmiObject' is not recognized as the name of a cmdlet, function, script file, or operable program.です。

PowerShellのコアのバージョン6.0の changelog に続いて、Get-Wmi *関数をGet-Cmi *の同等の関数に置き換える必要があることがわかりました。やってみよう:

Get-CimInstance -Class Win32_Process -Impersonation 3 -ComputerName IP_ADDRESS

戻り値は次のとおりです。Get-CimInstance : The term 'Get-CimInstance' is not recognized as the name of a cmdlet, function, script file, or operable program.

コマンドのリストを探し、Get-と入力してからTabと入力すると、実際にはWmi関数またはCim関数は表示されません。

コマンドレットInvoke-Commandを使用して同じコンピューターに接続できますが、前述したように、WinRmを使用せずに接続する必要があります。明らかに、これは 呼び出す)の場合ではありません。 -コマンド

多くのGoogle検索の結果、同様の質問が1つだけ見つかりました ここではSO ですが、コマンドレットEnter-PSSessionを使用しています。正しく理解していれば、 WinRM も使用します。 。

最後に、私はこれを見つけました ブログ投稿 私のニーズに合った手袋のようにフィットします。ただし、コマンドレットInvoke-WmiMethodおよびInvoke-CimMethodを使用することをお勧めします。これは、誰も驚いたことに、認識されないコマンドです。

私の質問は、WinRmを使用せずにLinuxマシンのPowerShellを介してWindows情報を取得するためにWMIクエリを実行する方法はありますか?

注1:WindowsマシンPowerShell(RPC経由で接続されているなど)でGet-Wmi*およびGet-Cim*コマンドレットを実行できます。 );

注2:PowerShellを使用せずにLinuxで処理するための 回避策 を知っています。同様の問題を抱えている人でも機能するはずですが解決できないため(少なくとも今のところ)、うまくいきませんでした エンコーディングの問題 ;

[〜#〜]情報[〜#〜]

  • OS:Debian 8.10

  • $ PSVersionTable.PSVersion:6.0.1

  • リモートウィンドウ:W10 Pro

3
James

代わりに、SSH経由のPoSHを参照してください。

こちらの手順をご覧ください。

SSHを介したPowerShellリモーティング

概要概要

PowerShellリモーティングは通常、接続ネゴシエーションとデータ転送にWinRMを使用します。 SSHは、LinuxプラットフォームとWindowsプラットフォームの両方で使用可能になり、真のマルチプラットフォームPowerShellリモート処理が可能になるため、このリモート処理の実装に選択されました。ただし、WinRMは、この実装ではまだ提供されていないPowerShellリモートセッション用の堅牢なホスティングモデルも提供します。これは、PowerShellリモートエンドポイント構成とJEA(Just Enough Administration)がこの実装ではまだサポートされていないことを意味します。

PowerShell SSHリモーティングを使用すると、WindowsマシンとLinuxマシン間で基本的なPowerShellセッションリモーティングを実行できます。これは、SSHサブシステムとしてターゲットマシン上にPowerShellホスティングプロセスを作成することによって行われます。最終的に、これは、エンドポイント構成とJEAをサポートするために、WinRMの動作と同様のより一般的なホスティングモデルに変更されます。

New-PSSession、Enter-PSSession、およびInvoke-Commandコマンドレットに、この新しいリモート接続を容易にするための新しいパラメーターセットが追加されました。

https://github.com/PowerShell/PowerShell/tree/master/demos/SSHRemoting

Anthony Geogheganのコメントに関して更新

はどうかと言うと - -

「それは有望に見えますが、GitHubリポジトリへのリンクは機能しなくなりました。」

----リンクはMSPSリポジトリに直接接続されているため、404が発生しているのは奇妙です。どちらの方法でも、PowerShellを使用して、これをシステムに直接取得できます。

とにかく…

Find-Module -Name '*ssh*' | Format-table -AutoSize

# Results


Version Name                         Repository Description                                                                                                
------- ----                         ---------- -----------                                                                                                
2.1     Posh-SSH                     PSGallery  Provide SSH and SCP functionality for executing commands against remote hosts.                             
0.0.2.0 OpenSSHUtils                 PSGallery  Utilities and functions for configuring OpenSSH on Windows.                                                
2.1.3   SSHSessions                  PSGallery  Svendsen Tech's SSH-Sessions module provides SSH session creation, management and interaction from Power...
1.0.0   SSH                          PSGallery  Provides a PowerShell-based SSH client based on SSH.net  http://sshnet.codeplex.com/                       
0.0.75  PSSharedGoods                PSGallery  Module covering functions that are shared within multiple projects                                         
1.1.3   PowerSSH                     PSGallery  This module detects the first use of an SSH command, automatically runs the SSH agent, keeps the SSH aut...
0.9.5   WinSSH                       PSGallery  Install OpenSSH-Win64, optionally install ssh-agent and sshd Services. Also includes functions to help c...
1.0.1   ssh-wrapper                  PSGallery  Exposes ssh from WSL by wrapping: bash -c "ssh $args". Requires Windows Subsystem for Linux on Windows 10. 
0.3.1   posh-sshell                  PSGallery  Provides integration with ssh-agent and pageant from within Powershell                                     
2.0.1.8 SkypeForBusinessHybridHealth PSGallery  Uses on-premises modules such as Skype For Business and SkypeOnlineConnector to validate basic requireme...
1.0.4   PSShortcut                   PSGallery  This module eases working with Windows shortcuts (LNK and URL) files.                                      
1.1.4   PowerSSH-Legacy              PSGallery  This module detects the first use of an SSH command, automatically runs the SSH agent, keeps the SSH aut...
1.0     cEPRSSharepoint              PSGallery  DSCModule helps in installing & configuring the sharepoint site, Farm etc.,                                
0.0.3   dockeraccesshelper           PSGallery  Allow a user account to access the docker engine without elevated access rights                            
0.3     PSShareFile                  PSGallery  A PowerShell module to manipulate various objects in Citrix's ShareFile service                            
0.0.1   PSSherpaDesk                 PSGallery  PowerShell module for interacting with the SherpaDesk API  


Find-Module -Name '*Posh-SSH' | 
Save-Module -Path "$env:USERPROFILE\Documents\WindowsPowerShell\Modules" 
Install-Module -Name 'Posh-SSH'

SSHRemotingのデモにはこのリンクを使用してください

私はちょうどそれを打ったので、私はそれがうまくいくことを知っています。

これらのYouTubeビデオPowerShell SSH Remotingの動作を参照してください。

3
postanote