-
Notifications
You must be signed in to change notification settings - Fork 0
/
Master.ps1
136 lines (129 loc) · 6.56 KB
/
Master.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
Write-Host "Install DC Step 1: Install-DC
Install DC Step 2: DC-Promo -DomainName <domain.com> [-AddDC]
Install Exchange Step 1: Install-ExchPreReq -Directory <C:\ExchFiles>
Install Exchange Setp 2 (once per domain): Prepare-Exchange -Directory <C:\ExchFiles>
Install Exchange Step 3: Install-Exchange -Directory <C:\ExchFiles>"
function Install-DC {
Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools -IncludeAllSubFeature
}
function DC-Promo {
param(
[string][Parameter(Mandatory=$true,Position=0)]$DomainName,
[switch]$AddDC
)
if($AddDC){
#Add DC to existing Forrest
$Creds = Get-Credential -Message "Enter Valid Crednetials to join the $DomainName Domain"
Install-ADDSDomainController -DomainName $DomainName -Credential $Creds -InstallDNS
}else{
#Create New Forest
Install-ADDSForest -DomainName $DomainName -InstallDNS
}
}
function Install-ExchPreReq{
param (
[string][Parameter(Mandatory=$true, Position=0)][ValidateScript({test-path $_})]$Directory
)
Push-Location $Directory #Change Dir to the given Directory
Get-ChildItem | ForEach-Object { Unblock-File $_ }
$myProcess = Start-Process "(1st) NDP471-KB4033342-x86-x64-AllOS-ENU.exe" -PassThru -ArgumentList "/q","/norestart"
$myProcess | Wait-Process
write-host ".NET Framework Installed" -ForegroundColor Green
$myProcess = Start-Process "(2nd)vcredist_x64.exe" -PassThru -ArgumentList "/passive","/norestart"
$myProcess | Wait-Process
Write-Host "Visiual C++ 2012 Installed" -ForegroundColor Green
$myProcess = Start-Process "(3rd)vcredist_x64.exe" -PassThru -ArgumentList "/install","/passive","/norestart"
$myProcess | Wait-Process
Write-Host "Visiual C++ 2013 Installed" -ForegroundColor Green
$myProcess = Start-Process "(4th)UcmaRuntimeSetup.exe" -PassThru -ArgumentList "/passive","/norestart"
$myProcess | Wait-Process
Write-Host "Unified Communications Managed API Installed" -ForegroundColor Green
#Pop-Location #return to previous directory
sleep 4
Install-WindowsFeature NET-Framework-45-Features, Server-Media-Foundation, RPC-over-HTTP-proxy, RSAT-Clustering, RSAT-Clustering-CmdInterface, RSAT-Clustering-Mgmt, 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-Lgcy-Mgmt-Console, Web-Metabase, Web-Mgmt-Console, Web-Mgmt-Service, Web-Net-Ext45, Web-Request-Monitor, Web-Server, Web-Stat-Compression, Web-Static-Content, Web-Windows-Auth, Web-WMI, Windows-Identity-Foundation, RSAT-ADDS
write-host "Installed Windows Features" -ForegroundColor Green
Write-Host "Will Reboot in 8 Sec." -ForegroundColor Red -BackgroundColor Black
sleep 8
Restart-Computer
}
function Prepare-Exchange{
param (
[string][Parameter(Mandatory=$true, Position=0)][ValidateScript({test-path $_})]$Directory
)
Set-Location $Directory
$mountResult = Mount-DiskImage C:\ExchFiles\ExchangeServer2016-x64-cu11.iso -PassThru
$DriveLetter = ($mountResult | Get-Volume).DriveLetter
$DriveLetter+=':\'
Push-Location $DriveLetter
$MyFile = $DriveLetter+"setup.exe"
if (!(test-path C:\ExchFiles)){
new-item -itemType Directory -path C:\ExchFiles | out-null
}
if (!(test-path C:\ExchFiles\SchemaPrepared.txt)){
$myProcess = Start-Process $MyFile -ArgumentList "/IAcceptExchangeServerLicenseTerms","/PrepareSchema" -PassThru
$myProcess | Wait-Process
if (Test-Path "AD:CN=ms-Exch-Schema-Version-Pt,$((Get-ADRootDSE).NamingContexts | Where-Object {$_ -like "*Schema*"})"){
new-item "C:\ExchFiles\SchemaPrepared.txt" -ItemType File -Force | out-null
}else{
Write-Warning "Something went terribly wrong preparing the schema. The Schema was not extended"
Write-host "Common Issues: Not running as Administrator. Not running as a domain user."
return -1
}
}
sleep 1
if (!(test-path C:\ExchFiles\ADPrepared.txt)){
$myProcess = Start-Process $MyFile -ArgumentList '/IAcceptExchangeServerLicenseTerms','/PrepareAD','/OrganizationName:"ORGANIZATION"' -PassThru
$myProcess | Wait-Process
new-item "C:\ExchFiles\ADPrepared.txt" -ItemType File -Force | out-null
}
sleep 1
if (!(Test-Path C:\ExchFiles\AllDomainsPrepared.txt)){
$myProcess = Start-Process $MyFile -ArgumentList "/IAcceptExchangeServerLicenseTerms","/PrepareAllDomains" -PassThru
$myProcess | Wait-Process
new-item "C:\ExchFiles\AllDomainsPrepared.txt" -ItemType File -Force | out-null
}
Pop-Location
Write-host "Completed, rebooting in 8 sec." -foregroundcolor Green
sleep 8
Restart-Computer
}
function Install-Exchange{
param (
[string][Parameter(Mandatory=$true, Position=0)][ValidateScript({test-path $_})]$Directory
)
set-Location $Directory
$mountResult = Mount-DiskImage C:\ExchFiles\ExchangeServer2016-x64-cu11.iso -PassThru
$DriveLetter = ($mountResult | Get-Volume).DriveLetter
$DriveLetter+=':\'
$MyFile = $DriveLetter+"setup.exe"
Push-Location $DriveLetter
$myProcess = Start-Process $myFile -ArgumentList "/IAcceptExchangeServerLicenseTerms","/Mode:Install","/Role:Mailbox" -PassThru
$myProcess | Wait-Process
#Restart-Computer
Pop-Location
}
function Move-Database{
param (
[string]$DriveLetter1,
[string]$DriveLetter2
)
$DBs = Get-mailboxDatabase
$i = 1
foreach ($DB in $DBs){
if (!($DB.Name -match "MBDB")){ #Make sure it hasn't already been renamed
Set-MailboxDatabase -identity $DB.Name -Name "MBDB0$i"
}
try{
Move-DatabasePath -Identity "MBDB0$i" -force -EdbFilePath $DriveLetter1"DB$i\MBDB0"$($i.tostring())".edb" -LogFolderPath $DriveLetter2"DB"$($i.tostring()) -errorAction Stop
}catch{
Write-Warning "Unable to move database MBDB0$i - It's probably not on this server and this command needs to be run on the server that it resides on.`nHeres the error: $_"
}
$i++
}
if (!((Get-SendConnector).AddressSpaces.Addrees -eq "*")){
New-SendConnector -Name Internet -AddressSpaces * -Internet -DNSRoutingEnabled $true
Write-Host "Created Send Connector for *"
}
Write-host "Renamed and moved Databases on this server"
Get-MailboxDatabase | Select-Object -Property Name,Server,edbfilepath,logfolderpath | FL
}