使用 powershell 无法在远程计算机上调用命令

发布于 2024-12-05 17:38:31 字数 540 浏览 0 评论 0原文

我在我的计算机上运行以下命令,使用调用命令将数据从一台服务器下载到另一台服务器,

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_ACCESSDENIED))

但是当我在计算机上运行上述命令时

c:\temp.ps1 -server serverX -id 4231e429-d238-4e32-a1bb-0ee812cd3124 -download $true

它按预期工作。

当我远程执行它时,我是否缺少某些东西......请帮助我。

谢谢

I ran the below commands on my machine to download data from one server to another server using the invoke command

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}

ERROR is: Failed: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

but when i run the above command on my machine as

c:\temp.ps1 -server serverX -id 4231e429-d238-4e32-a1bb-0ee812cd3124 -download $true

it works as expected.

Is there something i am missing when i execute it remotely....please help me.

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦幻的味道 2024-12-12 17:38:31

试试这个好参考:
http://www.ravichaganti.com/blog/?p=1108
http://technet.microsoft.com/en-us/magazine/ff700227.aspx

这可能与 TrustedHosts 或身份验证有关
客户端的设置。可以这样设置:WinRM设置
winrm/config/client @{TrustedHosts="*"}

在此处阅读有关此内容的更多信息:
http://blogs.dirteam.com/blogs/sanderberkouwer/archive/2008/02/23/remotely-managing-your-server-core-using-winrm-a​​nd-winrs.aspx

我使用

powershell.exe -ExecutionPolicy Unrestricted -WindowStyle Hidden -NoLogo

我使用这段代码:

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
}

Try this good References:
http://www.ravichaganti.com/blog/?p=1108
http://technet.microsoft.com/en-us/magazine/ff700227.aspx

It might be something to do with the TrustedHosts or Authentication
setting of a client. You can set it like this:WinRM set
winrm/config/client @{TrustedHosts="*"}

Read more about this here:
http://blogs.dirteam.com/blogs/sanderberkouwer/archive/2008/02/23/remotely-managing-your-server-core-using-winrm-and-winrs.aspx

I use

powershell.exe -ExecutionPolicy Unrestricted -WindowStyle Hidden -NoLogo

I use this code:

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
}
薄荷港 2024-12-12 17:38:31

您需要在远程计算机上启用远程处理。您还需要确保防火墙/防病毒软件不会阻止远程端口。这些是 http 的端口 5985 或 https 的端口 5986。

如果两台机器都在同一个域上,那么工作起来相当容易。然而,如果机器位于不同的域,那么情况会更加复杂。远程服务器上有一个注册表设置需要更改,并且您需要传递凭据。请阅读此处了解更多信息 。当然也可以启用 ssl,但那是另一个故事了。

You need to enable remoting on the remote machine. You also need to make sure the firewall/anti virus does not block the remoting ports. These are port 5985 for http, or port 5986 for https.

If both machines on the same domain it's fairly easy to get working. If the machines are on different domains however then it's more complex. There's a registry setting that needs to be changed on the remote server, and you need to pass credentials. Have a read here for more info. There is of course ssl which can also be enabled, but that's another story.

<逆流佳人身旁 2024-12-12 17:38:31

您的脚本中有一个错误。

您不应在 Invoke-Command 之前执行 Enter-PSSession,因为 Invoke-Command 本身会设置 PSSession。
仅使用此:

Invoke-command -computername Server1 -credential:'dom\jack' {c:\temp.ps1 -server serverX -id 4231e429-d238-4e32-a1bb-0ee812cd3124 -download $true}

...没有 Enter-PSSession

There is a bug in your script.

You should not be executing Enter-PSSession before the Invoke-Command, because the Invoke-Command itself sets up the PSSession.
Use only this:

Invoke-command -computername Server1 -credential:'dom\jack' {c:\temp.ps1 -server serverX -id 4231e429-d238-4e32-a1bb-0ee812cd3124 -download $true}

... Without the Enter-PSSession

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文