Standardize logging
This commit is contained in:
@@ -1,21 +1,13 @@
|
|||||||
# Purpose: Sets up the Server and Workstations OUs
|
# Purpose: Sets up the Server and Workstations OUs
|
||||||
|
|
||||||
Write-Host "$('[{0:HH:mm}]' -f (Get-Date)) Checking AD services status..."
|
# Hardcoding DC hostname in hosts file to sidestep any DNS issues
|
||||||
$svcs = "adws","dns","kdc","netlogon"
|
|
||||||
Get-Service -name $svcs -ComputerName localhost | Select Machinename,Name,Status
|
|
||||||
|
|
||||||
# Hardcoding DC hostname in hosts file
|
|
||||||
Add-Content "c:\windows\system32\drivers\etc\hosts" " 192.168.38.102 dc.windomain.local"
|
Add-Content "c:\windows\system32\drivers\etc\hosts" " 192.168.38.102 dc.windomain.local"
|
||||||
|
|
||||||
# Force DNS resolution of the domain
|
|
||||||
ping /n 1 dc.windomain.local
|
|
||||||
ping /n 1 windomain.local
|
|
||||||
|
|
||||||
Write-Host "$('[{0:HH:mm}]' -f (Get-Date)) Creating Server and Workstation OUs..."
|
Write-Host "$('[{0:HH:mm}]' -f (Get-Date)) Creating Server and Workstation OUs..."
|
||||||
# Create the Servers OU if it doesn't exist
|
# Create the Servers OU if it doesn't exist
|
||||||
$servers_ou_created = 0
|
$servers_ou_created = 0
|
||||||
while ($servers_ou_created -ne 1) {
|
while ($servers_ou_created -ne 1) {
|
||||||
Write-Host "$('[{0:HH:mm}]' -f (Get-Date)) Creating Server OU"
|
Write-Host "$('[{0:HH:mm}]' -f (Get-Date)) Creating Server OU..."
|
||||||
try {
|
try {
|
||||||
Get-ADOrganizationalUnit -Identity 'OU=Servers,DC=windomain,DC=local' | Out-Null
|
Get-ADOrganizationalUnit -Identity 'OU=Servers,DC=windomain,DC=local' | Out-Null
|
||||||
Write-Host "Servers OU already exists. Moving On."
|
Write-Host "Servers OU already exists. Moving On."
|
||||||
@@ -23,7 +15,7 @@ while ($servers_ou_created -ne 1) {
|
|||||||
}
|
}
|
||||||
catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
|
catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
|
||||||
New-ADOrganizationalUnit -Name "Servers" -Server "dc.windomain.local"
|
New-ADOrganizationalUnit -Name "Servers" -Server "dc.windomain.local"
|
||||||
Write-Host "Created Servers OU."
|
Write-Host "$('[{0:HH:mm}]' -f (Get-Date)) Created Servers OU."
|
||||||
$servers_ou_created = 1
|
$servers_ou_created = 1
|
||||||
}
|
}
|
||||||
catch [Microsoft.ActiveDirectory.Management.ADServerDownException] {
|
catch [Microsoft.ActiveDirectory.Management.ADServerDownException] {
|
||||||
@@ -38,7 +30,7 @@ while ($servers_ou_created -ne 1) {
|
|||||||
# Create the Workstations OU if it doesn't exist
|
# Create the Workstations OU if it doesn't exist
|
||||||
$workstations_ou_created = 0
|
$workstations_ou_created = 0
|
||||||
while ($workstations_ou_created -ne 1) {
|
while ($workstations_ou_created -ne 1) {
|
||||||
Write-Host "$('[{0:HH:mm}]' -f (Get-Date)) Creating Workstations OU"
|
Write-Host "$('[{0:HH:mm}]' -f (Get-Date)) Creating Workstations OU..."
|
||||||
try {
|
try {
|
||||||
Get-ADOrganizationalUnit -Identity 'OU=Workstations,DC=windomain,DC=local' | Out-Null
|
Get-ADOrganizationalUnit -Identity 'OU=Workstations,DC=windomain,DC=local' | Out-Null
|
||||||
Write-Host "Workstations OU already exists. Moving On."
|
Write-Host "Workstations OU already exists. Moving On."
|
||||||
@@ -46,7 +38,7 @@ Write-Host "$('[{0:HH:mm}]' -f (Get-Date)) Creating Workstations OU"
|
|||||||
}
|
}
|
||||||
catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
|
catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
|
||||||
New-ADOrganizationalUnit -Name "Workstations" -Server "dc.windomain.local"
|
New-ADOrganizationalUnit -Name "Workstations" -Server "dc.windomain.local"
|
||||||
Write-Host "Created Workstations OU."
|
Write-Host "$('[{0:HH:mm}]' -f (Get-Date)) Created Workstations OU."
|
||||||
$workstations_ou_created = 1
|
$workstations_ou_created = 1
|
||||||
}
|
}
|
||||||
catch [Microsoft.ActiveDirectory.Management.ADServerDownException] {
|
catch [Microsoft.ActiveDirectory.Management.ADServerDownException] {
|
||||||
|
|||||||
Reference in New Issue
Block a user