-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkioskMDM.ps1
168 lines (111 loc) · 3.89 KB
/
kioskMDM.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
function PrintCfg
{
Get-CimInstance -Namespace "root\cimv2\mdm\dmmap" -ClassName "MDM_AssignedAccess"
}
function ApplyCfg
{
$aacsp = Get-CimInstance -Namespace "root\cimv2\mdm\dmmap" -ClassName "MDM_AssignedAccess"
Write-Host "`n1) Multi App`n2) Shell Launcher"
$type = $Host.Ui.ReadLine()
if ($type -ne 1 -and $type -ne 2)
{
Write-Host "Invalid Input"
ApplyCfg
}
else
{
try
{
$escXML = Get-XML
}
catch
{
Write-Host "`n"$_ -ForeGroundColor DarkRed
break
}
if ($type -eq 1)
{
$aacsp.Configuration = $escXML
}
elseif ($type -eq 2)
{
$prodname = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ProductName
if ($prodname -like "*Enterprise*" -or $prodname -like "*Education*")
{
$aacsp.ShellLauncher = $escXML
}
else
{
Write-Host "Only Windows 10 Enterprise or Education are licensed to use Shell Launcher. You are currently using " $prodname -ForegroundColor DarkRed
break
}
}
Set-CimInstance -CimInstance $aacsp
Write-Host "`nThe current configuration is:"
PrintCfg
}
}
function ClearCfg
{
$count = 0
$aacsp = Get-CimInstance -Namespace "root\cimv2\mdm\dmmap" -ClassName "MDM_AssignedAccess"
if ($aacsp.Configuration)
{
$aacsp.Configuration = $NULL
Set-CimInstance -CimInstance $aacsp
Write-Host "Multi-App Kiosk Configuration cleared"
$count++
}
if ($aacsp.ShellLauncher)
{
$aacsp.ShellLauncher = $NULL
Set-CimInstance -CimInstance $aacsp
Write-Host "Shell Launcher Configuration cleared"
$count++
}
if ($count -eq 0)
{
Write-Host "No Multi-App or Shell Launcher Configuration found on present machine"
}
}
function ExtractCfg
{
$count = 0
$aacsp = Get-CimInstance -Namespace "root\cimv2\mdm\dmmap" -ClassName "MDM_AssignedAccess"
if ($aacsp.Configuration)
{
$XML = [xml]($aacsp.Configuration)
Format-XML $XML -indent 4 >> .\extractedMultiApp.xml
Write-Host "Found Multi-App Kiosk, saving configuration as extractedMultiApp.xml"
$count++
}
if ($aacsp.ShellLauncher)
{
$XML = [xml]($aacsp.ShellLauncher)
Format-XML $XML -indent 4 >> .\extractedShellLauncher.xml
Write-Host "Found Shell Launcher, saving configuration as extractedShellLauncher.xml"
$count++
}
if ($count -eq 0)
{
Write-Host "No Multi-App or Shell Launcher Configuration found on present machine"
}
}
function Get-XML
{
$Path = Read-Host "Enter the path to XML File"
$XML = Get-Content -Path $Path -ErrorAction Stop
$escXML = [System.Security.SecurityElement]::Escape($XML)
return $escXML
}
function Format-XML ([xml]$xml, $indent=2) #from https://devblogs.microsoft.com/powershell/format-xml/
{
$StringWriter = New-Object System.IO.StringWriter
$XmlWriter = New-Object System.XMl.XmlTextWriter $StringWriter
$xmlWriter.Formatting = “indented”
$xmlWriter.Indentation = $Indent
$xml.WriteContentTo($XmlWriter)
$XmlWriter.Flush()
$StringWriter.Flush()
return $StringWriter.ToString()
}