Create user in correct OU

The following script was working fine untill I upgraded to v5. Did anything change in v5 that would prevent this script from working? For example, does this script need to be reqwitten in PowerShell?

I am using this script in an update job, under the "Updating Rules", "Rules to Move Object" (generated by script)

$userLocation = $srcObj["DepartmentDescription"]

$CentralEntitlements = "OU=Users,OU=Central Entitlements,OU=Support Services,DC=domain,DC=ad"

$CentralMaint = "OU=Users,OU=Central Maintenance,OU=Support Services,DC=domain,DC=ad"

$Executive = "OU=Users,OU=Executive,OU=Support Services,DC=domain,DC=ad"

$Facilities = "OU=Users,OU=Facilities,OU=Support Services,DC=domain,DC=ad"

$Finance = "OU=Users,OU=Finance,OU=Support Services,DC=domain,DC=ad"

$HR = "OU=Users,OU=Human Resources,OU=Support Services,DC=domain,DC=ad"

$IT = "OU=Users,OU=Information Technology,OU=Support Services,DC=domain,DC=ad"

$Payroll = "OU=Users,OU=Finance,OU=Support Services,DC=domain,DC=ad"

$Purchasing = "OU=Users,OU=Purchasing,OU=Support Services,DC=domain,DC=ad"

$QA = "OU=Users,OU=Quality Assurance,OU=Support Services,DC=domain,DC=ad"

$RD = "OU=Users,OU=Resource Development,OU=Support Services,DC=domain,DC=ad"

"102101-SS-Central Maint." {$container = $CentralMaint; break}

"103101-SS-Executive" {$container = $Executive; break}

"104101-SS-Facilities" {$container = $Facilities; break}

"105101-SS-Finance" {$container = $Finance; break}

"106101-SS-HR" {$container = $HR; break}

"107101-SS-IT" {$container = $IT; break}

"108101-SS-Payroll" {$container = $Payroll; break}

"109101-SS-Purchasing" {$container = $Purchasing; break}

"110101-SS-QA" {$container = $QA; break}

"111101-SS-R&D" {$container = $RD; break}

default {$container = $lostandfound}

}

# Return Organizational Unit DN

$container

Thanks!

Didi

  • it appears that you are missing the actual Switch statement in the code. Try this below:

    ******************************************************************************************************

    $userLocation = $srcObj["DepartmentDescription"]

     

    $CentralEntitlements = "OU=Users,OU=Central Entitlements,OU=Support Services,DC=domain,DC=ad"

    $CentralMaint = "OU=Users,OU=Central Maintenance,OU=Support Services,DC=domain,DC=ad"

    $Executive = "OU=Users,OU=Executive,OU=Support Services,DC=domain,DC=ad"

    $Facilities = "OU=Users,OU=Facilities,OU=Support Services,DC=domain,DC=ad"

    $Finance = "OU=Users,OU=Finance,OU=Support Services,DC=domain,DC=ad"

    $HR = "OU=Users,OU=Human Resources,OU=Support Services,DC=domain,DC=ad"

    $IT = "OU=Users,OU=Information Technology,OU=Support Services,DC=domain,DC=ad"

    $Payroll = "OU=Users,OU=Finance,OU=Support Services,DC=domain,DC=ad"

    $Purchasing = "OU=Users,OU=Purchasing,OU=Support Services,DC=domain,DC=ad"

    $QA = "OU=Users,OU=Quality Assurance,OU=Support Services,DC=domain,DC=ad"

    $RD = "OU=Users,OU=Resource Development,OU=Support Services,DC=domain,DC=ad"

    switch ($userLocation) {

    "102101-SS-Central Maint." {$container = $CentralMaint; break}

    "103101-SS-Executive" {$container = $Executive; break}

    "104101-SS-Facilities" {$container = $Facilities; break}

    "105101-SS-Finance" {$container = $Finance; break}

    "106101-SS-HR" {$container = $HR; break}

    "107101-SS-IT" {$container = $IT; break}

    "108101-SS-Payroll" {$container = $Payroll; break}

    "109101-SS-Purchasing" {$container = $Purchasing; break}

    "110101-SS-QA" {$container = $QA; break}

    "111101-SS-R&D" {$container = $RD; break}

    default {$container = $lostandfound}

    }

     

    # Return Organizational Unit DN

    $container

  • Thanks! That was the issue. Imust have inadvertently overwritten the switch statement.