【问题标题】:Powershell Get-WmiObject Access is deniedPowershell Get-WmiObject 访问被拒绝
【发布时间】:2012-08-11 16:24:39
【问题描述】:

我有一个包含以下行的 Powershell 脚本:

$package = Get-WmiObject -Class Win32_Product -ComputerName $TargetServer -Filter ("Name='{0}'" -f $ApplicationName)

我按照这个答案的步骤来启用服务器之间的 Powershell 远程处理:remoting security steps

当我从 Powershell ISE(在提升的管理窗口中)运行脚本时,我收到以下错误:

Get-WmiObject : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At line:1 char:14
+ Get-WmiObject <<<<  win32_bios -computername d-vasbiz01
+ CategoryInfo          : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

我需要能够在 ISE 中运行脚本,以便解决其他问题。

谁能建议我需要做些什么来修复这个安全错误?

【问题讨论】:

  • 我只是想验证一下 - 您已经从标准窗口以及具有提升权限的窗口尝试过,对吧?
  • 我注意到您在谈论远程处理。您是否正在尝试双跳?
  • 不,托管客户端和服务器的虚拟机都在同一个域中 - 实际上在同一个物理主机上。
  • 好的,我的错误 - 从 TFS 运行时也不起作用。无论代码如何运行,我都会遇到安全异常。我是否需要启用机器之间的信任或类似的东西?

标签: powershell tfs


【解决方案1】:

我需要将凭据传递给 Get-WmiObject cmdlet。

我在这里找到了答案:Powershell Masters

【讨论】:

  • 你能帮我提供更多细节吗?我真的被困住了。提前致谢
【解决方案2】:

在猜测了一段时间后,缓存的凭据是我的问题。

打开 Windows 凭据管理器:

rundll32.exe keymgr.dll,KRShowKeyMgr

删除所有缓存的条目。

【讨论】:

    【解决方案3】:

    要扩展 Rob Bowman 的答案,您可以预先收集凭据,也可以在运行命令时收集。

    • 预先(最好,因为您可以将其重新用于未来的 Get-WmiObject 命令:

      $creds = get-credential
      
      $package = Get-WmiObject -Class Win32_Product -ComputerName $TargetServer -Filter ("Name='{0}'" -f $ApplicationName) -credential $creds
      
    • 内联:

      $package = Get-WmiObject -Class Win32_Product -ComputerName $TargetServer -Filter ("Name='{0}'" -f $ApplicationName) -credential (get-credential)
      

    【讨论】:

      【解决方案4】:

      您必须授予该用户 WMI 权限。

      https://technet.microsoft.com/en-us/library/cc771551(v=ws.11).aspx

      本地/域管理员默认应该有这个。

      【讨论】:

      • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
      猜你喜欢
      • 1970-01-01
      • 2013-09-06
      • 2021-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-25
      • 2012-12-10
      • 1970-01-01
      相关资源
      最近更新 更多