-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActiveDirectorySetupPowerShellScript-CVO-Programmeren2-2014.ps1
509 lines (236 loc) · 11.6 KB
/
ActiveDirectorySetupPowerShellScript-CVO-Programmeren2-2014.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
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
CJusersIndolDownloadslOneLong.ps1
README. txt
donderdag 12 juni 2014 11:19
PowerShell Options:
1: Domaev01.ServerInstall.ps1
- Sets up the ComputerName, IP, DC and DHCP
2: Domaev02. ServerCofigInfo.ps1 + Domaev. ServerCofigInfo.txt
- Shows some server Hardware information
3: Domaev03. DHCPConfig•ps1
- Configures some DHCP scope and reservations
4: Domaev04. DHCPConfigInfo.ps1 + Domaev. DHCPConfigInfo.txt
- Puts some DHCP Config Info to a Textfile in the root of the script
5: Domaev05. CreateFolders .ps1
- Creates some directories with permissions on the Server
6: Domaev06. CreateOUStructure.ps1
- Creates some Organizational Units
7: Domaev07. CreateUsers.ps1
- Create some users and sets some settings for those users
8: Domaev08. RetriveUsers.ps1
+ DDomaev.ADUsers.txt
- List some users from desired AD/OU
9: Domaev09. PowerShellTools.ps1
- The main Menu for the Script is here.
p. s.
You can always check my GitHub for an updated version of it,
with less hardcoding, and some error ahndling.
https://github.com/Nikolai-D/Angel0fForgiveness/tree/master/PowerShell/Domaev. PowerShell
-Opdrachten9
Have fun :)
Domaev01. ServerInstall.psl
"You will need to start this first option of ServerInstall 3 times.
Because there are 2 reboots between the first two options.
After third option you can happily continue.
So now choose desired option:
1 for Changing the Computer name
2 for Installing Domain Controller
3 and this last one option for installing DHCP"
#Call myScriptl from myScript2
Switch (Read-Host "Make a Choise") {
(. \Domaev01. ServerInstalllCompName.ps1)
2
(. \Domaev01. ServerInstall2DC.ps1}
Domaev01. ServerInstalllCompName.ps1
$CompName = Read-Host "Type in the desired ServerName (W2K8PWSHLL01 for Example) "
Rename-Computer $CompName #setting server name
Restart-Computer #obviousely rebooting the machine
Domaev01. ServerInstall2DC.ps1
Write-Host "Lets install some IP and DNS settings."
$Comp = Read-Host "Give the CompName please,"
- 1-
C:|UsersIndolDownloads|OneLong.ps1
SIP = Read-Host "Now type in the desired IP address of the Server (for example 192.168.126.140),"
SPref = Read-Host "Also please type in the desired Prefixtenth (for example 24),"
$DG = Read-Host "Please type in the desired DefaultGateway (for example
192. 168.126.254),"
SPWD = Read-Host "Please type the desired local Administrator password in. (Like
Admin2012) "
New-Net IPAddress $IP -InterfaceAlias "Ethernet" -PrefixLength $Pref -DefaultGateway $DG #setting some TCPIP settings
Set-DnsClientServerAddress -InterfaceAlias
"Ethernet" -ServerAddresses ($IP)
#setting
DNS
AD SERUCE INTERFACEE
( [adsi] "WinNT://$Comp/Administrator"). SetPassword ("$PWD") #admin PW? Admin2012
Install-WindowsFeature AD-Domain-Services -IncludeManagementTools Install-ADDSForest -DomainName domaev. local
#check for 1SB? THE PREFiT - LENGTCH iN IPVG iS THE EQUiVALENT OF THE
Domaev01. ServerInstallInstDHCP. ps1
SUBNET MASK iN iPU4. HOWEVER, RATHER THAN BRiNG
EXPEESSED EN YOENEOS LiKE iTiS IN IPVI,
I EXPRESSEO AE AN INTECER BETWEEN 2-128,
Add-WindowsFeature - IncludeManagementTools dhcp
• \Domaev09. PowerShellTools.ps1
Domaev02. ServerConfigInfo.ps1
WMi → WiNDOWS MANAGEMENT
#get computer manufacturer and serialnumber
INSTRUMENTATION.
#Get-WmiObject win32 bios | format-table manufacturer, serialnumber #get total physical memory
# ( (Get-WmiObject -class "win32_ physicalmemory" -Namespace "root\cimv2"). capacity) / 1gb
#get disk size
#Get-WmiObject -Class "win32_diskdrive" | Format-Table model, size
Write-Host "Showing some Hardware info in the the Text files in the root of the Script"
#Hardware info to a file
ROOT CMUZ ISTHE DREANLT NAMESDACK
$Bios = Get-WmiObject win32_bios
FOr WMS QUERRiES.
$Ram = ( (Get-WmiObject -class "win32_physicalmemory" -Namespace "root \cimv2"). capacity
) / 1gb
$disk = Get-WniObject -Class "win32_ diskdrive"
$info = ("manufacturer ="* $Bios. manufacturer), ("serialnumber = " + $Bios. serialnumber
), ("physicalMemory = " +$Ram), ("disktype =" +$disk. model), ("diskSize =" +$disk.size)
Sinfo |Out-File . \Domaev. ServerConfIginfo.txt
Sinfo
#Icp/ip configuration to a file
Sip = Get-WmiObject -Class win32_networkadapterconfiguration
Sipinfo = ("dns=" +$ip. dnsdomain), ("defaultgateway = " + $ip. dafaultipgateway), ("ip
address = " + Sip. ipaddress), ("nameserver = " + $ip. dnshostname)
Sipinfo | Out-File. \Domaev. ServerConfIginfor. txt
• PowerShel1Tools.ps1 PiPFLiNING PiPELiNING <COmPuTiNC- PiTELiNE iS A
BOAA BROCRSSiNGELIMENISCONNECTED
Domaev03. DHCPconfig.psl
# PowerShell 3.0 creates a
IN TH WHERE THE ONES OR ONE LEMENT
DHCP Scope
Write-Host "Lets set some DHCP settings"
$StartRange = Read-Host "Please type in the StartRange like 192.168.126.160"
SEndRange = Read-Host "Please type in the EndRange like 192.168.126.189"
$SubnetMask = Read-Host "Please type in the SubnetMask like 255.255.255.0"
JorsIndolDownloadslOneLong,ps1
#scopoID = Road-Host "Please type in the Scopei 11ke 192.169.226.2601
$StartRangeBx = Read-Host "Please type in StartRangeEx the like 192.168.126.180"
SEndRangeEx = Read-Host "Please type in the EndRangeEx like 192. 168.126.189"
donderdag 12 juni 2014 11:19
§IPAddress = Read-Host "Please type in the IPAddress like 192.168.126.182"
$ClientID = Read-Host "Please type in the ClientID like f8-db-7f-4f-a4-90"
Install-WindowsFeature DHCP -IncludeManagementTools
Import-Module DHCPServer -Verbose: $False
Add-DHCPServerv4Scope -Name reservationExl -StartRange $StartRange -EndRange $EndRange
-SubnetMask $SubnetMask
Add-DhcpServerv4ExclusionRange -ScopeID $ScopeID -StartRange $StartRangeEx -EndRange
SEndRangeEx
Add-DhcpServerv4Reservation -ScopeID $ScopeID -IPAddress $IPAddress -ClientID $ClientID
• \Domaev09. PowerShellTools.ps1
Domaev04. DHCPConfigInfo.ps1
Write-Host "This
script will output some DHCP config info."
§ScopeId = Read-Host "Type in the scopeID of the DHCP, like 192.168.126.60"
Get-DhcpServerv4Scope | Out-File c: \Domaev. DHCPConfigInfo. txt
Get-DhcpServerv4Reservation -ScopeId $ScopeId | Out-File •\Domaev. DHCPConfigInfo.txt
Get-DhcpServerv4ExclusionRange -ScopeId $ScopeId |Out-File •\Domaev. DHCPConfigInfo.txt
•\Domaev09. PowerShellTools. PowerShellTools.ps1
Domaev05. CreateFolders.ps1
new-item
"C: \DATA\Daily Communications" -itemtype directory
new-item "C: \DATA \Administratie" -itemtype directory new-item C: \DATA\ProjectX\Managers -itemtype directory new-item C: \DATA\ProjectX\Administrators -itemtype directory
new-item C: \Homes -itemtype directory new-item C: \Profiles -itemtype directory
FOFRACH
Get-Acl "C: \DATA\Daily Communications" | Format-List
Sacl = Get-Acl "C: \DATA\Daily Communications"
$acl. SetAccessRuleProtection ($True, SFalse)
Srule = New-Object System. Security. AccessControl. FileSystemAccessRule ("Everyone",
"FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl. AddAccessRule ($rule)
Set-Acl "C: \DATA\Daily Communications" Sacl
Get-Acl "C:\DATA\Daily Communications" | Format-List
Get-Acl "C: \DATA\Administratie" | Format-List
Sacl = Get-Acl "C: \DATA\Administratie"
Sacl. SetAccessRuleProtection ($True, $False)
§rule = New-Object System. Security. AccessControl. FileSystemAccessRule ("Everyone",
"FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl. AddAccessRule ($rule)
Set-Acl "C: \DATA\Administratie" Sacl
Get-Acl "C: \DATA\Administratie" | Format-List
Get-Acl C: \DATA\ProjectX\Managers | Format-List
$ac1 = Get-Acl C: \DATA\ ProjectX \Managers
-3-
C: UsersindolDownloads OneLong.ps1
$acl.SetAccessRuleProtection ($True, $False)
Srule = New-Object System.Security.AccessControl. FileSystemAccessRule ("Everyone"
"FullControl"
• "ContainerInherit, ObjectInherit", "None", "Allow")
Sacl. AddAccessRule (§rule)
Set-Acl C: \DATA\Project\Managers Sacl
Get-Acl C: \DATA\Project\Managers | Format-List
Get-Acl C: \DATA\ProjectX\Administrators | Format-List
Sacl = Get-Acl C: DATA\Project Administrators
Sacl. SetAccessRuleProtection ($True, $False)
Srule = New-Object System. Security AccessControl. FileSystemAccessRule ("Everyone"
"FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
Sacl. AddAccessRule ($rule)
Set-Acl C: \DATA\ProjectX\Administrators $acl
Get-Acl C: \DATA\ProjectX\Administrators | Format-List
Get-Acl C: \Homes | Format-List
Sacl = Get-Acl C: \Homes
Sacl. SetAccessRuleProtection ($True, $False)
Srule = New-Object System. Security AccessControl. FileSystemAccessRule ("Everyone"
"FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
Sacl. AddAccessRule ($rule)
Set-Acl C: \Homes Sacl
Get-Acl C: \Homes | Format-List
Get-Acl C: \Profiles | Format-List
Sacl = Get-Acl C: \Profiles
Sacl. SetAccessRuleProtection ($True, $False)
$rule = New-Object System. Security. AccessControl. FileSystemAccessRule ("Everyone",
"FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
Sacl. AddAccessRule ($rule)
Set-Acl C: \Profiles Sacl
Get-Acl C: \Profiles | Format-List
• \Domaev09. PowerShellTools ps1
Domaev06. CreateOUStructure.ps1
Write-Host "Lets create some OUs on this Domain"
• \Domaev09. PowerShellTools.ps1
Domaev06. CreateUAStrueture.ps1
Write-Host "Let
create some OUs on this Domain"
dadd ou "OUbeheer, DC=domaev, DC=local"
dsadd ou "oU=ITAdmins, DC=domaev, DC=1oca1"
dsadd ou
"OU=Managers, DC=domaev, DC=local"
dadd
"OU-Werkvloer, DC=domaev, DC=local"
dsadd ou "OU=Magazijn, DC-domaev, DC-local"
dsadd ou "OU=Deheer, DC=domaev, DC=local"
dadd ou "OU=ITAdmins, DC=domaev, DC=local"
dsadd ou "OU=Managers, DC=domaev, DC=local"
dsadd
ou "OU=Werkvloer, DC=domaev, DC=local"
dadd ou "OU-Magazijn, DC=domaev, DC=local"
dsadd
ou "OU=Laadkaai, DC=domaev, DC=local"
dadd ou "OU=Administratie, DC=domaev, DC=local"
-4-
sadd ou "OU
aadkaai, DC=domaev, DC=local"
dadd ou
Administratie, DC=domaev, DC-local"
• \Domaevp9. PowerShellTools.ps1
Domaev07 CreateUsers. CreateUsers.ps1
New-ADUSer -SamAccountName rverheyen -Name "Rudy Verheyen" -Account Password ( ConvertTo-SecureString -AsPlainText "Hoboken2660" -Force) -Enabled $true - PasswordNeverExpires Strue -Path 'OU=ITAdmins, DC=domaev, DC=local ' New-ADUser -SamAccountName dveusters -Name "Danny Veusters" -Account Password ( ConvertTo-SecureString -AsPlainText "Hoboken2660" -Force) -Enabled $true - PasswordNeverExpires $true -Path 'OU=Managers, DC=domaev, DC=local' New-ADUser -SamAccountName abertels -Name "An Bertels" -AccountPassword ( ConvertTo-SecureString -AsPlainText "Hoboken2660" -Force) -Enabled Strue - PasswordNeverExpires $true -Path 'OU=Administratie, DC=domaev, DC-local' set-aduser rverheyen -homedirectory |\192.168.126. 140\homes \rverheyen -homedrive h: set-aduser dveusters -homedirectory |\192.168.126.140\homes\dveusters -homedrive h: set-aduser abertels -homedirectory |\192.168.126.140 \homes \abertels -homedrive h: set-aduser rverheyen -profilepath | \192.168.126.140\profiles\rverheyen set-aduser deusters -profilepath | \192.168.126.140\profiles\dveusters set-aduser abertels -profilepath \ \192.168.126.140\profiles\abertels Add-ADGroupMember -Identity 'Domain Admins' -Member rverheyen
• \Domaev09. PowerShellTools.ps1
Domaev08 RetrieveUser. RetrieveUser.ps1
$oU = read-host "Welke OU wilt u bekijken?"
Get-ADUser -Filter * -SearchBase "ou=$OU, do-domaev, dc=local" | Out-File C: \Domaev.
ADUsers.txt
• \Domaev09. PowerShellTools.ps1
Domaev08. RetriveUsers.psl
SOU = read-host
Helke OU wilt u bekijken?"
Get-ADUser
Filter * -SearchBase "ou=$OU, de=domaev, dc=local" | Out-File C: \Domaev.
ADUsers.
• \Domae
v09. PowerShellTools.ps1
Domaev09. PowerShellTools. ps1/
"Lets do some PS hacking, which Script do you want to run?
PowerShell Options:
1: Domaev01. ServerInstall.psl