执行远程计算机上的批处理文件 [英] Execute batch file on remote computer

查看:255
本文介绍了执行远程计算机上的批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在host_computer并试图对REMOTE_COMPUTER(工作组的一部分)执行批处理文件,以使psremoting并使用WinRM的添加trustedhosts。

根据<α

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

我试图创建一个过程,即

  $服务器=REMOTE_COMPUTER
$工艺= [WMICLASS]\\\\ $服务器\\ ROOT \\ CIMV2:Win32_Process的

但我得到错误

 无法转换值\\\\ REMOTE_COMPUTER \\ ROOT \\ CIMV2:Win32_Process的输入System.Management.ManagementClass。错误:访问被拒绝(从HRESULT异常:0X80070005(E_ACCESSDENIED))。在行:1字符:1
+ $工艺= [WMICLASS]\\\\ $服务器\\ ROOT \\ CIMV2:Win32_Process的
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
    + CategoryInfo:InvalidArgument:(:) []的RuntimeException
    + FullyQualifiedErrorId:InvalidCastToWMIClass

然后我试图使用PSEXEC

  PsExec.exe \\\\ REMOTE_COMPUTER -u用户名-p密码为C:\\共享\\ enable.bat

和得到错误

  D:\\ pstools \\ PsExec.exe:在行:1字符:1
+ D:\\ pstools \\ PsExec.exe \\\\ REMOTE_COMPUTER -u用户名-p密码为C:\\共享\\ ENA ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo:NotSpecified:(:字符串)[],的RemoteException
    + FullyQualifiedErrorId:NativeCommandError PSEXEC V2.0 - 执行过程远程版权所有(C)二零零一年至2013年标记Russinovich的Sysinternals - www.sysinternals.com句柄无效。连接到REMOTE_COMPUTER ...无法访问REMOTE_COMPUTER:连接到REMOTE_COMPUTER ...

和这个批处理脚本是使psremoting使用WinRM的添加可信主机

 关闭@echo
C:\\共享\\ remote.ps1
WinRM的设置winrm /配置/客户端/ AUTH @ {基本=真}
WinRM的设置winrm /配置/客户@ {AllowUnencrypted =真}
WinRM的设置winrm /配置/客户@ {TrustedHosts =host_computer}


解决方案

有就设在这里的模块,这将通过WMI启用PSRemoting你。

http://gallery.technet.microsoft.com/scriptcenter/Enable-PSRemoting-Remotely-6cedfcb0

I am on host_computer and attempting to execute 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 creating a process, i.e.

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

But I get 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 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 batch script is to 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"}

解决方案

There is a module located here, which will enable PSRemoting via WMI for you.

http://gallery.technet.microsoft.com/scriptcenter/Enable-PSRemoting-Remotely-6cedfcb0

这篇关于执行远程计算机上的批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆