You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PowerShell远程获取系统信息时遇Get-WmiObject拒绝访问错误求助

解决PowerShell远程获取系统信息时的「Get-wmiObject : access is denied」错误

我是PowerShell新手,尝试通过脚本远程获取桌面设备的基础系统信息,但执行时遇到「Get-wmiObject : access is denied」错误。

我的脚本内容如下:

$remoteComputer = "IP address of the remote computer"

$desktopInfo = Get-WmiObject -Class Win32_Computer SystemProduct -ComputerName $remoteComputer

$serialNumber = $desktopInfo. IdentifyingNumber

$model = $desktopInfo.Name

$systemInfo = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $remoteComputer

$systemName = $systemInfo.Name

$processorInfo = Get-WmiObject -Class Win32_Processor -ComputerName $remoteComputer

$processorName= $processorInfo. Name

Write-Host "System Name: $systemName"

Write-Host "Processor Name: $processorName"

Write-Host "Serial Number: $serialNumber"

Write-Host "Model: Smodel"

一、先修正脚本中的语法错误

  • WMI类名错误:Win32_Computer SystemProduct 中间的空格需删除,正确类名为 Win32_ComputerSystemProduct
  • 变量引用的空格:属性名前的空格要去掉,比如 $desktopInfo. IdentifyingNumber → $desktopInfo.IdentifyingNumber,$processorInfo. Name → $processorInfo.Name
  • 最后一行输出错误:Smodel 应该是变量 $model,即 Write-Host "Model: $model"

修正后的脚本:

$remoteComputer = "IP address of the remote computer"

$desktopInfo = Get-WmiObject -Class Win32_ComputerSystemProduct -ComputerName $remoteComputer

$serialNumber = $desktopInfo.IdentifyingNumber

$model = $desktopInfo.Name

$systemInfo = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $remoteComputer

$systemName = $systemInfo.Name

$processorInfo = Get-WmiObject -Class Win32_Processor -ComputerName $remoteComputer

$processorName= $processorInfo.Name

Write-Host "System Name: $systemName"
Write-Host "Processor Name: $processorName"
Write-Host "Serial Number: $serialNumber"
Write-Host "Model: $model"

二、解决「access is denied」权限问题

1. 本地运行要求

必须以管理员身份启动PowerShell,远程WMI访问需要提升的权限。

2. 确认远程机器WMI服务状态

确保远程机器上的「Windows Management Instrumentation」服务(服务名:Winmgmt)处于运行状态,可通过以下命令验证(需初步连通远程机器):

Get-Service -Name Winmgmt -ComputerName $remoteComputer

3. 配置远程机器WMI权限

在远程机器上操作:

  • 按下Win+R输入wmimgmt.msc打开WMI控制
  • 右键「WMI控制(本地)」→「属性」→切换到「安全」标签
  • 展开Root → 选中CIMV2 → 点击「安全」按钮
  • 添加你用来远程访问的账户,勾选远程启用和读取权限,点击确定保存

4. 远程机器防火墙设置

在远程机器上开启WMI相关入站规则:

  • 打开「Windows Defender防火墙」→「高级设置」
  • 找到「入站规则」,启用以下规则:
    • Windows Management Instrumentation (WMI-In)
    • Windows Management Instrumentation (DCOM-In)

5. 指定远程凭据(跨账户访问时)

如果本地登录账户与远程机器账户不一致,需在Get-WmiObject命令中添加-Credential参数,指定远程机器上有权限的账户:

$cred = Get-Credential
$desktopInfo = Get-WmiObject -Class Win32_ComputerSystemProduct -ComputerName $remoteComputer -Credential $cred

执行后会弹出窗口让你输入远程机器的用户名和密码。


内容的提问来源于stack exchange,提问作者Aryaman Sharma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 07:20:17