我在host_computer上并尝试在remote_computer(WORKGROUP的一部分)上执行批处理文件以启用psremoting并使用winrm添加trustedhosts。
我尝试创建一个过程,即
$server = "remote_computer"
$process = [WMICLASS]"\\$server\ROOT\CIMV2:win32_process"
但我收到错误
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
然后我尝试使用psexec
PsExec.exe \\remote_computer -u username -p password 'C:\share\enable.bat'
并获得错误
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...
此批处理脚本是使用winrm启用psremoting并添加可信主机
@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"}