简体   繁体   English

转换VBS脚本以将WMI类名称列表到Powershell

[英]Convert VBS Script to List WMI Class Names to Powershell

Basically I'd like to use Powershell to dump a list of all available classes in the root\\cimv2 namespace. 基本上我想使用Powershell转储root\\cimv2命名空间中所有可用类的列表。 I have a vbscript which accomplishes the task: 我有一个完成任务的vbscript:

Set objWMIService = _ 
   GetObject("winmgmts:{impersonationLevel=impersonate}root\cimv2")

Set colClasses = objWMIService.SubClassesOf

For Each objClass In colClasses
If Left(objClass.Path_.Class,6) = "Win32_" Then
   WScript.Echo objClass.Path_.Class
End If
Next

I've been able to get powershell to retrieve the list, but I can't seem to figure out how to get it to Write-Host the names. 我已经能够获得PowerShell来检索列表,但我似乎无法弄清楚如何将它Write-Host的名称。 This is where I'm at now: 这就是我现在所处的位置:

$WMIService = Get-WmiObject -Namespace root\cimv2 -List
$aClasses = $WMIService.SubClassesOf
foreach ($Class in $aClasses) {
    Write-Host $Class.Path_.Class
}

Powershell dumps a long list of nothing, so I know it's enumerated something. Powershell抛弃了一长串没有的东西,所以我知道它列举了一些东西。 I've tried all sorts of $Class.x and haven't hit the magic one yet. 我已经尝试过各种各样的$Class.x并且还没有尝试过那些神奇的。 Does anyone know? 有人知道吗?

Something similar to: 类似的东西:

$WMIService = Get-WmiObject -Namespace root\cimv2 -List
$WMIService | where { $_.Name -like "Win32_*" } | foreach { $_.Name }

Will get you what you're looking for, I think. 我想,会得到你想要的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM