Files
DetectionLab/Vagrant/scripts/configure-ou.ps1
2019-03-24 10:08:19 +07:00

44 lines
1.8 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Purpose: Sets up the Server and Workstations OUs
Write-Host "Checking DNS Settings before starting..."
Get-DnsClientServerAddress | Select-Object ExpandProperty ServerAddresses
Write-Host "Hardcoding windomain.local via the hosts file"
Add-Content "c:\windows\system32\drivers\etc\hosts" " 192.168.38.102 windomain.local"
Add-Content "c:\windows\system32\drivers\etc\hosts" " 192.168.38.102 dc.windomain.local"
Write-Host "Checking AD services status..."
$svcs = "adws","dns","kdc","netlogon"
Get-Service -name $svcs -ComputerName localhost | Select Machinename,Name,Status
Write-Host "Creating Server and Workstation OUs..."
Write-Host "Creating Servers OU..."
Write-Host "DEBUG: $env:computername.$env:userdnsdomain"
try {
if (!([ADSI]::Exists("LDAP://OU=Servers,DC=windomain,DC=local")))
{
New-ADOrganizationalUnit -Name "Servers" -Server "dc.windomain.local"
}
else
{
Write-Host "Servers OU already exists. Moving On."
}
} catch {
New-ADOrganizationalUnit -Name "Servers" -Server "dc.windomain.local"
}
Write-Host "Creating Workstations OU"
try {
if (!([ADSI]::Exists("LDAP://OU=Workstations,DC=windomain,DC=local")))
{
New-ADOrganizationalUnit -Name "Workstations" -Server "dc.windomain.local"
}
else
{
Write-Host "Workstations OU already exists. Moving On."
}
} catch {
New-ADOrganizationalUnit -Name "Workstations" -Server "dc.windomain.local"
}
# Sysprep breaks auto-login. Let's restore it here:
Set-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name AutoAdminLogon -Value 1
Set-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name DefaultUserName -Value "vagrant"
Set-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name DefaultPassword -Value "vagrant"