IT ALIVE
This commit is contained in:
parent
1d142bbe7b
commit
2088972db4
|
@ -2,7 +2,7 @@
|
||||||
# Contact: rayyan.hodges@studytafensw.edu.au
|
# Contact: rayyan.hodges@studytafensw.edu.au
|
||||||
# Program Name: AutoOUADCreator
|
# Program Name: AutoOUADCreator
|
||||||
# Purpose of script: Create a batch set of OU' using a CSV file within an existing Active Directory Forest.
|
# Purpose of script: Create a batch set of OU' using a CSV file within an existing Active Directory Forest.
|
||||||
# Extra Notes: Modify line 37 with appropriate domain info. (AlphaDelta.com is used in this scenario)
|
# Extra Notes: Modify line 37 and 59 with appropriate domain info. (AlphaDelta.com is used in this scenario)
|
||||||
|
|
||||||
#Import the Active Directory module to allow modifcations to the forest.
|
#Import the Active Directory module to allow modifcations to the forest.
|
||||||
import-module ActiveDirectory
|
import-module ActiveDirectory
|
||||||
|
@ -29,13 +29,16 @@ echo $fpath
|
||||||
#Create OU's within the Active Directory forest by looping throughout each row within the CSV file.
|
#Create OU's within the Active Directory forest by looping throughout each row within the CSV file.
|
||||||
foreach ($row in $fous) {
|
foreach ($row in $fous) {
|
||||||
# Get the name of the OU from the CSV
|
# Get the name of the OU from the CSV
|
||||||
$ouName = $row.Name
|
$ouName = $row.ouName
|
||||||
|
|
||||||
|
# Debug output - Check if program is actually reading CSV containing OU names.
|
||||||
|
Write-Host "Processing OU name: '$ouName'"
|
||||||
|
|
||||||
# Ensure $ouName is not null or empty
|
# Ensure $ouName is not null or empty
|
||||||
if (-not [string]::IsNullOrWhiteSpace($ouName)) {
|
if (-not [string]::IsNullOrWhiteSpace($ouName)) {
|
||||||
# Get all existing OUs in the specified path
|
# Get all existing OUs in the specified path
|
||||||
try {
|
try {
|
||||||
$existingOUs = Get-ADOrganizationalUnit -Filter * -SearchBase "DC=PSTest,DC=local" | Select-Object -ExpandProperty Name
|
$existingOUs = Get-ADOrganizationalUnit -Filter * -SearchBase "DC=alphadelta,DC=com" | Select-Object -ExpandProperty Name
|
||||||
} catch {
|
} catch {
|
||||||
Write-Host "Error retrieving existing OUs: $_"
|
Write-Host "Error retrieving existing OUs: $_"
|
||||||
exit
|
exit
|
||||||
|
@ -50,10 +53,10 @@ foreach ($existingOU in $existingOUs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i if (-not $ouExists) {
|
if (-not $ouExists) {
|
||||||
# Create the OU
|
# Create the OU
|
||||||
try {
|
try {
|
||||||
New-ADOrganizationalUnit -Name $ouName -Path "DC=PSTest,DC=local" -ErrorAction Stop
|
New-ADOrganizationalUnit -Name $ouName -Path "DC=alphadelta,DC=com" -ErrorAction Stop
|
||||||
Write-Host "OU '$ouName' created successfully."
|
Write-Host "OU '$ouName' created successfully."
|
||||||
} catch {
|
} catch {
|
||||||
Write-Host "Error creating OU '$ouName': $_"
|
Write-Host "Error creating OU '$ouName': $_"
|
||||||
|
|
Loading…
Reference in New Issue