-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcustomize-windows-client.ps1
More file actions
125 lines (109 loc) · 4.1 KB
/
customize-windows-client.ps1
File metadata and controls
125 lines (109 loc) · 4.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
<#
.Synopsis
PowerShell post-installation script to minimize and customize Windows operating systems
.Description
This post-installation script is for minimize and customize a Windows Client.
.Notes
File Name: customize-windows-client.ps1
Author: https://github.com/filipnet/customize-windows-client
License: BSD 3-Clause "New" or "Revised" License
Requires: PowerShell 5.1 or above + RunAsAdministrator
.Example
.\customize-windows-client.ps1
.LINK
https://github.com/filipnet/customize-windows-client
#>
# Variables
$HOSTNAME = "win10client"
$WORKGROUP = "WORKGROUP"
$DRIVELABELSYS = "OS"
$TEMPFOLDER = "C:\Temp"
$INSTALLFOLDER = "C:\Install"
$POWERMANAGEMENT = "High performance"
$DRIVELETTERCDROM = "z:"
$CURRENTLOCALADMIN = "Administrator"
$NEWLOCALADMIN = "local_admin"
$WINDOWSBUILD = (Get-WmiObject Win32_OperatingSystem).BuildNumber
$WINDOWSSERVER2016 = "14393"
$WINDOWSSERVER2019 = "17763"
$CR = "`n"
$BLANK = " "
$TIME = Get-Date -UFormat "%A %d.%m.%Y %R"
$FOREGROUNDCOLOR = "Yellow"
# Define actions should be excluded
$Excludes = @(
"Disable-Administrator-Description.ps1";
"Disable-Autoplay.ps1";
"Disable-Autorun.ps1";
"Disable-RDP-Printer-Mapping.ps1";
"Set-Driveletter-CDROM.ps1";
"Show-Known-File-Extensions.ps1";
"Set-PowerManagement-HighPerformance.ps1";
)
# ---------- DO NOT CHANGE THINGS BELOW THIS LINE -----------------------------
# Check if the powershell is started as an administrator
function Test-Administrator {
[OutputType([bool])]
param()
process {
[Security.Principal.WindowsPrincipal]$user = [Security.Principal.WindowsIdentity]::GetCurrent();
return $user.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator);
}
}
if(-not (Test-Administrator)) {
Write-Error "This script must be executed as Administrator.";
Read-Host “Press ENTER to continue...”
exit 1;
}
# Create C:\Temp and C:\Install folders if not exists
Write-Host ($CR +"Create $TEMPFOLDER and $INSTALLFOLDER folders") -foregroundcolor $FOREGROUNDCOLOR
If(!(test-path $TEMPFOLDER)) {
New-Item -ItemType Directory -Force -Path $TEMPFOLDER
}
If(!(test-path $INSTALLFOLDER)) {
New-Item -ItemType Directory -Force -Path $INSTALLFOLDER
}
## Backup Registry
Write-Host ($CR +"Create Registry Backup" + $BLANK + $TIME) -foregroundcolor $FOREGROUNDCOLOR $CR
reg export HKLM C:\Install\registry-backup-hklm.reg /y | Out-Null
reg export HKCU C:\Install\registry-backup-hkcu.reg /y | Out-Null
reg export HKCR C:\Install\registry-backup-hkcr.reg /y | Out-Null
# Start customization
Write-Host ($CR +"This system will customized and minimized") -foregroundcolor $FOREGROUNDCOLOR $CR
$confirmation = Read-Host "Are you sure you want to proceed? [press: y]"
if ($confirmation -eq 'y') {
# Create array of actions out of include folder
$Actions = @((Get-ChildItem -Path 'includes').Name)
# Delete excluded actions out of action-array
$Actions = $Actions |Where-Object { $Excludes -notcontains $_ }
# Execute selected actions"
foreach ($Action in $Actions) {
Write-Host "Execute " -NoNewline
Write-Host ("$Action") -foregroundcolor Yellow -NoNewline
Write-Host " ..."
& "includes\$Action"
}
}
# Start renaming client
Write-Host ($CR +"Hostname and workgoup will be cahnged") -foregroundcolor $FOREGROUNDCOLOR $CR
$confirmation = Read-Host "Are you sure you want to change it? [press: y]"
if ($confirmation -eq 'y') {
# Set hostname and workgroup
Try {
Rename-Computer -NewName $HOSTNAME -ErrorAction Stop
} Catch {
Write-Warning $Error[0]
}
Try {
Add-Computer -WorkgroupName $WORKGROUP -ErrorAction Stop
} Catch {
Write-Warning $Error[0]
}
Write-Host ("Server renamed to $HOSTNAME and joined to workgroup $WORKGROUP") -foregroundcolor $FOREGROUNDCOLOR $CR
}
# Restart to apply all changes
Write-Host ($CR +"This system will restart to apply all changes") -foregroundcolor $FOREGROUNDCOLOR $CR
$confirmation = Read-Host "Are you sure you want to proceed restart? [press: y]"
if ($confirmation -eq 'y') {
Restart-Computer -ComputerName localhost
}