2016-09-24 09:49:09 +00:00
|
|
|
Param(
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
|
|
$Class,
|
|
|
|
[Parameter(Mandatory=$false)]
|
2021-12-06 19:57:23 +00:00
|
|
|
$Namespace = "root/cimv2",
|
|
|
|
[Parameter(Mandatory=$false)]
|
2017-03-03 13:55:11 +00:00
|
|
|
$CollectorName = ($Class -replace 'Win32_PerfRawData_Perf',''),
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
|
|
$ComputerName = "localhost",
|
|
|
|
[Parameter(Mandatory=$false)]
|
2021-12-06 19:57:23 +00:00
|
|
|
[CimSession] $Session
|
2016-09-24 09:49:09 +00:00
|
|
|
)
|
2017-03-03 13:55:11 +00:00
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
2021-12-06 19:57:23 +00:00
|
|
|
if($null -ne $Session) {
|
|
|
|
$wmiObject = Get-CimInstance -CimSession $Session -Namespace $Namespace -Class $Class
|
2017-03-03 13:55:11 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-12-06 19:57:23 +00:00
|
|
|
$wmiObject = Get-CimInstance -ComputerName $ComputerName -Namespace $Namespace -Class $Class
|
2017-03-03 13:55:11 +00:00
|
|
|
}
|
|
|
|
|
2019-08-01 15:00:42 +00:00
|
|
|
$members = $wmiObject `
|
2016-09-24 09:49:09 +00:00
|
|
|
| Get-Member -MemberType Properties `
|
|
|
|
| Where-Object { $_.Definition -Match '^u?int' -and $_.Name -NotMatch '_' } `
|
2020-02-24 04:51:58 +00:00
|
|
|
| Select-Object Name, @{Name="Type";Expression={$_.Definition.Split(" ")[0]}}
|
2016-09-24 09:49:09 +00:00
|
|
|
$input = @{
|
2021-12-06 19:57:23 +00:00
|
|
|
"Namespace"=$Namespace;
|
2016-09-24 09:49:09 +00:00
|
|
|
"Class"=$Class;
|
|
|
|
"CollectorName"=$CollectorName;
|
|
|
|
"Members"=$members
|
2019-08-01 15:01:33 +00:00
|
|
|
} | ConvertTo-Json
|
2016-09-24 09:49:09 +00:00
|
|
|
$outFileName = "..\..\collector\$CollectorName.go".ToLower()
|
|
|
|
$input | .\collector-generator.exe | Out-File -NoClobber -Encoding UTF8 $outFileName
|
|
|
|
go fmt $outFileName
|