Created
December 18, 2018 08:16
-
-
Save FriedrichWeinmann/49892d55e7905cc197f72b010828c1ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scriptBlock = { | |
Connect-Lab | |
$id = "<id>" | |
$labname = "wsFund$($id)" | |
$domainName = "lab$($id).contoso.com" | |
$labSources = 'C:\LabSources' | |
$image = 'Windows Server 2016 Datacenter Evaluation (Desktop Experience)' | |
New-LabDefinition -Name $labname -DefaultVirtualizationEngine HyperV | |
$parameters = @{ | |
Memory = 2GB | |
OperatingSystem = $image | |
} | |
Add-LabMachineDefinition -Name "L$($id)DC" @parameters | |
Add-LabMachineDefinition -Name "L$($id)AdminHost" @parameters | |
Add-LabMachineDefinition -Name "L$($id)Exchange" @parameters | |
Install-Lab | |
Install-LabWindowsFeature -ComputerName "L$($id)AdminHost" -FeatureName NET-Framework-Core, NET-Non-HTTP-Activ, GPMC, RSAT-AD-Tools | |
Install-LabWindowsFeature -ComputerName L1DC -FeatureName AD-Domain-Services, DNS -IncludeManagementTools | |
$domcred = New-Object PSCredential("lab$($id)\Administrator", ("Somepass1" | ConvertTo-SecureString -AsPlainText -Force)) | |
Invoke-LabCommand -ComputerName "L$($id)DC" -ArgumentList $domainName, $domcred -ScriptBlock { | |
param ($DomainName, $Domcred) | |
Install-ADDSForest -DomainName $DomainName -InstallDNS -SafeModeAdministratorPassword $Domcred.Password -Force -Confirm:$false | |
} | |
Start-Sleep -Seconds 600 | |
Invoke-LabCommand -ComputerName "L$($id)AdminHost", "L$($id)Exchange" -ArgumentList (Get-LabVM -ComputerName "L$($id)DC").IpV4Address -ScriptBlock { | |
param ($Address) | |
$ifindex = (Get-NetIPInterface "Ethernet" -AddressFamily IPV4).IfIndex | |
Set-DnsClientServerAddress -InterfaceIndex $ifindex -ServerAddresses $Address | |
} | |
Invoke-LabCommand -ComputerName "L$($id)AdminHost", "L$($id)Exchange" -ArgumentList $domcred, $domainName -ScriptBlock { | |
param ($Credential, $DomainName) | |
Add-Computer -DomainName $DomainName -Credential $Credential -Restart -Force | |
} | |
Start-Sleep -Seconds 300 | |
Invoke-LabCommand -ComputerName "L$($id)DC", "L$($id)AdminHost", "L$($id)Exchange" -ScriptBlock { | |
$null = New-Item -Path C:\ -Name Scripts -ItemType Directory -Force | |
} -Credential $domcred | |
$dcsession = New-LabPSSession -ComputerName "L$($id)DC" -Credential $domcred | |
Copy-Item -Path C:\LabSources\PostInstallationActivities\PrepareFirstChildDomain\LabUsers.txt -Destination C:\Scripts -ToSession $dcsession | |
Copy-Item -Path 'C:\LabSources\PostInstallationActivities\PrepareFirstChildDomain\New-ADLabAccounts 2.0.ps1' -Destination C:\Scripts -ToSession $dcsession | |
Invoke-LabCommand -ComputerName "L$($id)DC" -Credential $domcred -ScriptBlock { | |
& 'C:\Scripts\New-ADLabAccounts 2.0.ps1' | |
} | |
} | |
foreach ($number in (1 .. 1)) | |
{ | |
$encodedCommand = [scriptblock]::Create($scriptBlock.ToString().Replace("<id>", $number)) | Convert-PSUObject script encoded | |
Start-Process powershell.exe -Verb RunAs -ArgumentList "-NoExit", "-EncodedCommand", $encodedCommand | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment