forked from Call4cloud/Enrollment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefault_Enrollment.ps1
295 lines (225 loc) · 8.74 KB
/
Default_Enrollment.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
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
##############################################
#### Install required PowerShell Modules #####
##############################################
$PSModules = @("AzureADPreview","AzureAD","msonline","WindowsAutopilotIntune","MSAL.PS")
Foreach ($PSModule in $PSModules){
if (Get-Module -ListAvailable -Name $PSModule) {
Write-Host "$PSModule Module exists"
}
else {
Write-Host "$PSModule Module does not exist yet"
try {
Install-Module $PSModule -AllowClobber
Write-Host "$PSModule installed now"
}
catch {
Write-Host "$PSModule cannot be installed"
}
}
#### Import PowerShell Modules #####
if (Get-Module -Name $PSModule) {
Write-Host "$PSModule Module loaded"
}
else {
Write-Host "$PSModule Module not loaded yet"
try {
Import-Module $PSModule
Write-Host "$PSModule loaded now"
}
catch {
Write-Host "$PSModule cannot be loaded"
}
}
}
Install-PackageProvider -Name NuGet -Force
install-Module -Name PowerShellGet -Force -AllowClobber
$ScriptPath = $PSScriptRoot
if($ScriptPath -eq ""){
#$ScriptPath = "C:\Users\rudy.ooms\OneDrive - call4cloud\555 - MS365 Beta\Default Uitrol"
$ScriptPath = "C:\klant uitrollen"
}
Set-Location $ScriptPath
Import-Module ".\DU\functions\Test-JSON.ps1"
$JSONPath = "$ScriptPath\DU\JSON\"
$ADMXPath = "$ScriptPath\DU\ADMX"
$FunctionPath = "$ScriptPath\DU\functions"
if (Test-Path "$ScriptPath\DU\Packages"){
$PackagePath = "$ScriptPath\DU\Packages"
}
else{
$PackagePath = "C:\Packages"
}
$ChocoPackagePath = "$ScriptPath\DU\Packages\ChocolateyAppsInstall"
$Powershellscripts = "$ScriptPath\DU\scripts"
# Replacing quotes for Test-Path
$JSONPath = $JSONPath.replace('"','')
if(!(Test-Path "$JSONPath")){
Write-Host "Import Path for JSON file doesn't exist..." -ForegroundColor Red
Write-Host "Script can't continue..." -ForegroundColor Red
Write-Host
break
}
#### Ask Credentials ####
Write-Host "Customer name AzureAD van $klant " -ForegroundColor "Yellow" -NoNewline
$user = Read-Host
$Cred = Get-Credential $user
connect-msgraph -AdminConsent | Out-Null
############################
####Getting the tokens ####
############################
#token Intune Powershell
$RedirectUri = "urn:ietf:wg:oauth:2.0:oob"
$authResult = Get-MsalToken -ClientId 'd1ddf0e4-d672-4dae-b554-9d5bdfd93547' -Scopes 'https://graph.microsoft.com/.default' -RedirectUri $RedirectUri
$accesstoken1b = $authresult.accesstoken
$headers1b = @{
'Content-Type'='application/json'
'Authorization'="Bearer " + $accesstoken1b
'ExpiresOn'=$authResult.ExpiresOn
}
#token Azure PowerShell
$authResult = Get-MsalToken -ClientId '1950a258-227b-4e31-a9cf-717495945fc2' -Scopes 'https://graph.microsoft.com/.default'
$accesstoken1e = $authresult.accesstoken
$headers1e = @{
'Content-Type'='application/json'
'Authorization'="Bearer " + $accesstoken1e
'ExpiresOn'=$authResult.ExpiresOn
}
#token AzureRm
login-azurermaccount -Credential $Cred
$context = Get-AzureRmContext
$tenantId = $context.Tenant.Id
$SubscriptionId = $context.Subscription
$cache = $context.TokenCache
$cacheItem = $cache.ReadItems()
$refreshtoken=$cacheItem[$cacheItem.Count -1].refreshtoken
$body = "grant_type=refresh_token&refresh_token=$($refreshToken)&resource=74658136-14ec-4630-ad9b-26e160ff0fc6"
$apiToken = Invoke-RestMethod "https://login.microsoftonline.com/$tenantId/oauth2/token" -Method POST -Body $body -ContentType 'application/x-www-form-urlencoded'
$headersazurerm = @{
'Authorization' = 'Bearer ' + $apiToken.access_token
'Content-Type' = 'application/json'
'X-Requested-With'= 'XMLHttpRequest'
'x-ms-client-request-id'= [guid]::NewGuid()
'x-ms-correlation-id' = [guid]::NewGuid()
}
#Connect to graph and azuread
connect-azuread -Credential $Cred
$id = get-AzureADTenantDetail
$klant = $id.DisplayName
##################
#### Part 2 ####
##################
.\DU\DU2a_Create_Dynamic_Groups.ps1
########################
## Fetching Group ID's #
########################
$URL = "https://graph.microsoft.com/v1.0/groups?"
$Allgroups = (Invoke-RestMethod -Headers $headers1b -Uri $URL -Method GET).value
$group= $Allgroups | Where-Object -Property Displayname -Value "All windows devices" -eq
$allwindowsdevicesgroupid = $group.id
$group= $Allgroups | Where-Object -Property Displayname -Value "MS365BusinessLicences" -eq
$ms365licensegroupid = $group.id
$group= $Allgroups | Where-Object -Property Displayname -Value "autopilotstaticgroup" -eq
$autopilotstaticgroupid = $group.id
$group= $Allgroups | Where-Object -Property Displayname -Value "Exclude_Require_MDM_Managed_devices_Windows_Mac" -eq
$excluderequiremdmwindowsid = $group.id
$group= $Allgroups | Where-Object -Property Displayname -Value "Exclude_Require_MDM_Managed_devices_mobile_access" -eq
$excluderequiremdmmobileid = $group.id
$group= $Allgroups | Where-Object -Property Displayname -Value "Exclude_Require_MFA_Weblogin_Nonmanaged_devices" -eq
$exlcuderequiremfaid = $group.id
$group= $Allgroups | Where-Object -Property Displayname -Value "Exclude_Require_MAM_Approved_app_Exceptexchange" -eq
$excluderequireapprovedappexceptexchangepid = $group.id
$group= $Allgroups | Where-Object -Property Displayname -Value "Exclude_Require_MAM_Approved_app_Onlyexchange" -eq
$excludereapprovedapponlyexchangeid = $group.id
$group= $Allgroups | Where-Object -Property Displayname -Value "Exclude_Block_exchangeDownloads_Nonmanaged_devices" -eq
$excluderequiredownloadsexchangeid = $group.id
$group= $Allgroups | Where-Object -Property Displayname -Value "Exclude_Block_Legacy_Authenticatie" -eq
$excludeblocklegacyauthid = $group.id
$group= $Allgroups | Where-Object -Property Displayname -Value "Exclude_Block_Require_Trusted_Countries" -eq
$excludeblockcountriesid = $group.id
##### "ALL Users" groepID ophalen #####
$group= $Allgroups | Where-Object -Property Displayname -Value "Alle gebruikers" -eq
if ($group -eq ""){
$group= $Allgroups | Where-Object -Property Displayname -Value "all users" -eq
}
$allusersgroupid = $group.id
###################################
.\DU\DU2b_Create_Autopilot_Profiles.ps1
.\DU\DU2c_Autopilot_profile_assignment.ps1
.\DU\DU2d_Link_license_to_Group.ps1
#### CustomerName for the Dedicated Solarwinds app ####
$PackagePathCust = "$PackagePath\$klant"
#### Map Solarwinds aanmaken ####
New-Item -Path $PackagePathCust -Name "Solarwinds" -ItemType "directory" -force
#Make sure the Solarwinds Intune Win file exist in that folder!
.\DU\DU2e_Set_Intune_As_MDMAuthority.ps1
.\DU\DU2f_Config_Apple_MDM.ps1
.\DU\DU2g_Assign_Google_Apps.ps1
#### Android en IOS App Beveiligings/Configuratie beleid maken ####
.\DU\DU2h_AppProtectionPolicyUnmanagedDevices.ps1
.\DU\DU2h_AppProtectionPolicymanagedDevices.ps1
.\DU\DU2i_Create_Enrollment_Restrictions.ps1
##################
#### Part 3 ####
#################
#### Apps uploaden ######
# Windows10 Apps
.\DU\DU3b_Windows10_Upload_Basic_Apps.ps1
# iOS Apps
.\DU\DU3b_iOS_Upload_Basic_Apps.ps1
# Office365 Apps
.\DU\DU3b_Office365_Upload_Apps.ps1
# Edge App
.\DU\DU3b_Edge_Upload_App.ps1
# Chocolatey Apps
.\DU\DU3b_Chocolatey_Upload_Basic_Apps.ps1
#### Apps assignment ######
# Windows10 Apps
.\DU\DU3b_Windows10_Assign_Basic_Apps.ps1
# iOS Apps
.\DU\DU3b_iOS_Assign_Basic_Apps.ps1
# Chocolatey Apps
.\DU\DU3b_Chocolatey_Assign_Basic_Apps.ps1
.\DU\DU3b_Chocolatey_Assign_Large_Icons.ps1
#### Configure Enrollment Status page #####
.\DU\DU3c_Config_Enrollment_Status_Page.ps1
##################
#### Part 4 ####
##################
### Importing Administrative Templates ########
.\DU\DU4a_DeviceConfigurationADMX_Import_FromJSON.ps1
.\DU\Du4a_DeviceConfigurationADMX_Assignment.ps1
####### Importing Device Configurations #####
.\DU\Du4b_Windows10_ImportAllDeviceConfigs.ps1
.\DU\DU4b_AppConfigurationPolicy_ImportFromJSON.ps1
.\DU\DU4b_AppConfigurationPolicy_Assignment.ps1
###### Importing Powershellscripts ##############
.\DU\DU4c_Enroll_Windows10_Powershellscripts.ps1
#### Importing Firewall Rules ########
.\DU\DU4d_Windows10_firewallRules.ps1
##################
#### Part 5 ####
##################
.\DU\DU5_Import_Compliance_Policies.ps1
##################
#### Part 6 ####
##################
.\DU\DU6_Config_WindowsUpdate.ps1
##################
#### Part 7 ####
##################
.\DU\DU7_Config_WindowsHello.ps1
##################
#### Part 8 ####
##################
.\CA\DU8_Deploy_ConditionalAccessRules.ps1
##################
#### Part 9 ####
##################
####Securing Active Directory######
.\SL1\SL1_1.ps1
####Securing Configuring Exchange Online######
.\SL1\SL1_2.ps1
#####Change Sharepoint Settings ###########
.\SL1\SL1_3.ps1
#####Changing Teams and Commerce Settings######
.\SL1\SL1_4.ps1