Run remote process using powershell

I have the following line of code to create an object to access a remote server before I associate it with a username, password, and process:

$process = [WMIClass]"\\remoteServer\ROOT\cimv2:Win32_Process" 

I tried this on two computers, one of them without errors, but the other that I run has an exception:

 Cannot convert value "\\remoteServer\ROOT\cimv2:Win32_Process" to type "System.Manage ment.ManagementClass". Error: "Access is denied. (Exception from HRESULT: 0x800 70005 (E_ACCESSDENIED))" 

The remote server is the same. Not sure what I need to install on a local PC or a remote PC to make this work? On both client computers, user names are members of Administrators.

+1
source share
3 answers

Is there a reason you don't want to use psexec?

http://technet.microsoft.com/en-us/sysinternals/bb545027.aspx

+2
source

Have you considered removing PowerShell? If your PowerShell 2.0 is working, I recommend that you take a look at it. Once you have configured remote access, you can execute commands on the remote server using the Invoke-Command command:

 Invoke-Command -ComputerName {serverName} –ScriptBlock { commands } 

ScriptBlock can contain any powershell commands so that you can run processes on a remote machine using this mechanism. To enable remote access, you need to use the Enable-PSRemoting cmdlet, and you can get detailed information about this at http://blogs.msdn.com/powershell/archive/2009/04/30/enable-psremoting.aspx and http: //technet.microsoft.com/en-us/library/dd819498.aspx

+11
source

I know this is an old post, but it seems to me what you need to do is run the following command on a remote machine:

"Get-ExecutionPolicy"

it looks like its set to "Limited", which means that it will not run any "Invoke-Commands" commands or remote scripts.

You can change it to 1 of 7 options:

  • Unrestricted_ ___ (least secure, but if you need to fix the problem, set this parameter)
  • RemoteSigned __ (there will be only all scripts with a signature, this is an option)
  • AllSigned_ _____ (the best option if you need to run remote scripts, but all will be signed)
  • Restricted_ ____ (I believe this option is installed by default in Windows 7 and above WS2k8)
  • Default
  • Bypass
  • Undefined
+1
source

Source: https://habr.com/ru/post/915841/


All Articles