xml/puppet.dsc.Types.ps1xml

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?xml version="1.0" encoding="utf-8"?>
<Types>
  <Type>
    <Name>Microsoft.PowerShell.DesiredStateConfiguration.DscResourceInfo</Name>
    <Members>
      <ScriptProperty>
        <Name>provider_name</Name>
        <GetScriptBlock>
          [string]$first = $this.name.Substring(0,1)
          $first.ToUpperInvariant() + $this.name.ToLowerInvariant().Substring(1)
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>relative_mof_path</Name>
        <GetScriptBlock>
          if($this.Path.Contains('WINDOWS\system32\WindowsPowershell\v1.0\Modules')){
            (Split-Path $this.Path -NoQualifier).Replace('\WINDOWS\system32\WindowsPowershell\v1.0\Modules\', '')
          }else{
            $this.Path.Replace('import/dsc_resources/','')
          }
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>allowed_properties</Name>
        <GetScriptBlock>
          $this.properties | ? { $_.name -notmatch '(dependson|waitfor.*)' }
        </GetScriptBlock>
      </ScriptProperty>
    </Members>
  </Type>
  <Type>
    <Name>Microsoft.PowerShell.DesiredStateConfiguration.DscResourcePropertyInfo</Name>
    <Members>
      <ScriptProperty>
        <Name>description</Name>
        <GetScriptBlock>
          "TODO!!!"
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>ShortType</Name>
        <GetScriptBlock>
          $text = $this.PropertyType.TrimStart('[')
          if($text.EndsWith(']]')){
            $text = $text.Replace(']]',']')
          }else{
            $text = $text.TrimEnd(']')
          }
          $text
        </GetScriptBlock>
      </ScriptProperty>
      <ScriptProperty>
        <Name>Type</Name>
        <GetScriptBlock>
          if($this.values){
            $typeText = "Enum[$( ($this.Values | % { "'$($_.ToLowerInvariant())'" }) -join `", `" )]"
          }else{
            if($this.embeddedinstance){
              $typeText = 'String'
            }else{
              $typeText = switch ($this.PropertyType.TrimStart('[').TrimEnd(']')){
                'Bool' { 'Boolean';break; }
                'String' { 'String';break; }
                default {
                  $text = $this.PropertyType.TrimStart('[')
                  if($text.EndsWith(']]')){
                    $text = $text.Replace(']]',']')
                  }else{
                    $text = $text.TrimEnd(']')
                  }
                  (Get-Culture).TextInfo.ToTitleCase($Text)
                }
              }
            }
          }
 
          if($this.array){
            $typeText = "Array[$($typeText)]"
          }
 
          if($this.credential){
            $typeText = "Struct[{ user => String[1], password => String[1] }]"
          }
 
          switch($this.IsMandatory){
            $true {
              '"', $typeText, '"' -Join ''
            }
            $false{
              "`"Optional[$($typeText)]`""
            }
          }
        </GetScriptBlock>
      </ScriptProperty>
      <AliasProperty>
        <Name>required</Name>
        <ReferencedMemberName>IsMandatory</ReferencedMemberName>
      </AliasProperty>
      <ScriptProperty>
        <Name>embeddedinstance</Name>
        <GetScriptBlock>
$EmbeddedInstances = @{
  "Hashtable" = "MSFT_KeyValuePair";
  "PSCredential" = "MSFT_Credential";
  "Hashtable[]" = "MSFT_KeyValuePair";
  "PSCredential[]" = "MSFT_Credential";
  "HashtableArray" = "MSFT_KeyValuePair";
  "PSCredentialArray" = "MSFT_Credential";
}
$basetypes = @(
"[Uint8","[Uint16]","[Uint32]","[Uint64]",`
"[Sint8]","[Sint16]","[Sint32]","[Sint64]",`
"[Real32]","[Real64]","[Char16]","[String]",`
"[bool]","[Boolean]","[DateTime]","[Hashtable]",`
"[PSCredential]",`
"[Uint8[]]","[Uint16[]]","[Uint32[]]","[Uint64[]]",`
"[Sint8[]]","[Sint16[]]","[Sint32[]]","[Sint64[]]",`
"[Real32[]]","[Real64[]]","[Char16[]]","[String[]]",`
"[Boolean[]]","[DateTime[]]","[Hashtable[]]",`
"[PSCredential[]]",`
"Microsoft.Management.Infrastructure.CimInstance",`
"Microsoft.Management.Infrastructure.CimInstance[]"
        )
        if($basetypes -contains $this.PropertyType){
          return $false
        }else{
          return $true
        }
        </GetScriptBlock>
      </ScriptProperty>
    </Members>
  </Type>
</Types>