使用 powershell 无法在远程计算机上调用命令
我在我的计算机上运行以下命令,使用调用命令将数据从一台服务器下载到另一台服务器,
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个好参考:
http://www.ravichaganti.com/blog/?p=1108
http://technet.microsoft.com/en-us/magazine/ff700227.aspx
在此处阅读有关此内容的更多信息:
http://blogs.dirteam.com/blogs/sanderberkouwer/archive/2008/02/23/remotely-managing-your-server-core-using-winrm-and-winrs.aspx
我使用
我使用这段代码:
Try this good References:
http://www.ravichaganti.com/blog/?p=1108
http://technet.microsoft.com/en-us/magazine/ff700227.aspx
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
I use this code:
您需要在远程计算机上启用远程处理。您还需要确保防火墙/防病毒软件不会阻止远程端口。这些是 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.
您的脚本中有一个错误。
您不应在 Invoke-Command 之前执行 Enter-PSSession,因为 Invoke-Command 本身会设置 PSSession。
仅使用此:
...没有 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:
... Without the Enter-PSSession