-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-IntuneADMXURI.ps1
199 lines (165 loc) · 6.93 KB
/
Get-IntuneADMXURI.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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<#
.Synopsis
Reads ADMX files and outputs all of the possible OMA-URI Settings you can set with it.
.DESCRIPTION
Easily convert ADMX files into OMA-URI for Microsoft Intune. Feed this script a admx file and it will output all of the OMI-URI and the options available for each setting.
.EXAMPLE
.\Get-IntuneOMAURI.ps1 -ADMXFile 'C:\temp\admx template\GoogleChrome.admx -AppName GoogleChrome
This example pulls in the GoogleChrome.admx file and will open a grid view of all the settings afterwards.
The AppName helps create the ADMX Ingestion URI.
#>
Param(
[Parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[ValidateScript({
if (-not ($_ | Test-Path)) {
throw "File not Found. Check the file path you speicfied"
}
return $true
})]
[System.IO.FileInfo]$ADMXFile,
[Parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$AppName,
[Parameter (Mandatory=$false)]
[ValidateNotNullorEmpty()]
[switch]$CsvExport = $false
)
# Results storage
$results = @()
# Lets build out the OMA-URI for Ingesting the ADMX file
$admxIngestionURI = "./Device/Vendor/MSFT/Policy/ConfigOperations/ADMXInstall/{0}/Policy/{1}" -f $AppName,"$($AppName)Admx"
$settingURI = "Vendor/MSFT/Policy/Config/{0}~Policy<category>/" -f $AppName
# Prep the ADMX file for parsing
[xml]$admxData = Get-Content $ADMXFile
$categories = $admxData.policyDefinitions.categories.category
# Need to build out Categories to be able to build the setting OMA-URI properly
foreach ($policy in $admxData.policyDefinitions.policies.policy) {
# Identify Scope of the Policy
# Machine, Device, User, or Both
switch -Regex ($policy.class) {
'User' {
$policyScope = 'User'
}
'Device|Machine' {
$policyScope = 'Device'
}
'Both' {
$policyScope = @(
'User',
'Device'
)
}
}
# Create Policy OMA-URI
$policyOmaUri = $policyScope | Foreach-Object { "./$_/$($settingURI.Replace('<category>',$policyCategoryURI))$($policy.name)" }
# building OMA-URI for this policy
[string]$policyCategoryURI = "~$($policy.ParentCategory.ref)"
while ($true) {
if (($categories | Where-Object {$_.Name -eq $policyCategoryURI.Split('~')[1]}).PSObject.Properties.name -match "parentCategory" ) {
# The current category has a parent
$policyCategoryURI = "~$(($categories | Where-Object {$_.Name -eq $policyCategoryURI.Split('~')[1]}).parentCategory.ref)$policyCategoryURI"
}
else {
# No more parents exist break the loop
break
}
} # end Build OMA-URI Setting
if ($null -ne $policy.enabledList) {
# Take a look at the Enabled/Disable policies
$results += [PSCustomObject]@{
Name = $policy.name
"OMA-URI" = $policyOmaUri | Out-String
Setting = "<enabled/> OR <disabled/>"
}
continue
}
# If the setting only contains elements
elseif ($null -ne $policy.elements) {
foreach ($element in $policy.elements) {
# Check the Type of Element
switch ($element.PSobject.Properties.name) {
'enum' {
# Basically a list of options
[string]$enumSetting = ""
switch (($element.enum.item.value | Get-Member | Where-Object {$_.MemberType -eq 'Property'}).Name) {
'string' {
foreach ($item in $element.enum.item.value.string) {
$enumSetting += "<enabled/> <data id=$($element.enum.id) -value `"$($item)`"/>`n"
}
}
'decimal' {
foreach ($item in $element.enum.item.value.decimal.value) {
$enumSetting += "<enabled/> <data id=$($element.enum.id) -value `"$($item)`"/>`n"
}
}
}
$results += [PSCustomObject]@{
Name = $policy.name
"OMA-URI" = $policyOmaUri | Out-String
Setting = $enumSetting
}
} # end enum
'decimal' {
# A simple numeric option that limits
# Check if there are limits on the decimal
if ($null -eq $element.decimal.minValue) {
$results += [PSCustomObject]@{
Name = $policy.name
"OMA-URI" = $policyOmaUri | Out-String
Setting = "<enabled/> <data id=$($element.decimal.id) value=`"<!-- Max Value of: $($element.decimal.maxValue) -->`"/>`n"
}
}
elseif ($null -eq $element.decimal.maxValue) {
$results += [PSCustomObject]@{
Name = $policy.name
"OMA-URI" = $policyOmaUri | Out-String
Setting = "<enabled/> <data id=$($element.decimal.id) value=`"<!-- Min Value of: $($element.decimal.minValue) -->`"/>`n"
}
}
else {
$results += [PSCustomObject]@{
Name = $policy.name
"OMA-URI" = $policyOmaUri | Out-String
Setting = "<enabled/> <data id=$($element.decimal.id) value=`"<!-- Value Range: $($element.decimal.minValue)-$($element.decimal.maxValue) -->`"/>`n"
}
}
} # end decimal
'text' {
# Need to check if the Max Length is set
if ($null -eq $element.text.maxLength) {
$results += [PSCustomObject]@{
Name = $policy.name
"OMA-URI" = $policyOmaUri | Out-String
Setting = "<enabled/> <data id=$($element.text.id) value=`"<!-- [String] -->`"/>`n"
}
}
else {
$results += [PSCustomObject]@{
Name = $policy.name
"OMA-URI" = $policyOmaUri | Out-String
Setting = "<enabled/> <data id=$($element.text.id) value=`"<!-- [String] Max Length: $($element.text.maxLength) -->`"/>`n"
}
}
} # end text
} # end element switch
} # end foreach element
} # end if element
# Simple Enable only setting
else {
# elements, enableList, and disableList properties are not present, this is simply an enable rule
$results += [PSCustomObject]@{
Name = $policy.name
"OMA-URI" = $policyOmaUri | Out-String
Setting = "<enabled/>"
}
continue
} # End simple Enable Setting
} # end foreach Policy
# Output ADMX Ingestion OMA-URI
$admxIngestionURI | Out-File -FilePath "$PSScriptRoot\$AppName-ADMX-Ingestion-OMA-URI.txt" -Force
if ($CsvExport) {
$results | Export-Csv -Path "$PSScriptRoot\$AppName-ADMX-Intune-Settings.csv" -NoTypeInformation -Force
} else {
$results | Out-GridView
}