forked from Micke-K/IntuneManagement
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMDM_MAM.psm1
More file actions
224 lines (179 loc) · 6.4 KB
/
MDM_MAM.psm1
File metadata and controls
224 lines (179 loc) · 6.4 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
########################################################
#
# Common module functions
#
########################################################
function Add-ModuleMenuItems
{
Add-MenuItem (New-Object PSObject -Property @{
Title = (Get-MDMMAMName)
MenuID = "IntuneGraphAPI"
Script = [ScriptBlock]{Get-MDMMAM}
})
}
function Get-SupportedImportObjects
{
$global:importObjects += (New-Object PSObject -Property @{
Selected = $true
Title = (Get-MDMMAMName)
Script = [ScriptBlock]{
param($rootFolder)
Write-Status "Import all MDM/MAM setting"
Import-AllMDMMAMObjects (Join-Path $rootFolder (Get-MDMMAMFolderName))
}
})
}
function Get-SupportedExportObjects
{
$global:exportObjects += (New-Object PSObject -Property @{
Selected = $true
Title = (Get-MDMMAMName)
Script = [ScriptBlock]{
param($rootFolder)
Write-Status "Export all MDM/MAM settings"
Get-MDMMAMObjects | ForEach-Object { Export-SingleMDMMAM $PSItem.Object (Join-Path $rootFolder (Get-MDMMAMFolderName)) }
}
})
}
function Export-AllObjects
{
param($addObjectSubfolder)
$subFolder = ""
if($addObjectSubfolder) { $subFolder = Get-MDMMAMFolderName }
}
########################################################
#
# Object specific functions
#
########################################################
function Get-MDMMAMName
{
return "MDM/MAM"
}
function Get-MDMMAMFolderName
{
return "MDMMAM"
}
function Get-MDMMAM
{
Write-Status "Loading MDM/MAM object"
$dgObjects.ItemsSource = @(Get-MDMMAMObjects)
#Scriptblocks that will perform the export tasks. empty by default
$script:exportParams = @{}
$script:exportParams.Add("ExportAllScript", [ScriptBlock]{
Export-AllMDMMAM $global:txtExportPath.Text
Set-ObjectGrid
Write-Status ""
})
$script:exportParams.Add("ExportSelectedScript", [ScriptBlock]{
Export-SelectedMDMMAM $global:txtExportPath.Text
Set-ObjectGrid
Write-Status ""
})
#Scriptblock that will perform the import all files
$script:importAll = [ScriptBlock]{
Import-AllMDMMAMObjects $global:txtImportPath.Text
Set-ObjectGrid
}
#Scriptblock that will perform the import of selected files
$script:importSelected = [ScriptBlock]{
Import-MDMMAMObjects $global:lstFiles.ItemsSource -Selected
Set-ObjectGrid
}
#Scriptblock that will read json files
$script:getImportFiles = [ScriptBlock]{
Show-FileListBox
$global:lstFiles.ItemsSource = @(Get-JsonFileObjects $global:txtImportPath.Text -Exclude "*_Settings.json")
}
Add-DefaultObjectButtons -export ([scriptblock]{Show-DefaultExportGrid @script:exportParams}) -import ([scriptblock]{Show-DefaultImportGrid -ImportAll $script:importAll -ImportSelected $script:importSelected -GetFiles $script:getImportFiles}) -ViewFullObject ([scriptblock]{Get-MDMMAMObject $global:dgObjects.SelectedItem.Object})
}
function Get-MDMMAMObjects
{
Get-AzureNativeObjects "MdmApplications" -property @('appDisplayName')
}
function Get-MDMMAMObject
{
param($object, $additional = "")
if(-not $Object.objectId) { return }
Invoke-AzureNativeRequest "/MdmApplications/$($Object.objectId)$additional"
}
function Export-AllMDMMAM
{
param($path = "$env:Temp")
if(-not (Test-Path $path)) { mkdir -Path $path -Force -ErrorAction SilentlyContinue | Out-Null }
if(Test-Path $path)
{
foreach($objTmp in ($global:dgObjects.ItemsSource))
{
Export-SingleMDMMAM $objTmp.Object $path
}
}
}
function Export-SelectedMDMMAM
{
param($path = "$env:Temp")
Export-SingleMDMMAM $global:dgObjects.SelectedItem.Object $path
}
function Export-SingleMDMMAM
{
param($psObj, $path = "$env:Temp")
if(-not $psObj) { return }
if($global:runningBulkExport -ne $true)
{
if($global:chkAddCompanyName.IsChecked) { $path = Join-Path $path $global:organization.displayName }
if($global:chkAddObjectType.IsChecked) { $path = Join-Path $path (Get-MDMMAMFolderName) }
}
if(-not (Test-Path $path)) { mkdir -Path $path -Force -ErrorAction SilentlyContinue | Out-Null }
if(Test-Path $path)
{
Write-Status "Export $($psObj.appDisplayName)"
$obj = Invoke-AzureNativeRequest "MdmApplications/$($psObj.objectId)"
if($obj)
{
$fileName = "$path\$((Remove-InvalidFileNameChars $obj.appDisplayName)).json"
ConvertTo-Json $obj -Depth 5 | Out-File $fileName -Force
}
if($obj.mdmAppliesToGroups)
{
$obj.mdmAppliesToGroups | ForEach-Object { Add-GroupMigrationObject $PSItem.objectId }
}
if($obj.mamAppliesToGroups)
{
$obj.mamAppliesToGroups | ForEach-Object { Add-GroupMigrationObject $PSItem.objectId }
}
$global:exportedObjects++
}
}
function Import-MDMMAM
{
param($obj)
$argStr = "?"
if($obj.enrollmentUrl) { $argStr += "mdmAppliesToChanged=true" }
else{ $argStr += "mdmAppliesToChanged=false" }
if($obj.mamEnrollmentUrl) { $argStr += "&mamAppliesToChanged=true" }
else{ $argStr += "&mamAppliesToChanged=false" }
$response = Invoke-AzureNativeRequest "MdmApplications/$($obj.objectId)$argStr" -Method PUT -Body (Update-JsonForEnvironment (ConvertTo-Json $obj -Depth 5))
}
function Import-AllMDMMAMObjects
{
param($path = "$env:Temp")
Import-MDMMAMObjects (Get-JsonFileObjects $path)
}
function Import-MDMMAMObjects
{
param(
$Objects,
[switch]
$Selected
)
Write-Status "Import MDM/MAM settings"
foreach($obj in $objects)
{
if($Selected -and $obj.Selected -ne $true) { continue }
Write-Log "Import MDM/MAM app settings: $($obj.Object.appDisplayName)"
Import-MDMMAM $obj.Object
# No assignments for MDM/MAM
}
$dgObjects.ItemsSource = @(Get-MDMMAMObjects)
Write-Status ""
}