forked from brianary/scripts
-
Notifications
You must be signed in to change notification settings - Fork 14
/
ConvertFrom-CimInstance.ps1
40 lines (34 loc) · 1.21 KB
/
ConvertFrom-CimInstance.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
37
38
39
40
<#
.SYNOPSIS
Convert a CimInstance object to a PSObject.
.INPUTS
Microsoft.Management.Infrastructure.CimInstance to convert to a PSObject.
.OUTPUTS
PSObject converted from the CimInstance entered.
.FUNCTIONALITY
Scheduled Tasks
.EXAMPLE
$tasks = Get-ScheduledTask |ConvertFrom-CimInstance.ps1
Gets the scheduled tasks as PSObjects that support tab completion and can be serialized and exported.
#>
#Requires -Version 3
[CmdletBinding()][OutputType([Management.Automation.PSCustomObject])] Param(
# The CimInstance object to convert to a PSObject.
[Parameter(Position=0,ValueFromPipeline=$true)]
[Microsoft.Management.Infrastructure.CimInstance] $InputObject
)
Process
{
$value = [ordered]@{'#CimClassName' = $InputObject.CimClass.CimClassName}
foreach($name in $InputObject.CimClass.CimClassProperties)
{
if($null -eq $InputObject.$name) {continue}
switch($InputObject.CimInstanceProperties[$name].CimType)
{
Instance {$value[$name] = $InputObject.$name |ConvertFrom-CimInstance.ps1}
InstanceArray {$value[$name] = [psobject[]]@($InputObject.$name |ConvertFrom-CimInstance.ps1)}
default {$value[$name] = $InputObject.$name}
}
}
[pscustomobject]$value
}