I'm trying to connect to a Windows Machine via PowerShell in a Linux Machine to get some system's info, but I need to achieve it without use the WinRm.
Firstly, I installed the PowerShell following the instructions here. Starting the PowerShell with pwsh
worked fine.
Then I tried to get some info through WMI using the following command:
Get-WmiObject -Class Win32_Process -Impersonation 3 -ComputerName IP_ADDRESS
The return is Get-WmiObject : The term 'Get-WmiObject' is not recognized as the name of a cmdlet, function, script file, or operable program.
.
Following the changelog for the version 6.0 of PowerShell's core, I found that the Get-Wmi* functions should be replaced for Get-Cmi* equivalents. Let's try:
Get-CimInstance -Class Win32_Process -Impersonation 3 -ComputerName IP_ADDRESS
The return is: Get-CimInstance : The term 'Get-CimInstance' is not recognized as the name of a cmdlet, function, script file, or operable program.
Looking for the list of commands, typing Get-
and then Tab, the return indeed does not show any Wmi or Cim function.
I'm able to connect to the same computer using the cmdlet Invoke-Command
, but as I said, I need to achieve it without the use of WinRm, and, apparently, this is not the case of Invoke-Comand
After a lot of Google search, I found only one similar question here in SO, but it user the cmdlet Enter-PSSession
, that's also use WinRM if I understood correctly.
Finally, I found this blog post with fits like a glove with my needs. However, It suggest the use of the cmdlets Invoke-WmiMethod
and Invoke-CimMethod
that, for surprise of nobody, aren't recognized commands.
My question is: Are there anyway to run a WMI query to get some Windows info through PowerShell in a linux machine without the use of WinRm?
Note1: I'm able to run the Get-Wmi*
and Get-Cim*
cmdlets in Windows machine PowerShell (connected via RPC, for example);
Note2: I know a workaround to deal with it in linux without PowerShell and it should work for someone with similar problem, but it didn't work for me due to an unsolvable (for now, at least) encoding problem;
INFO
-
OS: Debian 8.10
-
$PSVersionTable.PSVersion: 6.0.1
-
Remote Windows: W10 Pro
Best Answer
Look to PoSH over SSH instead.
See the step thru here:
Updated with regards to Anthony Geoghegan comment
As for ---
----The link is directly to the MS PS repo, so, Yeppers it's odd that a 404 is happening. Either way, you can get this directly on your system by using PowerShell.
Anyway …
Use this link for demo of SSHRemoting
I just hit it, so I know it works.
See these YouTube videos PowerShell SSH Remoting in action.