Powershell 6的哪个库包含get-wmiobject命令? [英] What Library for Powershell 6 contains the get-wmiobject command?

查看:397
本文介绍了Powershell 6的哪个库包含get-wmiobject命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在PowerShell(版本6)中使用get-WmiObject命令时收到以下错误:

I am getting the following error upon attempting to use the get-WmiObject command in PowerShell (version 6):

PS C:\Users\zsofi> Get-WmiObject Win32_product | select name, packagecache

Get-WmiObject : The term 'Get-WmiObject' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-WmiObject Win32_product | select name, packagecache
+ ~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Get-WmiObject:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException`

推荐答案

Gert Jan Kraaijeveld的有用答案为确实只有在 Windows PowerShell 中才可用的cmdlet(在PowerShell [Core] 6+以上版本中也没有).

Gert Jan Kraaijeveld's helpful answer offers a solution for cmdlets that truly are available only in Windows PowerShell (not also in PowerShell [Core] 6+).

但是,在这种特殊情况下,正如Lee_Daily在评论中指出的那样,您可以使用

In this particular case, however, as Lee_Daily notes in a comment, you can use the
Get-CimInstance cmdlet
, which is available in PowerShell [Core] 6+ too:

Get-CimInstance CIM_Product | Select-Object Name, PackageCache

注意CIM_Product类名称; CIM类通常与WMI Win32_*对应类具有相同的属性.

Note the CIM_Product class name; CIM classes typically have the same properties as their WMI Win32_* counterparts.

在PowerShell Core 中,所有将来的开发工作都将投入使用,CIM cmdlet是您唯一的选择,但即使在 Windows PowerShell ,因为 WMI(*-Wmi*)cmdlet在PowerShell版本3()(于2012年9月发布)中已被弃用.引入了CIM cmdlet;从 Get-CimInstance文档 :

In PowerShell Core, where all future development effort will go, the CIM cmdlets are your only option, but it is advisable to use the CIM (*-Cim*) cmdlets even in Windows PowerShell, because the WMI (*-Wmi*) cmdlets were deprecated in PowerShell version 3 (released in September 2012), when the CIM cmdlets were introduced; from the Get-CimInstance docs:

从Windows PowerShell 3.0开始,此cmdlet已被Get-CimInstance取代.

对于 为什么 CIM cmdlet是更好的选择(引自

As for why the CIM cmdlets are the better choice (quoted from this TechNet blog post):

WMI cmdlet的最大缺点是它们使用DCOM访问远程计算机. DCOM对防火墙不友好,可以被网络设备阻止,并在出现问题时发出一些不可思议的错误.

The big drawback to the WMI cmdlets is that they use DCOM to access remote machines. DCOM isn’t firewall friendly, can be blocked by networking equipment, and gives some arcane errors when things go wrong.

同一篇博客文章还描述了CIM cmdlet的方式:

The same blog post also describes how the CIM cmdlets:

  • use the same standards-based remoting mechanism as PowerShell itself (WS-Management, via its Windows implementation, WinRM)

  • 也就是说,设置用于PowerShell远程处理的计算机(请参阅

  • That is, computers that are set up for PowerShell remoting (see about_Remote_Requirements) implicitly support targeting via the CIM cmdlets.

但是,您仍然可以使用

However, you can still use the DCOM protocol (like the WMI cmdlets did) on an opt-in basis, using the New-CimSessionOption cmdlet.

支持会话

功能与过时的WMI对应器稍有不同,因为返回的对象没有直接使用方法的方法; 方法必须通过 Invoke-CimMethod .

function slightly differently than their obsolete WMI counterparts in that the objects returned do not have methods directly; methods must be called via Invoke-CimMethod.

这篇关于Powershell 6的哪个库包含get-wmiobject命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆