
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 では、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
、これも使用されますウィンRM私が正しく理解していれば。
ついにこれを見つけたブログ投稿私のニーズにぴったりです。ただし、コマンドレットの使用を提案していますInvoke-WmiMethod
がInvoke-CimMethod
、誰も驚かないかもしれませんが、コマンドは認識されません。
私の質問は、WinRm を使用せずに Linux マシンで PowerShell を介して WMI クエリを実行し、Windows 情報を取得する方法があるかどうかです。
注1: Windows マシンの PowerShell (たとえば、RPC 経由で接続) でコマンドレットGet-Wmi*
を実行できます。Get-Cim*
注2: 私は知っている回避策PowerShellなしでLinuxで対処する方法は、同様の問題を抱えている人には有効であるはずですが、解決できない(少なくとも今のところ)ため、私にはうまくいきませんでした。エンコードの問題;
情報
OS: Debian 8.10
$PSバージョンテーブル.PSバージョン: 6.0.1
リモート Windows: W10 Pro
答え1
代わりに、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 です。
アンソニー・ジオゲガンのコメントに関して更新
はどうかと言うと - -
「それは有望に見えますが、GitHub リポジトリへのリンクは機能しなくなりました。」
---- リンクは MS PS リポジトリに直接接続されているため、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のデモについてはこのリンクを使用してください
ちょうどそれを打ったので、それが機能することがわかりました。