Linux에서 PowerShell을 통해 Windows에 원격 연결

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의 경우 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 기능이 표시되지 않습니다.

cmdlet을 사용하여 동일한 컴퓨터에 연결할 수 있지만 Invoke-Command앞서 말했듯이 WinRm을 사용하지 않고 연결해야 하며 분명히 그렇지 않습니다.호출 명령

구글링을 많이 해보니 비슷한 질문이 딱 하나 발견됐네요여기 그래서, 하지만 cmdlet을 사용하는 Enter-PSSession경우에도 사용됩니다.WinRM내가 올바르게 이해했다면.

마침내 나는 이것을 발견했다블로그 게시물내 필요에 꼭 맞는 장갑처럼요. 그러나 이는 cmdlet의 사용을 제안하며 Invoke-WmiMethod놀랍게도 Invoke-CimMethod아무도 명령을 인식하지 못합니다.

내 질문은: 어쨌든 WinRm을 사용하지 않고 Linux 시스템에서 PowerShell을 통해 일부 Windows 정보를 얻기 위해 WMI 쿼리를 실행할 수 있습니까?

참고1: Windows 컴퓨터 PowerShell(예: RPC를 통해 연결됨)에서 및 cmdlet을 Get-Wmi*실행할 수 있습니다 .Get-Cim*

노트 2: 나도 알아해결 방법PowerShell 없이 Linux에서 이 문제를 처리하려면 비슷한 문제가 있는 사람에게는 작동해야 하지만 (적어도 지금은) 해결할 수 없는 문제로 인해 저에게는 작동하지 않았습니다.인코딩 문제;

정보

  • OS: 데비안 8.10

  • $PSVersionTable.PS버전: 6.0.1

  • 원격 Windows: W10 Pro

답변1

대신 SSH를 통해 PoSH를 살펴보세요.

여기를 통해 단계를 참조하십시오:

SSH를 통한 PowerShell 원격

개요

PowerShell 원격은 일반적으로 연결 협상 및 데이터 전송을 위해 WinRM을 사용합니다. 이제 Linux 및 Windows 플랫폼 모두에서 사용할 수 있고 진정한 다중 플랫폼 PowerShell 원격 기능을 허용하므로 이 원격 구현을 위해 SSH가 선택되었습니다. 그러나 WinRM은 이 구현이 아직 수행하지 않는 PowerShell 원격 세션을 위한 강력한 호스팅 모델도 제공합니다. 이는 PowerShell 원격 끝점 구성 및 JEA(Just Enough Administration)가 이 구현에서 아직 지원되지 않음을 의미합니다.

PowerShell SSH 원격을 사용하면 Windows와 Linux 컴퓨터 간에 기본 PowerShell 세션 원격을 수행할 수 있습니다. 이는 대상 컴퓨터에 SSH 하위 시스템으로 PowerShell 호스팅 프로세스를 생성하여 수행됩니다. 결국 이는 엔드포인트 구성 및 JEA를 지원하기 위해 WinRM이 작동하는 방식과 유사한 보다 일반적인 호스팅 모델로 변경될 것입니다.

New-PSSession, Enter-PSSession 및 Invoke-Command cmdlet에는 이제 이 새로운 원격 연결을 용이하게 하는 새로운 매개 변수 집합이 있습니다.

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

Anthony Geoghegan 의견과 관련하여 업데이트되었습니다.

---에 관해서는

'유망해 보이지만 GitHub 저장소에 대한 링크가 더 이상 작동하지 않습니다.'

----링크는 MS PS 저장소로 직접 연결되므로 Yeppers 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이 실제로 작동하는 모습을 확인하세요.

관련 정보