1

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

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

I tried this on two PCs, one is OK without any errors, but another one I am going to 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 remoteServer is the same one. Not sure what I have to set on local PC or remote PC to make this work? On both client PCs, the user names are all member of Administrators.

David.Chu.ca
  • 37,408
  • 63
  • 148
  • 190

3 Answers3

11

Have you considered looking into PowerShell remoting? If your running PowerShell 2.0 I'd recommend that you take a look at it. Once you have set up remoting you'll be able to execute commands on the remote server using the Invoke-Command:

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

The ScriptBlock can contain any powershell commands so you will be able to start processes on the remote machine with this mechanism. To enable remoting you'll need to use the Enable-PSRemoting cmdlet and you can get details of this at http://blogs.msdn.com/powershell/archive/2009/04/30/enable-psremoting.aspx and http://technet.microsoft.com/en-us/library/dd819498.aspx

  • Unfortunately, I cannot install PS 2.0 since it requires SP 3 which is not available through out network permission. – David.Chu.ca Nov 23 '09 at 21:01
2

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

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

No Refunds No Returns
  • 8,092
  • 4
  • 32
  • 43
  • 2
    I tried PSExec. It woks for running bat on remote PC. However, it does not let me run PS scripts on remote PC. PS is hanging on remote process but not script exec. – David.Chu.ca Nov 23 '09 at 18:38
1

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

"Get-ExecutionPolicy"

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

You can change it to 1 of 7 options:

  1. Unrestricted____(least secure but if you need to troubleshoot set this option)
  2. RemoteSigned__(will only all scripts with a signature, this a so so option)
  3. AllSigned______(Best option if youu need to run remote scripts, but all will beed signed)
  4. Restricted_____(I believe this option is set by default in windows 7 nad WS2k8)
  5. Default
  6. Bypass
  7. Undefined
user953533
  • 321
  • 2
  • 6