加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 无法在远程计算机上使用Get-Service -ComputerName

发布时间:2020-12-14 02:54:01 所属栏目:Windows 来源:网络整理
导读:我有一个带有虚拟盒的 Windows 2003盒子设置,我无法使用它来使用它. 我在我的Windows 7机器上试试这个 Get-Service –ComputerName myserver 我回来了 Get-Service : Cannot open Service Control Manager on computer 'myserver'. This operation might req
我有一个带有虚拟盒的 Windows 2003盒子设置,我无法使用它来使用它.

我在我的Windows 7机器上试试这个

Get-Service –ComputerName myserver

我回来了

Get-Service : Cannot open Service Control Manager on computer 'myserver'. This operation might require other privileges.
At Script1.ps1:2 char:4
+ gsv <<<<  -cn myserver
    + CategoryInfo          : NotSpecified: (:) [Get-Service],InvalidOperationException
    + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.GetServiceCommand

在搜索时我发现我应该尝试使用Enable-PSRemoting.

我这样做了,现在当我尝试使用它时,我得到了

WinRM already is set up to receive requests on this machine. WinRM
already is set up for remote management on this machine.

但我仍然得到同样的错误.这是因为我使用的是虚拟机吗?我将虚拟操作系统设置为我的域,我甚至可以使用我的AD帐户凭据登录.

我可以从中获取其他信息.

所以我不能用PowerShell连接它.

解决方法

使用PowerShell V2,您有两种远程命令方法.

内置远程处理的命令:

PowerShell v2中的一小组命令具有-ComputerName参数,该参数允许您指定要访问的目标计算机.

Get-Process
Get-Service
Set-Service

Clear-EventLog
Get-Counter
Get-EventLog
Show-EventLog
Limit-EventLog
New-EventLog
Remove-EventLog
Write-EventLog

Restart-Computer
Stop-Computer

Get-HotFix

这些命令可以自行进行远程处理,因为底层基础架构已经支持远程处理,或者它们解决了对系统管理特别重要的场景.它们构建在DCOM的顶部,在访问角度,当您可以使用NET.exe或PSExec.exe等命令与远程计算机建立会话时,可以使用它们.

您正在尝试使用其中一个并且您的凭据(-cred参数)存在问题,因为您的令牌凭据不能用于建立与远程计算机的管理会话.

PowerShell远程子系统:

在使用PowerShell远程处理访问远程计算机之前,必须明确启用该计算机上的远程处理服务.您可以使用Enable-PSRemoting cmdlet执行此操作.如果您在工作组中工作,还需要使用此命令启用服务器进入客户端计算机(在客户端计算机上以管理员身份):

Set-Item WSMan:localhostClientTrustedHosts *

然后,您将使用New-PSSession Cmdlet(带-computername和-credentials)来创建会话对象.然后,Invoke-Command(带-session和-scriptblock)cmdlet允许您远程调用另一台计算机上的scriptblock.这是远程处理中大多数功能的基本元素.您还可以使用Enter-PSSession与服务器建立交互式(类似SSL)PowerShell命令行.

有用链接:Layman’s guide to PowerShell 2.0 remoting

测试一下:

$sess = New-PSSession -ComputerName myServer-Credential (Get-Credential)
Invoke-Command -Session $sess -ScriptBlock {get-service}
...
Remove-PSSession -Session $sess

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读