Executing a batch file on a remote computer

I am on host_computer and am trying to execute a batch file on remote_computer (part of WORKGROUP) to enable psremoting and use winrm to add trustedhosts.

Based on http://social.technet.microsoft.com/Forums/scriptcenter/en-US/732495c0-114c-4a1e-bbe1-5a7a3b84012d/execute-a-batch-file-on-a-remote-pc?forum= ITCG

I tried to create a process, i.e.

$server = "remote_computer" $process = [WMICLASS]"\\$server\ROOT\CIMV2:win32_process" 

But I get an error

 Cannot convert value "\\remote_computer\ROOT\CIMV2:win32_process" to type "System.Management.ManagementClass". Error: "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))" At line:1 char:1 + $process = [WMICLASS]"\\$server\ROOT\CIMV2:win32_process" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [], RuntimeException + FullyQualifiedErrorId : InvalidCastToWMIClass 

Then I tried using psexec

 PsExec.exe \\remote_computer -u username -p password 'C:\share\enable.bat' 

And get an error

 D:\pstools\PsExec.exe : At line:1 char:1 + D:\pstools\PsExec.exe \\remote_computer -u username -p password 'C:\share\ena ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError PsExec v2.0 - Execute processes remotely Copyright (C) 2001-2013 Mark Russinovich Sysinternals - www.sysinternals.com The handle is invalid. Connecting to remote_computer...Couldn't access remote_computer: Connecting to remote_computer... 

And this script package should enable psremoting and add trusted hosts using winrm

 @echo off C:\share\remote.ps1 winrm set winrm/config/client/auth @{Basic="true"} winrm set winrm/config/client @{AllowUnencrypted="true"} winrm set winrm/config/client @{TrustedHosts="host_computer"} 
+1
source share

All Articles