Skip to content

Commit d4c8ebe

Browse files
committed
initial commit
1 parent 426bdb9 commit d4c8ebe

File tree

1 file changed

+146
-0
lines changed

1 file changed

+146
-0
lines changed

run-setup.ps1

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
## iex ((New-Object System.Net.WebClient).DownloadString('http://dreamthief.us/CoreServerSetup03.ps1'))
2+
3+
4+
<#
5+
TODO:
6+
Timezone check
7+
Set-TimeZone -Name "Pacific Standard Time"
8+
Time Check
9+
NTP Servers
10+
WindowsUpdates
11+
setup64 /c
12+
13+
#>
14+
15+
clear-host
16+
17+
##Banner
18+
Write-host "#############################################################" -ForegroundColor Green
19+
Write-host "### Welcome to CUSCo ###" -ForegroundColor Green
20+
Write-host "### Casteel's Ultimate Server Configuration ###" -ForegroundColor Green
21+
Write-host "### Use at your own risk! ###" -ForegroundColor Green
22+
Write-host "### ###" -ForegroundColor Green
23+
Write-host "#############################################################" -ForegroundColor Green
24+
write-host ""
25+
write-host ""
26+
27+
28+
### Ask for input
29+
$newhost = read-host "What is the hostname for this server?"
30+
write-host ""
31+
$ipaddr = read-host "What is the IP Address?"
32+
write-host ""
33+
$subnet = read-host "What is the Subnet? Slash format e.g. 24 or 27 or 16"
34+
35+
if ($subnet -eq 30) {$mask = "255.255.255.252"}
36+
elseif($subnet -eq 29) {$mask = "255.255.255.248"}
37+
elseif ($subnet -eq 28) {$mask = "255.255.255.240"}
38+
elseif($subnet -eq 27) {$mask = "255.255.255.224"}
39+
elseif($subnet -eq 26) {$mask = "255.255.255.192"}
40+
elseif($subnet -eq 25) {$mask = "255.255.255.128"}
41+
elseif($subnet -eq 24) {$mask = "255.255.255.0"}
42+
elseif($subnet -eq 23) {$mask = "255.255.254.0"}
43+
elseif($subnet -eq 22) {$mask = "255.255.252.0"}
44+
elseif($subnet -eq 21) {$mask = "255.255.248.0"}
45+
elseif($subnet -eq 20) {$mask = "255.255.240.0"}
46+
elseif($subnet -eq 19) {$mask = "255.255.224.0"}
47+
elseif($subnet -eq 18) {$mask = "255.255.192.0"}
48+
elseif($subnet -eq 17) {$mask = "255.255.128.0"}
49+
elseif($subnet -eq 16) {$mask = "255.255.0.0"}
50+
51+
write-host ""
52+
$gateway = read-host "What is the gateway address?"
53+
write-host ""
54+
$dns = read-host "What is the DNS? More can be added after final config if needed"
55+
56+
### Write out the input
57+
write-host ""
58+
Write-host "The new hostname will be: " -NoNewline -foregroundcolor yellow
59+
write-host $newhost.ToUpper() -ForegroundColor red
60+
Write-host " The IP Address will be: " -nonewline -ForegroundColor yellow
61+
write-host $ipaddr -ForegroundColor red
62+
Write-host " The subnet mask will be: " -nonewline -ForegroundColor yellow
63+
write-host $mask -ForegroundColor red
64+
Write-host " The gateway will be: " -nonewline -ForegroundColor yellow
65+
write-host $gateway -ForegroundColor red
66+
Write-host " The DNS Server will be: "-nonewline -ForegroundColor yellow
67+
write-host $dns -ForegroundColor red
68+
write-host ""
69+
write-host ""
70+
71+
##Final warnings
72+
write-host ""
73+
Write-host "This script will make the following changes to this machine"
74+
write-host ""
75+
write-host " 1. Update the network to the above details"
76+
write-host " 2. Install Choclatey"
77+
write-host " 3. Allow Ping through the firewall"
78+
write-host " 4. Enable RDP Access and allow it through the firewall"
79+
write-host " 5. Enable PS remote access and allow ANY machine to connect"
80+
write-host " 6. "
81+
write-host " 7. " -ForegroundColor red
82+
write-host " 8. "
83+
write-host ""
84+
write-host ""
85+
86+
87+
$choice = ""
88+
while ($choice -notmatch "[y|n]") {
89+
$choice = read-host "Do you want to continue? (Y/N)"
90+
}
91+
92+
if ($choice -eq "n") {
93+
break
94+
}
95+
96+
write-host ""
97+
write-host ""
98+
Write-host "...and so we begin!" -ForegroundColor red
99+
write-host ""
100+
write-host ""
101+
write-host ""
102+
103+
# import needed modules
104+
write-host "Importing needed modules" -ForegroundColor Green
105+
import-module netsecurity, dnsclient, NetTCPIP, netadapter
106+
write-host "Import complete" -ForegroundColor Green
107+
write-host ""
108+
109+
### Rename the server
110+
Write-host "Renaming the computer"
111+
rename-computer $newhost
112+
Write-Host "Computer rename process complete" -ForegroundColor Green
113+
write-host ""
114+
115+
116+
### Install choclatey
117+
Write-Host "Installing Chocolatey" -ForegroundColor Green
118+
invoke-expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
119+
write-host ""
120+
write-host ""
121+
122+
##Set up the network
123+
Write-Host "Setting up the network" -ForegroundColor Green
124+
Disable-NetAdapterBinding -Name "Ethernet0" -ComponentID ms_tcpip6
125+
New-NetIPAddress -InterfaceIndex 12 -IPAddress $ipaddr -PrefixLength $subnet -DefaultGateway $gateway
126+
Set-DnsClientServerAddress -InterfaceIndex 12 -ServerAddresses ("$dns", "8.8.8.8")
127+
Write-Host "Network setup complete" -ForegroundColor Green
128+
write-host ""
129+
130+
131+
###Allow ping
132+
Write-Host "Allow ping through the firewall" -ForegroundColor Green
133+
Enable-NetFirewallRule -DisplayGroup "File and Printer Sharing"
134+
Write-Host "Ping now allowed" -ForegroundColor Green
135+
Write-Host "Ping was my best friend in school" -ForegroundColor Green
136+
write-host ""
137+
138+
139+
### Allow RDP
140+
Write-Host "Setting up RDP access" -ForegroundColor Green
141+
set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'-name "fDenyTSConnections" -Value 0
142+
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
143+
Write-Host "RDP Access complete" -ForegroundColor Green
144+
write-host ""
145+
146+
shutdown /r

0 commit comments

Comments
 (0)