Advertisement
D0cEvil

PowerShell - Install ADDs Domain Services Lab

Dec 6th, 2022
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 2.63 KB | Software | 0 0
  1. ###Script made by Michel Belanger###
  2.  
  3. ##set the ip appdress on net adapter##
  4.  
  5. ##Get name adapter and index##
  6. Get-NetAdapter
  7.  
  8. Write-Host ""
  9. Write-Host ""
  10. Write-Host ""
  11. $interfaceIndex = Read-Host "Enter the interfaceindex of the network adapter needed"
  12.  
  13. ##enter the prefix length##
  14. $prefixlength = Read-Host "Enter the prefix length"
  15.  
  16.  
  17. ##command to enter and verify the ipv4 address##
  18. $serverip = Read-Host "Enter a valid IPV4 for the network adapter card"
  19.  
  20. $iparr = $serverip.Split(".")
  21.  
  22. If($iparr.Length -ne 4)
  23.  
  24. {Write-Host "Enter a valid format xxx.xxx.xxx.xxx" -ForegroundColor Red}
  25.  
  26.  
  27. foreach ($bytes in $iparr)
  28.     {
  29.         if([int]$bytes -lt 0 -or [int]$bytes -gt 255)
  30.  
  31.         {Write-Host "Value must be between 0 and 255" -ForegroundColor red}    
  32.    
  33.     }
  34.  
  35.  
  36. ##Set the default Gateway##
  37. $GatewayIP = Read-Host "Enter a valid IPV4 for the default gateway"
  38.  
  39. $Gatewayiparr = $GatewayIP.Split(".")
  40.  
  41. If($Gatewayiparr.Length -ne 4)
  42.  
  43. {Write-Host "Enter a valid format xxx.xxx.xxx.xxx" -ForegroundColor Red}
  44.  
  45.  
  46. foreach ($bytes in $Gatewayiparr)
  47.     {
  48.         if([int]$bytes -lt 0 -or [int]$bytes -gt 255)
  49.  
  50.         {Write-Host "Value must be between 0 and 255" -ForegroundColor red}    
  51.    
  52.     }
  53.  
  54. ##set dns server Adress##
  55. New-NetIPAddress -InterfaceIndex $interfaceIndex -IPAddress $serverip -PrefixLength $prefixlength -DefaultGateway $GatewayIP
  56. Set-dnsclientserveraddress -interfaceindex $interfaceIndex -serveraddresses $serverip
  57.  
  58.  
  59. ##Install ADDs Domain Services
  60. install-windowsfeature -name ad-domain-services
  61.  
  62. ##Set a secure string Password##
  63. $password = Read-Host "Enter your secure password"
  64. $SecurePassword = convertto-securestring -asplaintext -string $password -Force
  65.  
  66. ##Install the new Forest##
  67.  
  68. ##Enter the Domain name##
  69. $DomainName = Read-Host "Enter the domain name"
  70.  
  71. ##Remove the .com for the net Bios Name##
  72. $NetBiosName = $DomainName
  73. $BiosName = $NetBiosName.Split(".")
  74.  
  75. ## Enter the Domain Mode##
  76. ##$DomainMode = Read-Host "Enter the domain mode"
  77.  
  78. #Enter the Forest name##
  79. ##$ForestMode = Read-Host "Enter the Forest mode"
  80.  
  81. ##Enter the DataBase Path##
  82. $DataBasePath = Read-Host "Enter the database Path"
  83.  
  84. ##Enter the Log Path##
  85. $LogPath = Read-Host "Enter the Log Path"
  86.  
  87. ##Enter the SysVol Path##
  88. $SysVolPath = Read-Host "Enter the SysVol Path"
  89.  
  90.  
  91. install-addsforest -domainname $DomainName -safemodeadministratorpassword $SecurePassword -domainnetbiosname $BiosName[0] -domainmode win2012r2 -forestmode win2012r2 -databasepath $DataBasePath -logpath $LogPath -sysvolpath $SysVolPath -norebootoncompletion -installdns
  92.  
  93.  
  94. ##Command to restart computer##
  95. Restart-Computer -Confirm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement