feat: adapting to support CimSession and alternative namespaces
Signed-off-by: Sam Storie <sam.storie@emerson.com>
This commit is contained in:
parent
3cf0fa347f
commit
96e081c7d4
|
@ -2,19 +2,21 @@ Param(
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
$Class,
|
$Class,
|
||||||
[Parameter(Mandatory=$false)]
|
[Parameter(Mandatory=$false)]
|
||||||
|
$Namespace = "root/cimv2",
|
||||||
|
[Parameter(Mandatory=$false)]
|
||||||
$CollectorName = ($Class -replace 'Win32_PerfRawData_Perf',''),
|
$CollectorName = ($Class -replace 'Win32_PerfRawData_Perf',''),
|
||||||
[Parameter(Mandatory=$false)]
|
[Parameter(Mandatory=$false)]
|
||||||
$ComputerName = "localhost",
|
$ComputerName = "localhost",
|
||||||
[Parameter(Mandatory=$false)]
|
[Parameter(Mandatory=$false)]
|
||||||
$Credential
|
[CimSession] $Session
|
||||||
)
|
)
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
if($Credential -ne $null) {
|
if($null -ne $Session) {
|
||||||
$wmiObject = Get-CimInstance -ComputerName $ComputerName -Credential $Credential -Class $Class
|
$wmiObject = Get-CimInstance -CimSession $Session -Namespace $Namespace -Class $Class
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$wmiObject = Get-CimInstance -ComputerName $ComputerName -Class $Class
|
$wmiObject = Get-CimInstance -ComputerName $ComputerName -Namespace $Namespace -Class $Class
|
||||||
}
|
}
|
||||||
|
|
||||||
$members = $wmiObject `
|
$members = $wmiObject `
|
||||||
|
@ -22,6 +24,7 @@ $members = $wmiObject `
|
||||||
| Where-Object { $_.Definition -Match '^u?int' -and $_.Name -NotMatch '_' } `
|
| Where-Object { $_.Definition -Match '^u?int' -and $_.Name -NotMatch '_' } `
|
||||||
| Select-Object Name, @{Name="Type";Expression={$_.Definition.Split(" ")[0]}}
|
| Select-Object Name, @{Name="Type";Expression={$_.Definition.Split(" ")[0]}}
|
||||||
$input = @{
|
$input = @{
|
||||||
|
"Namespace"=$Namespace;
|
||||||
"Class"=$Class;
|
"Class"=$Class;
|
||||||
"CollectorName"=$CollectorName;
|
"CollectorName"=$CollectorName;
|
||||||
"Members"=$members
|
"Members"=$members
|
||||||
|
|
Loading…
Reference in New Issue