Repository navigation
Expand file tree
/
Copy pathWindows10Setup.ps1
More file actions
607 lines (524 loc) · 23.1 KB
/
Copy pathWindows10Setup.ps1
File metadata and controls
607 lines (524 loc) · 23.1 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
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
<#
.SYNOPSIS
Configures popular settings on a workstation for first time use
.DESCRIPTION
This script can be used to remove built in windows 10 apps,Export a Custome Start Menu config file,Import a default start menu config file,
Disable OneDrive, Disbale Cortana, Disable Hibernate, Join a workstation to a domain, Rename the workstation, Set the page file size, Disable Windows Tips,
Disable the Consumer experience and Disable the Xbox Services.
.PARAMETER RemoveApps
Use this switch enable app removal
.PARAMETER AppsToRemove
Specifyes the list of apps to be removed, if not used then will use a list of apps built into the script
.PARAMETER Preset
The preset parameter will run the script with specific settings
CleanOS - Disables Ads, Widnows Store, Consumer Experience, Windows Tip, Cortana, Xbox Services, and OneDrive. Sets the page file removes all most all apps
EveryDayUser - Disables Ads, Removes all most all apps and Sets the page file size
.PARAMETER StartMenuLayout
Specifyes the xml file for the start menu layout
.PARAMETER ExportStartMenuLayout
Exports the curent start menu layout to be used on other workstation
.PARAMETER DisableAds
Disables all ads and sujected apps from the start menu, explorer, and lock screen
.PARAMETER DisableOneDrive
Disables OneDrive on the workstation
.PARAMETER DisableCortana
Disables Cortana on the workstation
.PARAMETER DisableHibernate
Disables the hibernate power setting
.PARAMETER SetPowerConfig
Sets the power settings by defult I have this set to disable standby and Disk Timeout
.PARAMETER DisableWindowsStore
Disables access to the Windows Store, The app is still listed
.PARAMETER DisableConsumerExperience
Disables The installation of extra apps and the pinning of links to Windows Store pages of third-party applications
.PARAMETER SetWiredAutoConfigService
Seting this service will disable the wired ethernet card when wirless is in use and disables the wireless when the ethernet card is in use.
.PARAMETER JoinDomain
Joins the computer to a domain
.PARAMETER Account
Account used to join to a domain, if not specified you will be asked for the account
.PARAMETER Domain
Domain to join when the JoinDomain Parameter is used, if not specified you will be asked for the domain
.PARAMETER RenameComputer
Renames the workstation to what is specified for the parameter
.PARAMETER SetPageFile
Sets the page file size to the recomended ammount based on the ammount of memmory installed on the device
.PARAMETER PageFileDrive
Moves the page file to a new drive, if not specified will default to the C drive
.PARAMETER Reboot
Reboots the computer after all other taskes have been performed
.EXAMPLE
.\Win10Setup.ps1 -RemoveApps -AppsToRemove AppsList.txt
Removes all apps in the AppsList.txt file
.EXAMPLE
.\Win10Setup.ps1 -StartMenuLayout StartMenuLayout.xml
Imports the xml file to use as the default start menu layout for all new users
To build your xml run Export-StartLayout -Path "C:\example\StartMenuLayout.xml"
.EXAMPLE
.\Win10Setup.ps1 -StartMenuLayout StartMenuLayout.xml -RemoveApps -AppsToRemove AppsToRemove.txt -DisableOneDrive -DisableCortana
Imports the start menu config removes apps listed in the txt file disbales one drive and cortana.
.NOTES
Created By: Kris Gross
Contact: Krisgross@sccmtst.com
Twitter: @kmgamd
Version 2.1.0.2
.LINK
You can get updates to this script and others from here
http://www.sccmtst.com/
#>
Param(
[Switch]$RemoveApps,
[string]$AppsToRemove,
[string]$StartMenuLayout,
[Switch]$SetPageFile,
$PageFileDrive,
[Switch]$EnableRDP,
[Switch]$DisableOneDrive,
[Switch]$DisableCortana,
[Switch]$DisableWindowsTips,
[Switch]$DisableConsumerExperience,
[Switch]$DisableHibernate,
[Switch]$SetPowerConfig,
[Switch]$DisableXboxServices,
[Switch]$DisableAds,
[Switch]$DisableWindowsStore,
[Switch]$DisableConnectToInternetUpdates,
[ValidateSet('Mountain Standard Time','Pacific Standard Time','Eastern Standard Time','Central Standard Time')]
$SetTimeZone,
[Switch]$InstallDC,
[Switch]$JoinDomain,
[string]$Account,
[string]$Domain,
[string]$RenameComputer,
[ValidateSet('CleanOS','EveryDayUser','DomainComputerSetup')]
$Preset,
[Switch]$ExportStartMenuLayout,
[Switch]$Reboot
)
function Read-Error
{
Write-Error "$ErrorText"
exit
}
Function Export-StartMenuLayout
{
$ExportFile = Read-Host "Export Config Name (Must be a XML file)"
Export-StartLayout -Path "$PSScriptRoot\$ExportFile"
Write-Host "Config Saved To: $PSScriptRoot\$ExportFile"
}
Function Import-StartMenuLayout
{
Param
(
[ValidateSet('Blank','Admin','EveryDayUser')]
$PreSetLayout
)
$BlankLayout = @"
<LayoutModificationTemplate Version="1" xmlns="http://schemas.microsoft.com/Start/2014/LayoutModification">
<LayoutOptions StartTileGroupCellWidth="6" />
<DefaultLayoutOverride>
<StartLayoutCollection>
<defaultlayout:StartLayout GroupCellWidth="6" xmlns:defaultlayout="http://schemas.microsoft.com/Start/2014/FullDefaultLayout">
<start:Group Name="" xmlns:start="http://schemas.microsoft.com/Start/2014/StartLayout">
<start:DesktopApplicationTile Size="2x2" Column="0" Row="0" DesktopApplicationLinkPath="%APPDATA%\Microsoft\Windows\Start Menu\Programs\System Tools\File Explorer.lnk" />
</start:Group>
</defaultlayout:StartLayout>
</StartLayoutCollection>
</DefaultLayoutOverride>
</LayoutModificationTemplate>
"@
$EveryDayUser = @"
<LayoutModificationTemplate Version="1" xmlns="http://schemas.microsoft.com/Start/2014/LayoutModification">
<LayoutOptions StartTileGroupCellWidth="6" />
<DefaultLayoutOverride>
<StartLayoutCollection>
<defaultlayout:StartLayout GroupCellWidth="6" xmlns:defaultlayout="http://schemas.microsoft.com/Start/2014/FullDefaultLayout">
<start:Group Name="" xmlns:start="http://schemas.microsoft.com/Start/2014/StartLayout">
<start:Tile Size="2x2" Column="4" Row="2" AppUserModelID="Microsoft.WindowsCalculator_8wekyb3d8bbwe!App" />
<start:DesktopApplicationTile Size="2x2" Column="2" Row="0" DesktopApplicationLinkPath="%APPDATA%\Microsoft\Windows\Start Menu\Programs\System Tools\computer.lnk" />
<start:DesktopApplicationTile Size="2x2" Column="4" Row="0" DesktopApplicationLinkPath="%APPDATA%\Microsoft\Windows\Start Menu\Programs\System Tools\File Explorer.lnk" />
<start:Tile Size="2x2" Column="0" Row="0" AppUserModelID="Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge" />
<start:Tile Size="2x2" Column="0" Row="2" AppUserModelID="Microsoft.ZuneVideo_8wekyb3d8bbwe!Microsoft.ZuneVideo" />
<start:Tile Size="2x2" Column="2" Row="2" AppUserModelID="Microsoft.Windows.Photos_8wekyb3d8bbwe!App" />
<start:Tile Size="2x2" Column="0" Row="4" AppUserModelID="Microsoft.WindowsStore_8wekyb3d8bbwe!App" />
<start:Tile Size="2x2" Column="2" Row="4" AppUserModelID="windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" />
<start:Tile Size="2x2" Column="4" Row="4" AppUserModelID="Microsoft.BingWeather_8wekyb3d8bbwe!App" />
</start:Group>
</defaultlayout:StartLayout>
</StartLayoutCollection>
</DefaultLayoutOverride>
</LayoutModificationTemplate>
"@
#Configures the start menu layout
#Copyies a IE Shortcut to the all users start menu so all users will have it on the start menu
#Copy-Item -Path "Internet Explorer.lnk" -Destination "C:\ProgramData\Microsoft\Windows\Start Menu\Programs"
IF (!($StartMenuLayout) -and ($PreSetLayout -EQ "Blank"))
{
add-content $Env:TEMP\BlankLayout.xml $BlankLayout
$StartMenuLayout = "$Env:TEMP\BlankLayout.xml"
}
IF (!($StartMenuLayout) -and ($PreSetLayout -EQ "EveryDayUser"))
{
add-content $Env:TEMP\EveryDayUser.xml $EveryDayUser
$StartMenuLayout = "$Env:TEMP\EveryDayUser.xml"
}
Write-Host importing $StartMenuLayout
Import-StartLayout -LayoutPath $StartMenuLayout -MountPath C:\
}
Function Disable-OneDrive
{
Write-Host 'Disabling OneDrive'
$RegPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive"
$Name = "DisableFileSyncNGSC"
$Value = "1"
$Type = "DWORD"
Set-Location HKLM:
if (!(test-Path .\SOFTWARE\Policies\Microsoft\Windows\OneDrive)) {New-Item .\SOFTWARE\Policies\Microsoft\Windows\OneDrive}
New-ItemProperty -Path $RegPath -Name $Name -Value $Value -PropertyType $Type -Force | Out-Null
Set-Location $PSScriptRoot
}
Function Disable-XboxServices
{
Write-Host "Disabling Xbox Services"
Get-Service XblAuthManager,XblGameSave,XboxNetApiSvc,WMPNetworkSvc | stop-service -passthru | set-service -startuptype disabled
}
Function Disable-Cortana
{
Write-Host "Disabling Cortana"
$RegPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search"
$Name = "AllowCortana"
$Value = "0"
$Type = "DWORD"
Set-Location HKLM:
if (!(test-Path .\SOFTWARE\Policies\Microsoft\Windows\"Windows Search")) {New-Item .\SOFTWARE\Policies\Microsoft\Windows\"Windows Search"}
New-ItemProperty -Path $RegPath -Name $Name -Value $Value -PropertyType $Type -Force | Out-Null
Set-Location $PSScriptRoot
}
Function Disable-WindowsTips
{
Write-Host 'Disabling Windows Tip'
$RegPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent"
$Name = "DisableSoftLanding"
$Value = "1"
$Type = "DWORD"
Set-Location HKLM:
if (!(test-Path .\SOFTWARE\Policies\Microsoft\Windows\CloudContent)) {New-Item .\SOFTWARE\Policies\Microsoft\Windows\CloudContent}
New-ItemProperty -Path $RegPath -Name $Name -Value $Value -PropertyType $Type -Force | Out-Null
Set-Location $PSScriptRoot
}
Function Disable-ConsumerExperience
{
Write-Host 'Disabling Consumer Experience'
$RegPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent"
$Name = "DisableWindowsConsumerFeatures"
$Value = "1"
$Type = "DWORD"
Set-Location HKLM:
if (!(test-Path .\SOFTWARE\Policies\Microsoft\Windows\CloudContent)) {New-Item .\SOFTWARE\Policies\Microsoft\Windows\CloudContent}
New-ItemProperty -Path $RegPath -Name $Name -Value $Value -PropertyType $Type -Force | Out-Null
Set-Location $PSScriptRoot
}
Function Disable-Hibernate
{
powercfg.exe /hibernate off
If (!(test-Path -path $Env:SystemDrive\Hiberfil.sys)) {Write-Host "Hibernate Disabled"}
IF (Test-Path -Path $Env:SystemDrive\Hiberfil.sys) {Write-Host "Hibernate was not Disabled"}
}
Function Disable-Ads
{
$reglocation = "HKCU"
#Start menu ads
Write-Host 'Disabling Start Menu Ads for Current User'
Reg Add "$reglocation\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" /T REG_DWORD /V "SystemPaneSuggestionsEnabled" /D 0 /F
#Lock Screen suggestions
Write-Host 'Disabling Lock Screen Suggentions for Current User'
Reg Add "$reglocation\SOFTWARE\Microsoft\CurrentVersion\ContentDeliveryManager" /T REG_DWORD /V "SoftLandingEnabled" /D 0 /F
Write-Host "Disabling explorer ads for current user"
Reg Add "$reglocation\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /T REG_DWORD /V "ShowSyncProviderNotifications" /D 0 /F
$reglocation = "HKLM\AllProfile"
reg load "$reglocation" c:\users\default\ntuser.dat
Write-Host 'Disabling Start Menu Ads for default user'
Reg Add "$reglocation\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" /T REG_DWORD /V "SystemPaneSuggestionsEnabled" /D 0 /F
Write-Host 'Disabling Lock Screen Suggentions for Current User'
Reg Add "$reglocation\SOFTWARE\Microsoft\CurrentVersion\ContentDeliveryManager" /T REG_DWORD /V "SoftLandingEnabled" /D 0 /F
Write-Host "Disabling explorer ads for default user"
Reg Add "$reglocation\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /T REG_DWORD /V "ShowSyncProviderNotifications" /D 0 /F
#unload default user hive
[gc]::collect()
reg unload "$reglocation"
}
Function Disable-WindowsStore
{
Write-Host 'Disabling Windows Tip'
$RegPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent"
$Name = "DisableSoftLanding"
$Value = "1"
$Type = "DWORD"
Set-Location HKLM:
if (!(test-Path .\SOFTWARE\Policies\Microsoft\Windows\CloudContent)) {New-Item .\SOFTWARE\Policies\Microsoft\Windows\CloudContent}
New-ItemProperty -Path $RegPath -Name $Name -Value $Value -PropertyType $Type -Force | Out-Null
Set-Location $PSScriptRoot
}
Function Remove-Apps
{
If ($AppsToRemove)
{
If (!(Test-Path $AppsToRemove))
{
$ErrorText = "Could not find $AppsToRemove"
Read-Error
}
$AppsList = Get-Content $AppsToRemove
#Removes some windows apps
Foreach ($App in ($AppsList))
{
$item = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -Like "*$App*"}
Write-Host "Removing $App"
Remove-AppxProvisionedPackage -Online -PackageName $item.PackageName -erroraction silentlycontinue
Remove-AppxProvisionedPackage -Online -PackageName $item.PackageName -erroraction silentlycontinue
Get-AppxPackage -AllUsers | Where-Object Name -Like "*$App*" | Remove-AppxPackage -erroraction silentlycontinue
}
}
If (!($AppsToRemove))
{
Get-AppxPackage -AllUsers | where-object {$_.name -notlike "*Store*" -and $_.name -notlike "*Calculator*" -and $_.name -notlike "*Windows.Photos*" -and $_.name -notlike "*SoundRecorder*" -and $_.name -notlike "*MSPaint*" -and $_.name -notlike "*ZuneVideo*" -and $_.name -notlike "*BingWeather*" -and $_.name -notlike "*sticky*"} | Remove-AppxPackage -erroraction silentlycontinue
Get-AppxPackage -AllUsers | where-object {$_.name -notlike "*Store*" -and $_.name -notlike "*Calculator*" -and $_.name -notlike "*Windows.Photos*" -and $_.name -notlike "*SoundRecorder*" -and $_.name -notlike "*MSPaint*" -and $_.name -notlike "*ZuneVideo*" -and $_.name -notlike "*BingWeather*" -and $_.name -notlike "*sticky*" } | Remove-AppxPackage -erroraction silentlycontinue
Get-AppxProvisionedPackage -online | where-object {$_.displayname -notlike "*Store*" -and $_.displayname -notlike "*Calculator*" -and $_.displayname -notlike "*Windows.Photos*" -and $_.displayname -notlike "*SoundRecorder*" -and $_.displayname -notlike "*MSPaint*" -and $_.displayname -notlike "*ZuneVideo*" -and $_.displayname -notlike "*BingWeather*" -and $_.displayname -notlike "*sticky*" } | Remove-AppxProvisionedPackage -online -erroraction silentlycontinue
}
}
Function Set-PageFile
{
#Gets total memory
$Getmemorymeasure = Get-WMIObject Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum
#Converts the memory into GB
$TotalMemSize = $($Getmemorymeasure.sum/1024/1024/1024)
if ($PageFileDrive -eq $null)
{
$Drive = "C:"
}
else
{
IF ($PageFileDrive -like "*:")
{
$Drive = $PageFileDrive
}
else
{
$Drive = $PageFileDrive + ":"
}
}
#recomended Page file size is double the memory installed
Write-Host "Setting Page file size on: $Drive"
write-host "Total Memory Installed (gb): $TotalMemSize"
#2gb
If (($TotalMemSize -gt "1") -and ($TotalMemSize -le "2.1"))
{
Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 4096 4096"
Write-Host "Set page file for 2 gb of memory"
}
#4gb
If (($TotalMemSize -gt "2") -and ($TotalMemSize -le "4.1"))
{
Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 8194 8194"
Write-Host "Set page file for 4 gb of memory"
}
#6gb
If (($TotalMemSize -gt "4") -and ($TotalMemSize -le "6.1"))
{
Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 12288 12288"
Write-Host "Set page file for 6 gb of memory"
}
#8gb
If (($TotalMemSize -gt "6") -and ($TotalMemSize -le "8.1"))
{
Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 16384 16384"
Write-Host "Set page file for 8 gb of memory"
}
#12
If (($TotalMemSize -gt "8") -and ($TotalMemSize -le "12.1"))
{
Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 24576 24576"
Write-Host "Set page file for 12 gb of memory"
}
#16
If (($TotalMemSize -gt "12") -and ($TotalMemSize -le "16.1"))
{
Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 32768 32768"
Write-Host "Set page file for 16 gb of memory"
}
#24
If (($TotalMemSize -gt "16") -and ($TotalMemSize -le "24.1"))
{
Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 49152 49152"
Write-Host "Set page file for 24 gb of memory"
}
#32
If (($TotalMemSize -gt "24") -and ($TotalMemSize -le "32.1"))
{
Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 65536 65536"
Write-Host "Set page file for 32 gb of memory"
}
#64
If (($TotalMemSize -gt "32") -and ($TotalMemSize -le "64.1"))
{
Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value "$Drive\pagefile.sys 131072 131072"
Write-Host "Set page file for 32 gb of memory"
}
}
function Enable-RDP
{
Get-NetFirewallProfile | Set-NetFirewallProfile -Enabled "False"
If (Get-ItemProperty 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections")
{
Set-ItemProperty 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections" -Value "0"
}
Else
{
New-ItemProperty 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name "fDenyTSConnections" -Value "0"
}
}
Function Install-DC
{
Write-Warning "User imput is needed for Domain Controller setup"
#loads the ad feature
Get-WindowsFeature AD-Doamin-Services
Add-WindowsFeature "RSAT-AD-Tools"
#installs the Ad servics and sets variabls for the domain
Get-WindowsFeature AD-Domain-Services | Install-WindowsFeature
Write-Host
$Domain = Read-Host 'What will be the name of the domain?'
$NetBIOS = Read-Host 'What will be the netbios name?(please type in all caps)'
$Account = Read-Host 'What is the name of the local admin account?'
Write-Host
net user $Account /passwordreq:yes
net user $Account /expires:never
Import-Module ADDSDeployment
Install-ADDSForest `
-CreateDnsDelegation:$false `
-DatabasePath "C:\Windows\NTDS" `
-DomainMode "Win2012" `
-DomainName "$Domain" `
-DomainNetbiosName "$NetBIOS" `
-ForestMode "Win2012" `
-InstallDns:$true `
-LogPath "C:\Windows\NTDS" `
-NoRebootOnCompletion:$true `
-SysvolPath "C:\Windows\SYSVOL" `
-Force:$true
}
function Join-Domain
{
IF (!($Domain)) {$domain = Read-Host "Domain"}
IF (!($Account)) {$account = Read-Host "Account"}
$password = Read-Host "Password for $Account" -AsSecureString
Write-host "Joining $Domain as $Account"
$username = "$domain\$account"
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
Add-Computer -DomainName $domain -Credential $credential
$password = $null
$credential = $null
}
Function Set-Time
{
Set-TimeZone -Name "$SetTimeZone"
}
Function Set-PowerConfig
{
powercfg.exe -X disk-timeout-ac 0
powercfg.exe -X disk-timeout-dc 0
powercfg.exe -x -standby-timeout-ac 0
powercfg.exe -x -standby-timeout-dc 0
}
Function Disable-ConnectToInternetUpdates
{
Write-Host 'Disabling Consumer Experience'
$RegPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
$Name = "DoNotConnectToWindowsUpdateInternetLocations"
$Value = "1"
$Type = "DWORD"
Set-Location HKLM:
New-ItemProperty -Path $RegPath -Name $Name -Value $Value -PropertyType $Type -Force | Out-Null
Set-Location $PSScriptRoot
}
#Checks to see what switches are being used
If (($StartMenuLayout) -and ($ExportStartMenuLayout))
{
$ErrorText = "You can not use ExportStartMenuLayout parameter and StartMenuLayout parameter at the sametime"
Read-Error
}
If ($Preset -EQ "CleanOS")
{
IF (!($StartMenuLayout)) {Import-StartMenuLayout -PreSetLayout Blank}
Set-PageFile
Disable-Ads
Disable-WindowsStore
Disable-ConsumerExperience
Disable-WindowsTips
Disable-Cortana
Disable-XboxServices
Disable-OneDrive
Remove-Apps
}
IF ($Preset -EQ "EveryDayUser")
{
IF (!($StartMenuLayout)) {Import-StartMenuLayout -PreSetLayout EveryDayUser}
Disable-Ads
Remove-Apps
Set-PageFile
}
IF ($Preset -EQ "DomainComputerSetup")
{
Join-Domain
Set-PageFile
Disable-Ads
Disable-ConsumerExperience
Disable-WindowsTips
Disable-XboxServices
Remove-Apps
}
#Exports the current start menu config
If ($ExportStartMenuLayout){ Export-StartMenuLayout}
#If a config file is specifed will import it
IF ($StartMenuLayout) {Import-StartMenuLayout}
#Enable RDP
IF ($EnableRDP) {Enable-RDP}
IF ($SetTimeZone) {Set-Time}
#Disbales Xbox Services and stops them
If ($DisableXboxServices) {Disable-XboxServices}
#Add regkeys to disable OneDrive
If ($DisableOneDrive) {Disable-OneDrive}
#adds regkey needed to disable Cortana
If ($DisableCortana) {Disable-Cortana}
#Disables the windows store, The app is still listed
If ($DisableWindowsStore) {Disable-WindowsStore}
#Disables add on the start menu and lock screen
If ($DisableAds) {Disable-Ads}
#Disables Hibernate
If ($DisableHibernate) {Disable-Hibernate}
#Disables Windows Tips
If ($DisableWindowsTips) {Disable-WindowsTips}
#Disables Consumer Experience
If ($DisableConsumerExperience) {Disable-ConsumerExperience}
#Disable Connect to Windows Update Internet Location
IF ($DisableConnectToInternetUpdates) {Disable-ConnectToInternetUpdates}
#If a list file is specifyed will run the uninstall process
IF ($RemoveApps) {Remove-Apps}
#renames the computer
If ($RenameComputer) {Rename-Computer -NewName $RenameComputer}
#joins the computer to a domain
If ($JoinDomain) {Join-Domain}
#Sets the page file
If ($SetPageFile) {Set-PageFile}
#Sets power config
IF ($SetPowerConfig) {Set-PowerConfig}
IF ($InstallDC) {Install-DC}
#Reboots the computer
If ($Reboot)
{
Restart-Computer -ComputerName $env:COMPUTERNAME
}
else
{
Write-Host "You will need to reboot the computer before you see the change take affect"
Exit 0
}