Advertisement
Guest User

Core-Install

a guest
Oct 16th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.91 KB | None | 0 0
  1.  
  2. # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  3. # Changing the IP address of the servers NIC
  4. # New-NetIPAddress - InterfaceAlias $NICnew -IPAddress (Read-Host -Promt "Enter new IP address") `
  5. # -PrefixLength 24 -DefaultGateway (Read-Host -Promt "Enter new IP address")=
  6. # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7. ############# Need to create shares here ##################
  8. # Diskpart > List disk > Sel disk 1 > create part pri size=20480 > create part pri size=19465 >
  9. # sel part 1 > assign letter=X > format fs=ntfs quick > sel part 2 > asign letter=Z > format fs=ntfs quick.
  10. # VssAdmin.exe add shadowstorage /For=X: /ON=X: /MaxSize=500MB
  11. ############# Need to create shares here ##################
  12. # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  13.  
  14. ### Top var declaration. ###
  15. # Yes or No for Request
  16. $Y = @('Y','Yes', 'y', 'yes')
  17. $N = @('N', 'No', 'n', 'no')
  18. # Server
  19. $HostName = hostname
  20. $ReqChange_SRV = Write-Output (Read-Host -prompt "Server has name $Hostname. Do you want to change this? Type [yes|No]")
  21. $ReqNewSrvName = (Read-Host -Prompt "What name do you want to give to the server?")
  22. # NIC
  23. $CurNicName = (Get-NetAdapter).Name
  24. $ReqChange_NIC = Write-Output (Read-Host -prompt "NIC has name $CurNicName. Do you want to change this? Type [yes|No]")
  25. $ReqNewNicName = (Read-Host -Prompt "Enter new NIC name")
  26. # Domain name
  27. $ReqDomain = (Read-Host -Prompt "Enter Domain name")
  28. $CurDomain = (Get-ADDomain -Identity (Get-WmiObject Win32_ComputerSystem).Domain).NetBIOSName
  29. # (Get-ADDomain -Current LocalComputer).NetBIOSName
  30. # CSV files
  31. $OU = Import-Csv -Delimiter "," -Path (Read-Host -Prompt "Enter OU CSV file location")
  32. $users = Import-Csv -Delimiter "," -Path (Read-Host -Prompt "Enter Users CSV file location")
  33. $Groups = Import-Csv -Delimiter "," -Path (Read-Host -Prompt "Enter Groups CSV file location")
  34. # Password
  35. $securePassword = (ConvertTo-SecureString "TestPassw0rd!" -AsPlainText -Force)
  36. $UserPass = Get-WMIObject -class Win32_ComputerSystem | Select-Object username
  37. # GPO
  38. $ReqNewGpo = Write-Output (Read-Host -Prompt "Do you want to add a new GPO [Yes|No]")
  39. $ReqNewGPOName = Write-Output (Read-Host -Prompt "Enter a GPO name")
  40. $GPOComment = Write-Output (Read-Host -Prompt "Add a comment")
  41. ### Start of server name changing process. ###
  42. # If server name should be changed, change it.
  43. If ($ReqChange_SRV -in $Y) {
  44. Write-Output $ReqNewSrvName
  45. Write-Output "server name will be changed from $Hostname to $ReqNewSrvName"
  46. Rename-Computer -Confirm:0 -NewName $ReqNewSrvName
  47. # If server name should not be changed, continue to next step.
  48. } ElseIf ($ReqChange_SRV -in $N) {
  49. Write-Output "No changes will be made. Continuing to next step."
  50. } Else {
  51. Write-Output "Wrong input please try again."
  52. }
  53. # After previous step, sleep for 5 seconds.
  54. Start-Sleep -Seconds 2
  55. ### End of server name changing process. ###
  56.  
  57. ### Start of changing the NIC name. ###
  58. # If NIC name should be changed, change it.
  59. If ($ReqChange_NIC -in $Y) {
  60. Write-Output $ReqNewNicName
  61. Write-Output "NIC name will be changed from $CurNicName to $ReqNewNicName"
  62. Rename-NetAdapter -Name $CurNicName -NewName $ReqNewNicName
  63. # If server name should not be changed, continue to next step.
  64. } ElseIf ($ReqChange_NIC -in $N){
  65. Write-Output "No changes will be made. Continuing to next step."
  66. # If user enters false input
  67. }Else {
  68. Write-Output "Wrong input, please try again."
  69. }
  70. # After previous step, sleep for 5 seconds.
  71. Start-Sleep -Seconds 2
  72. ### End of NIC name changing process. ###
  73.  
  74. ### Start of installing and configuring AD-DS. ###
  75. # Installing the AD-DS Features.
  76. Write-Output "Installing Windows Feature AD-DS"
  77. Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools
  78. # Import module for script.
  79. Import-Module ActiveDirectory
  80. # To set all needed values for the AD-DS.
  81. Install-ADDSForest -DomainName $ReqDomain -SafeModeAdministratorPassword (read-host -prompt "Safe Mode Password" -assecurestring) `
  82. -DomainNetbiosName (read-host -prompt "NetBios Name") -DomainMode Win2012R2 -ForestMode Win2012R2 -DatabasePath "C:\Windows\NTDS" `
  83. -LogPath "C:\Windows\NTDS" -SysvolPath "C:\Windows\SYSVOL" -NoRebootOnCompletion -InstallDns -Force –PassThru
  84. Write-Output "Configured the AD-DS Feature"
  85. # Increasing the forest and domain functional level to Server2016.
  86. Set-ADForestMode -Identity $ReqDomain -ForestMode 'Windows2016Forest'
  87. Set-ADDomain -Identity $ReqDomain -DomainMode 'Windows2016Domain'
  88. # After previous step, sleep for 5 seconds.
  89. Start-Sleep -Seconds 2
  90. ### End of installing and configuring AD-DS. ###
  91.  
  92. ### Start of creating all the needed Organizational Units. ###
  93. # For loop for all items in Orginizational Unit CSV file.
  94. ForEach ($OUitem in $OU) {
  95. # Declaring the variables for the data in the OU CSV file.
  96. $OUName = $OUitem.Name
  97. $OUPath = $OUitem.Path
  98. # This command will be executed for each item in the csv file.
  99. New-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $true -Name $OUName -Path $OUPath
  100. # Sleep 1 second for each added item.
  101. Start-Sleep -Seconds 1
  102. }
  103. ### End of creating all the needed Organizational Units. ###
  104.  
  105. ### Start of creating all the users. ###
  106. # For loop for all items in Users CSV file.
  107. ForEach ($user in $users){
  108. # Declaring the variables for the data in the Users CSV file.
  109. $fName = $user.'First Name'
  110. $lName = $user.'Last Name'
  111. $DisplayName = ($fName+" "+$lName)
  112. $jTitle = $user.'Job Title'
  113. $Desc = $user.Description
  114. $AccName = ($fName[0]+"."+$lName)
  115. $OUpath = $user.'Organizational Unit'
  116. $Prpath = $user.'Profile Path'
  117. $HoPath = $user.'Home Path'
  118. $Drive = $user.Drive
  119. # This command will be executed for each item in the csv file.
  120. New-ADUser -name $AccName -GivenName $fName -surname $lName -Title $jTitle -DisplayName $DisplayName `
  121. -Description $Descri -Path $OUpath -ProfilePath $PrPath -HomeDrive $Drive -HomeDirectory $HoPath -Description $Desc `
  122. -AccountPassword $securePassword -ChangePasswordAtLogon 1 -Enabled 1 `
  123. # Sleep 1 second for each added item.
  124. Start-Sleep -Seconds 0.5
  125. }
  126. ### End of creating all the needed Users. ###
  127.  
  128. ### Start of creating all the Groups. ###
  129. ForEach ($Group in $Groups) {
  130. $Gname = $Group.Name
  131. $GManaged = $Group.Managed
  132. $GPath = $Group.Path
  133. $GDesc = $Group.Description
  134. $GCat = $Group.Category
  135. $GScope = $Group.Scope
  136.  
  137. New-ADGroup -Name $Gname -Managed $GManaged -Path $GPath `
  138. -Description $GDesc -GroupCatergory $GCat -GroupScope $GScope
  139. Start-Sleep -Seconds 0.5
  140. }
  141. ### End of creating all the Groups. ###
  142. ### Start of adding members to created Group. ###
  143. Foreach ( $Group in $Groups) {
  144. $GMember = $Group.Member
  145.  
  146.  
  147. Add-ADGroupMember -Identity $Gname -Members $GMember -Credentials $UserPass -Server $CurDomain
  148. Start-Sleep -Seconds 0.5
  149. }
  150. ### Start of adding members to created Group. ###
  151.  
  152. ### Start enabling RDP on Server. ###
  153. set-ItemProperty -Path 'HKLM:SystemCurrentControlSetControlTerminal Server' `
  154. -name "fDenyTSConnections" -Value 0
  155. Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
  156. set-ItemProperty -Path 'HKLM:SystemCurrentControlSetControlTerminal ServerWinStationsRDP-Tcp' `
  157. -name "UserAuthentication" -Value 1
  158. ### End enabling RDP on Server. ###
  159.  
  160. ### Start Creating GPO's. ###
  161.  
  162. Write-Output $ReqNewGpo
  163. If ($ReqNewGpo -in $Y){
  164. New-GPO -Name $ReqNewGPOName -Comment $GPOComment -Domain $CurDomain -Confirm:0
  165. }
  166. ElseIf ($ReqNewGpo -in $N) {
  167. Write-Output (Read-Host -Prompt "No new GPO will be added, continuing to enxt step.")
  168. }
  169. Else {
  170. Write-Output "Wrong input, please try again"
  171. }
  172. ### End Creating GPO's. ###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement