Scripts/get-smproperty.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
[CmdletBinding(DefaultParameterSetName="name")]
param ( 
    [Parameter(Position=0,ParameterSetName="name",Mandatory=$true)][string]$classname,
    [Parameter(Position=0,ParameterSetName="class",Mandatory=$true,ValueFromPipeline=$true)]
    [Microsoft.EnterpriseManagement.Configuration.ManagementPackClass]$class = $null,
    [Parameter()][string]$property = "*"
    )
PROCESS
{
if ( ! $class )
{
    $class = get-scsmclass $classname
    if ( $class -is [array] )
    {
        Write-Host -for RED "Too many classes, try again"
        $class | Write-host -for yellow
        exit
    }
    if ( ! $class )
    {
        Write-Host -for RED "$classname not found, try again"
        exit
    }
}
if ( $class.Abstract )
{
    $class.PropertyCollection|sort name -uniq
    $class.GetBaseTypes()|%{$_.propertycollection}|sort name -uniq
}
else
{
#$EMOT = "Microsoft.EnterpriseManagement.Common.CreatableEnterpriseManagementObject"
#$emo = new-object $EMOT $class.ManagementGroup,$class
# $emo.getproperties()|%{$_}|
$class.GetProperties("recursive")|add-member -pass NoteProperty Class $class | 
    where-object { $_.name -like "$property" } |
    sort name -uniq
}
}