远程计算机上的invoke命令未使用powershell工作
我在我的机器上运行了以下命令,使用invoke命令将数据从一台服务器下载到另一台服务器远程计算机上的invoke命令未使用powershell工作,powershell,Powershell,我在我的机器上运行了以下命令,使用invoke命令将数据从一台服务器下载到另一台服务器 Enable-PSRemoting -force Enter-PSSession Server1 invoke-command -computername Server1 -credential:'dom\jack' {c:\temp.ps1 -server serverX -id 4231e429-d238-4e32-a1bb-0ee812cd3124 -download $true} 错误为:失败
Enable-PSRemoting -force
Enter-PSSession Server1
invoke-command -computername Server1 -credential:'dom\jack' {c:\temp.ps1 -server serverX -id 4231e429-d238-4e32-a1bb-0ee812cd3124 -download $true}
错误为:失败:访问被拒绝。(HRESULT异常:0x80070005(E_访问被拒绝))
但是当我在我的机器上以
c:\temp.ps1-服务器serverX-id 4231e429-d238-4e32-a1bb-0ee812cd3124-下载$true
它按预期工作
当我远程执行它时,是否有我遗漏的东西…请帮助我
谢谢您需要在远程计算机上启用远程处理。您还需要确保防火墙/防病毒软件不会阻止远程处理端口。它们是用于http的端口5985,或用于https的端口5986
如果两台机器在同一个域上,那么很容易开始工作。但是,如果机器位于不同的域上,那么就更复杂了。远程服务器上有一个注册表设置需要更改,您需要传递凭据。请在此阅读。当然也可以启用ssl,但那是另一回事。试试这个好的参考资料:
这可能与受信任的主机或身份验证有关 客户端的设置。您可以这样设置:WinRM set winrm/config/client@{TrustedHosts=“*”} 请在此处阅读更多信息: 我用 我使用以下代码:
try
{
Invoke-Command -credential $testCred -computer $ServerName -scriptblock {
param([String]$scriptDeploy, [String]$destino) &"$scriptDeploy" 'parametro1' $destino
$ScriptBlockOutput = $Error
} -ArgumentList $RutaRemotaParaScriptDeInstalacion, "$dirRemotoDestino"
"`r`n`r`nOK para script de despliegue"
exit 0;
}
catch
{
"`r`n`r`nError en script de despliegue"
"`r`nError in " + $_.InvocationInfo.ScriptName + " at line: " + $_.InvocationInfo.ScriptLineNumber + ", offset: " + $_.InvocationInfo.OffsetInLine + ".";
exit -1
}
你的脚本中有一个bug 您不应该在Invoke命令之前执行Enter-PSSession,因为Invoke命令本身设置了PSSession。 仅使用以下选项:
Invoke-command -computername Server1 -credential:'dom\jack' {c:\temp.ps1 -server serverX -id 4231e429-d238-4e32-a1bb-0ee812cd3124 -download $true}
。。。在没有输入PSSession的情况下,我也使用了新的Itemproperty-name LocalAccountTokenFilterPolicy-path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System-propertyType DWord-value 1命令,但运气不好……我发现了与第一次显示的错误相同的端口是否打开?
telnet servername 5985是否连接?远程主机上是否配置了受信任的主机?从一个简单的远程调用开始,比如-scriptblock{get process}
,然后首先让它工作。当我运行WinRM quickconfig$securePassword=ConvertTo SecureString时,我可以看到“WinRM已经为此计算机上的远程管理设置了”xyz@J123"-AsPlainText-force$credential=New Object System.Management.Automation.PsCredential(“dom\jack”,$securePassword)Invoke命令-ComputerName Server1-ScriptBlock{c:\temp.ps1-server serverX-id 4231e429-d238-4e32-a1bb-0ee812cd3124-下载$true}-凭证$credential,但没有运气。您能否提供有关如何运行telnet或配置的受信任主机的更多信息?telnet
可用于测试端口是否打开/可访问,它可以安装在windows功能中。要添加可信主机,请参阅我链接到的文章中的可信主机
。你能按照我的建议尝试一个获取过程吗?这行吗?您在远程计算机上设置了执行策略吗?是的,我以“Invoke Command-ComputerName Server1-ScriptBlock{get process}-Credential$Credential”的形式运行get进程,它列出了所有进程。我还将远程计算机上的执行策略设置为“remotesigned”。今天我使用了不同的服务器,但在该服务器上也出现了相同的行为错误:“失败:访问被拒绝。(来自HRESULT的异常:0x80070005(E_ACCESSDENIED))”
Invoke-command -computername Server1 -credential:'dom\jack' {c:\temp.ps1 -server serverX -id 4231e429-d238-4e32-a1bb-0ee812cd3124 -download $true}