cho*_*bo2 6 windows powershell virtualbox powershell-2.0
我有一个带有虚拟盒的Windows 2003盒子设置,我无法使用它来使用它.
我在我的Windows 7机器上试试这个
Get-Service –ComputerName myserver
Run Code Online (Sandbox Code Playgroud)
我回来了
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
Run Code Online (Sandbox Code Playgroud)
在搜索时我发现我应该尝试使用Enable-PSRemoting.
我这样做了,现在当我尝试使用它时,我得到了
WinRM已设置为在此计算机上接收请求.WinRM已经设置为在此计算机上进行远程管理.
但我仍然得到同样的错误.这是因为我使用的是虚拟机吗?我将虚拟操作系统设置为我的域,我甚至可以使用我的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
Run Code Online (Sandbox Code Playgroud)
这些命令可以自行进行远程处理,因为底层基础架构已经支持远程处理,或者它们解决了对系统管理特别重要的场景.它们构建在DCOM的顶部,在访问角度,当您可以使用NET.exe或等命令与远程计算机建立会话时,可以使用它们PSExec.exe.
您正尝试使用其中一个并且您遇到凭据(-cred参数)问题,因为您的令牌凭据不能用于建立到远程计算机的管理会话.
PowerShell远程子系统:
在使用PowerShell远程处理访问远程计算机之前,必须明确启用该计算机上的远程处理服务.您可以使用Enable-PSRemotingcmdlet 执行此操作.如果您在工作组中工作,还需要使用此命令启用服务器进入客户端计算机(在客户端计算机上以管理员身份):
Set-Item WSMan:\localhost\Client\TrustedHosts *
Run Code Online (Sandbox Code Playgroud)
然后,您将使用New-PSSessionCmdlet(使用-computername和-credentials)来创建会话对象.然后Invoke-Command(使用-session和-scriptblock)cmdlet允许您远程调用另一台计算机上的脚本块.这是远程处理中大多数功能的基本元素.您还可以使用Enter-PSSession与服务器建立交互式(类似SSL)PowerShell命令行.
有用的链接:Layman的PowerShell 2.0远程指南
测试一下:
$sess = New-PSSession -ComputerName myServer-Credential (Get-Credential)
Invoke-Command -Session $sess -ScriptBlock {get-service}
...
Remove-PSSession -Session $sess
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
34346 次 |
| 最近记录: |