-
-
Notifications
You must be signed in to change notification settings - Fork 543
/
wmic.ps1
36 lines (31 loc) · 918 Bytes
/
wmic.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
param(
[string]$Namespace,
[string]$Class,
[string]$Filter,
[string]$Properties
)
$propertiesToDisplay = if ($Properties) { $Properties.Split(",") } else { @("*") }
$wmiQuery = @{
Namespace = $Namespace
Class = $Class
}
if ($Filter) {
$wmiQuery.Filter = $Filter
}
Get-WmiObject @wmiQuery | ForEach-Object {
$_.PSObject.Properties | Where-Object {
-not $_.Name.StartsWith("__") -and
($propertiesToDisplay -contains $_.Name -or $propertiesToDisplay -contains "*")
} | ForEach-Object {
$name = $_.Name
$value = $_.Value
# 改成 wmic 的输出格式
if ($value -is [Array]) {
$formattedValue = ($value | ForEach-Object { "`"$_`"" }) -join ","
Write-Output "$name={$formattedValue}"
}
else {
Write-Output "$name=$value"
}
}
}