Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param([string]$Stage)
- $ADDSSettings = @{
- Hostname = "SPDEV-DC"
- IPAddress = "192.168.0.225"
- }
- $SQLSettings = @{
- Hostname = "SPDEV-SQL"
- IPAddress = "192.168.0.226"
- JoinDomain = $True
- }
- $SP2010Settings = @{
- Hostname = "SPDEV-SP2010"
- IPAddress = "192.168.0.210"
- Version = "2010"
- JoinDomain = $True
- }
- $SP2013Settings = @{
- Hostname = "SPDEV-SP2013"
- IPAddress = "192.168.0.213"
- Version = "2013"
- JoinDomain = $True
- }
- $SetupPath = "D:"
- $AutoSPInstallerPath = "$SetupPath\Sharepoint\AutoSPInstaller"
- $NetBiosName = "pocketdomain"
- $TLD = "corp"
- $UserOU = "SharepointUsers"
- $DomainUsers = @(
- "SP_Farm",
- "SP_CacheSuperUser",
- "SP_CacheSuperReader",
- "SP_Services",
- "SP_PortalAppPool",
- "SP_ProfilesAppPool",
- "SP_SearchService",
- "SP_SearchContent",
- "SP_ProfileSync",
- "SP_VisioUser",
- "SP_PerfPointUser",
- "SP_ExcelUser"
- )
- $DNSServer = $ADDSSettings.IPAddress
- $NetMask = "255.255.255.0"
- $Gateway = "192.168.0.1"
- $Password = "Abc123!"
- $kms = "10.0.0.1"
- $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
- $DomainName = "$NetBiosName.$TLD"
- $UserPath = "OU=$UserOU,DC=$NetBiosName,DC=$tld"
- Function Add-Task ($Stage) {
- schtasks.exe /CREATE /RU 'builtin\users' /SC ONLOGON /RL HIGHEST /TN "$Stage" /tr "powershell.exe -file $SetupPath\Setup.ps1 -Stage $Stage"
- }
- if (!($Stage -match "First_Run")) {schtasks.exe /DELETE /TN "$Stage" /F}
- $First_Run_Scriptblock = {
- param($Settings)
- $Servername = $Settings.Hostname
- $IP = $Settings.IPAddress
- $JoinDomain = $Settings.JoinDomain
- cscript c:\windows\system32\slmgr.vbs /skms $kms:1688
- cscript c:\windows\system32\slmgr.vbs /ato
- cscript c:\windows\system32\slmgr.vbs /ato
- schtasks.exe /CHANGE /tn "\Microsoft\Windows\Server Manager\ServerManager" /disable
- net user administrator $Password
- New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name "AutoAdminLogon" -Value 1 -PropertyType String -Force
- New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name "DefaultUserName" -Value "Administrator" -PropertyType String -Force
- New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name "DefaultPassword" -Value $Password -PropertyType String -Force
- Write-Host "Setting network configuration..."
- $NetworkWMI = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'"
- $NetworkWMI.EnableStatic($IP, $NetMask)
- $NetworkWMI.SetGateways($Gateway, 1)
- $NetworkWMI.SetDNSServerSearchOrder($DNSServer)
- $ComputerWMI = Get-WmiObject win32_computersystem
- If ($Settings.Version) {[System.Environment]::SetEnvironmentVariable("Version", $Settings.Version, "Machine")}
- if ($JoinDomain) {
- $Counter = 0
- do {Write-Host "Waiting for $DomainName..."; $Counter++; Start-Sleep -Seconds 5}
- until ((Test-Connection $DomainName -quiet) -OR ($counter -eq 10))
- if (!(Test-Connection $DomainName)) {throw "Can't reach $DomainName"}
- $ComputerWMI.JoinDomainOrWorkGroup($DomainName, $Password, "$NetBiosName\Administrator", $Null, 23)
- $ComputerWMI.Rename($ServerName,$Password,"$NetBiosName\Administrator")
- New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name "DefaultUserName" -Value "$NetBiosName\Administrator" -PropertyType String -Force
- } else {
- Rename-Computer $Servername
- }
- }
- $Install_SQL_Scriptblock = {
- netsh advfirewall firewall add rule name="SQL" protocol=tcp dir=in localport=1433 action=allow enable=yes
- net user /add sqlagent $Password
- net user /add sqlengine $Password
- start-process -path "$SetupPath\SQL\setup.exe" -ArgumentList "/configurationfile=""$SetupPath\sql_configuration.ini""" -Wait
- }
- $Install_RSAT_Scriptblock = {
- Add-WindowsFeature -name "RSAT-AD-Tools"
- }
- $Install_ADDS_ScriptBlock = {
- Write-Host "Adding AD-Domain-Services"
- Add-WindowsFeature -Name "ad-domain-services" -IncludeAllSubFeature -IncludeManagementTools
- Write-Host "Adding DNS..."
- Add-WindowsFeature -Name "dns" -IncludeAllSubFeature -IncludeManagementTools
- Write-Host "Adding Group Policy Management Console..."
- Add-WindowsFeature -Name "gpmc" -IncludeAllSubFeature -IncludeManagementTools
- }
- $Install_Forest_Scriptblock = {
- Import-Module ADDSDeployment
- New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name "DefaultUserName" -Value "$NetBiosName\Administrator" -PropertyType String -Force
- Write-Host "Installing Forest..."
- $ForestSettings = @{
- CreateDNSDelegation = $False
- DatabasePath = "C:\Windows\NTDS"
- DomainMode = "Win2012"
- ForestMode = "Win2012"
- DomainName = $DomainName
- DomainNetbiosName = $NetBiosName
- InstallDns = $True
- LogPath = "C:\Windows\NTDS"
- NoRebootOnCompletion = $False
- SysvolPath = "C:\Windows\SYSVOL"
- Force = $True
- SafeModeAdministratorPassword = $SecurePassword
- }
- Install-ADDSForest @ForestSettings
- }
- $Setup_ADObjects_Scriptblock = {
- New-ADOrganizationalUnit "$UserOU"
- Foreach ($User in $DomainUsers) {New-ADUser $User -GivenName $User -Path $UserPath -Enabled $True -AccountPassword $SecurePassword}
- }
- $Install_PKI_Scriptblock = {
- Import-Module ServerManager
- Write-Host "Adding Certificate Services..."
- Add-WindowsFeature Adcs-Cert-Authority -IncludeManagementTools
- $PKISettings = @{
- CACommonName = "$env:COMPUTERNAME"
- CAType = "EnterpriseRootCA"
- CryptoProviderName = "RSA#Microsoft Software Key Storage Provider"
- KeyLength = 2048
- HashAlgorithmName = "SHA1 "
- ValidityPeriod = "Years"
- ValidityPeriodUnits = 3
- Force = $True
- }
- Install-AdcsCertificationAuthority @PKISettings
- }
- $Setup_Sharepoint_Scriptblock = {
- if ($Env:Version -eq "2013") {Import-Module ServerManager;Add-WindowsFeature Net-Framework-Features,Web-Server,Web-WebServer,Web-Common-Http,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-App-Dev,Web-Asp-Net,Web-Net-Ext,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Health,Web-Http-Logging,Web-Log-Libraries,Web-Request-Monitor,Web-Http-Tracing,Web-Security,Web-Basic-Auth,Web-Windows-Auth,Web-Filtering,Web-Digest-Auth,Web-Performance,Web-Stat-Compression,Web-Dyn-Compression,Web-Mgmt-Tools,Web-Mgmt-Console,Web-Mgmt-Compat,Web-Metabase,Application-Server,AS-Web-Support,AS-TCP-Port-Sharing,AS-WAS-Support, AS-HTTP-Activation,AS-TCP-Activation,AS-Named-Pipes,AS-Net-Framework,WAS,WAS-Process-Model,WAS-NET-Environment,WAS-Config-APIs,Web-Lgcy-Scripting,Windows-Identity-Foundation,Server-Media-Foundation,Xps-Viewer}
- Write-Host "Disabling UAC..."
- New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system' -Name EnableLUA -PropertyType DWord -Value 0 -Force
- Write-Host "Disabling IE first-run customization..."
- New-Item -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Internet Explorer\Main' -Force
- New-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Internet Explorer\Main' -name DisableFirstRunCustomize -PropertyType DWord -Value 1 -Force
- }
- $Install_Sharepoint_Scriptblock = {
- start-process -path "$AutoSPInstallerPath\AutoSPInstallerLaunch.bat" -ArgumentList "$AutoSPInstallerPath\PocketDomain-$env:Version.xml" -wait
- throw "Installing Sharepoint, no reboot required."
- }
- switch ($Stage)
- {
- "First_Run_ADDS" {&$First_Run_Scriptblock $ADDSSettings; Add-Task Install_RSAT}
- "First_Run_SQL" {&$First_Run_Scriptblock $SQLSettings; Add-Task Install_SQL}
- "First_Run_SP2013" {&$First_Run_Scriptblock $SP2010Settings; Add-Task Setup_Sharepoint}
- "First_Run_SP2010" {&$First_Run_Scriptblock $SP2013Settings; Add-Task Setup_Sharepoint}
- "Setup_Sharepoint" {&$Setup_Sharepoint_Scriptblock; Add-Task Install_Sharepoint}
- "Install_Sharepoint" {&$Install_Sharepoint_Scriptblock}
- "Install_RSAT" {&$Install_RSAT_Scriptblock; Add-Task Install_ADDS}
- "Install_SQL" {&$Install_SQL_Scriptblock}
- "Install_ADDS" {&$Install_ADDS_ScriptBlock; Add-Task Install_Forest}
- "Install_Forest" {&$Install_Forest_Scriptblock; Add-Task Install_PKI}
- "Install_PKI" {&$Install_PKI_Scriptblock; Add-Task Setup_ADObjects}
- "Setup_ADObjects" {&$Setup_ADObjects_Scriptblock}
- }
- if (!($Error[0])) {Restart-Computer} else {Write-Host "Errors!"; $Error | Select-Object * | Out-File c:\errors.txt -Append; notepad.exe c:\errors.txt}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement