简体   繁体   English

Powershell远程访问被拒绝

[英]Powershell remote access denied

I am trying to start a service on a remote computer using the following command on the cmdlet: 我正在尝试使用cmdlet上的以下命令在远程计算机上启动服务:

(Get-WmiObject -computer atl-fs-01 Win32_Service -Filter "Name='Alerter'").InvokeMethod("StartService",$null)

When I run the command I get the error Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) 当我运行命令时,我得到错误Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) . Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) After some research it appears I need to set my username and password, but I cannot find anything that allows me to set these prior to accessing the remote computer. 经过一番研究后,我似乎需要设置用户名和密码,但是在访问远程计算机之前找不到任何可以设置这些用户名和密码的东西。 I also plan on making a script for this so I don't have to type out everything on the command line. 我还计划为此编写脚本,因此不必在命令行中输入所有内容。 PowerShell code for setting user and password would be helpful as well. 用于设置用户和密码的PowerShell代码也将很有帮助。 Thanks. 谢谢。

You need to pass in the credential object (created with Get-Credential) using the "-Credential" switch. 您需要使用“ -Credential”开关传入凭据对象(使用Get-Credential创建)。

See this MSDN article for more information and an example. 有关更多信息和示例,请参见此MSDN文章

Chapter 13 (page 502) of Bruce Payette's (UTTERLY AWESOME) "Windows Powershell in Action, Second Edition" comprehensively covers configuration of remote Powershell admin. 布鲁斯·佩耶特(Bruce Payette)的第13章(第502页)(非常棒)“ Windows Powershell in Action,第二版”全面介绍了远程Powershell管理员的配置。 If you've not already asked Santa for a copy of this wonderful book, DO SO NOW! 如果您尚未要求圣诞老人提供这本精美的书的副本,请立即开始! :) :)

In case you are in a hurry: 如果您很着急:

MSDN ( and other sources ) have some good documentation on how to MSDN( 和其他来源 )提供了一些有关如何

  1. Enable remoting to a remote server 启用远程到远程服务器
  2. Connect from your local server to your remote server & execute commands 从本地服务器连接到远程服务器并执行命令

HTH. HTH。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM