Add try/catch to configure-ou.ps1
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
# Purpose: Sets up the Server and Workstations OUs
|
# Purpose: Sets up the Server and Workstations OUs
|
||||||
Write-Host "Creating Server and Workstation OUs..."
|
Write-Host "Creating Server and Workstation OUs..."
|
||||||
Write-Host "Creating Servers OU..."
|
Write-Host "Creating Servers OU..."
|
||||||
|
Write-Host "DEBUG: $env:computername.$env:userdnsdomain"
|
||||||
|
try {
|
||||||
if (!([ADSI]::Exists("LDAP://OU=Servers,DC=windomain,DC=local")))
|
if (!([ADSI]::Exists("LDAP://OU=Servers,DC=windomain,DC=local")))
|
||||||
{
|
{
|
||||||
New-ADOrganizationalUnit -Name "Servers" -Server "dc.windomain.local"
|
New-ADOrganizationalUnit -Name "Servers" -Server "dc.windomain.local"
|
||||||
@@ -9,7 +11,12 @@ else
|
|||||||
{
|
{
|
||||||
Write-Host "Servers OU already exists. Moving On."
|
Write-Host "Servers OU already exists. Moving On."
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
New-ADOrganizationalUnit -Name "Servers" -Server "dc.windomain.local"}
|
||||||
|
}
|
||||||
|
|
||||||
Write-Host "Creating Workstations OU"
|
Write-Host "Creating Workstations OU"
|
||||||
|
try {
|
||||||
if (!([ADSI]::Exists("LDAP://OU=Workstations,DC=windomain,DC=local")))
|
if (!([ADSI]::Exists("LDAP://OU=Workstations,DC=windomain,DC=local")))
|
||||||
{
|
{
|
||||||
New-ADOrganizationalUnit -Name "Workstations" -Server "dc.windomain.local"
|
New-ADOrganizationalUnit -Name "Workstations" -Server "dc.windomain.local"
|
||||||
@@ -18,6 +25,10 @@ else
|
|||||||
{
|
{
|
||||||
Write-Host "Workstations OU already exists. Moving On."
|
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:
|
# 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 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 DefaultUserName -Value "vagrant"
|
||||||
|
|||||||
Reference in New Issue
Block a user