Skip to content

Instantly share code, notes, and snippets.

@bill-long
Last active August 20, 2020 11:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bill-long/04f2e34143553ea3ee35e3322170559b to your computer and use it in GitHub Desktop.
Save bill-long/04f2e34143553ea3ee35e3322170559b to your computer and use it in GitHub Desktop.
<#
Examples
Create a DC:
iex ((New-Object System.Net.WebClient).DownloadString('https://gist.github.com/bill-long/04f2e34143553ea3ee35e3322170559b/raw'))
SetupServer -ComputerName LAB7DC1 -IpAddress "10.7.0.1" -PrefixLength 8 -Gateway "10.0.0.1" -DnsServer "10.0.0.1" -DomainName "bilonglab7.com" -MakeForest
Create an Exchange server:
iex ((New-Object System.Net.WebClient).DownloadString('https://gist.github.com/bill-long/04f2e34143553ea3ee35e3322170559b/raw'))
SetupServer -ComputerName LAB7E19-1 -IpAddress "10.7.0.2" -PrefixLength 8 -Gateway "10.0.0.1" -DnsServer "10.7.0.1" -DomainName "bilonglab7.com" -InstallExchange -ExchangeMediaPath "D:\"
If the WebClient throws a TLS error try:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
#>
function SetupServer(
[Parameter(Mandatory=$true) ] [string] $ComputerName,
[Parameter(Mandatory=$true) ] [string] $IpAddress,
[Parameter(Mandatory=$true) ] [int] $PrefixLength,
[Parameter(Mandatory=$true) ] [string] $Gateway,
[Parameter(Mandatory=$true) ] [string] $DnsServer,
[Parameter(Mandatory=$false)] [switch] $MakeForest = $false,
[Parameter(Mandatory=$true) ] [string] $DomainName,
[Parameter(Mandatory=$false)] [switch] $InstallExchange = $false,
[Parameter(Mandatory=$false)] [string] $ExchangeMediaPath = "D:\")
{
if ($env:computername -ne $ComputerName) {
Rename-Computer $ComputerName
Restart-Computer
}
if ($null -eq (Get-NetIPAddress | ? { $_.IPAddress -eq $IpAddress }))
{
Get-NetAdapter | ? { $_.InterfaceAlias -eq "Ethernet" } | % {
New-NetIPAddress -InterfaceIndex $_.InterfaceIndex -IPAddress $IpAddress -PrefixLength $PrefixLength -DefaultGateway $Gateway
Set-DnsClientServerAddress -InterfaceIndex $_.InterfaceIndex -ServerAddresses $DnsServer
}
}
if ($null -eq $env:UserDnsDomain)
{
if ($MakeForest) {
Install-WindowsFeature AD-Domain-Services
Import-Module ADDSDeployment
Install-ADDSForest -DomainName $DomainName
} else {
Add-Computer -DomainName $DomainName -Restart
}
}
if ($InstallExchange) {
# .net 4.7.2
Invoke-WebRequest http://go.microsoft.com/fwlink/?LinkId=863262 -OutFile net472.exe
& ".\net472.exe" "/passive" | Out-Default
Remove-Item ".\net472.exe"
# Visual C++ 2013 redist
Invoke-WebRequest http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe -OutFile vcredist.exe
& ".\vcredist.exe" "/passive" | Out-Default
Start-Sleep 5 # Takes a few seconds for the file lock to go away
Remove-Item ".\vcredist.exe"
# UCMA
& (Join-Path $ExchangeMediaPath "UCMARedist\setup.exe") "/passive" | Out-Default
# Windows Features
Install-WindowsFeature Server-Media-Foundation, NET-Framework-45-Features, RPC-over-HTTP-proxy, RSAT-Clustering, RSAT-Clustering-CmdInterface, RSAT-Clustering-PowerShell, WAS-Process-Model, Web-Asp-Net45, Web-Basic-Auth, Web-Client-Auth, Web-Digest-Auth, Web-Dir-Browsing, Web-Dyn-Compression, Web-Http-Errors, Web-Http-Logging, Web-Http-Redirect, Web-Http-Tracing, Web-ISAPI-Ext, Web-ISAPI-Filter, Web-Metabase, Web-Mgmt-Service, Web-Net-Ext45, Web-Request-Monitor, Web-Server, Web-Stat-Compression, Web-Static-Content, Web-Windows-Auth, Web-WMI, RSAT-ADDS
& "D:\setup" "/role:mb,mt" "/IAcceptExchangeServerLicenseTerms" | Out-Default
}
Write-Host "Done!"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment