更新时间:2022-12-22 23:10:12
有就设在这里的模块,这将通过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.
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