I'm trying to script user creation and am having issues with OU variables. I've managed to script the users to create in OU based on users department but I also need to do it based on location. I've pasted part of my script below, which works fine, I just want to know if there's an easy way of integrating Office variable into it so that if user office is New York and Department equals IT then move to NY IT OU for example. Our OU's are split by region and department so I understand it may be a little complicated but any pointers are appreciated. Thanks in advance.
If ($department -eq “IT”){
$OU = 'OU=IT,OU=London (LDN),OU=Europe,OU=Company Staffing,DC=testcompany,DC=local'
}elseIf($department -eq “Finance”){
$OU = 'OU=Finance,OU=London (LDN),OU=Europe,OU=Company Staffing,DC=testcompany,DC=local'
}elseIf($department -eq “Sales”){
$OU = 'OU=Sales,OU=London (LDN),OU=Europe,OU=Company Staffing,DC=testcompany,,DC=local'
}elseIf($department -eq “HR”){
$OU = 'OU=HR,OU=London (LDN),OU=Europe,OU=Company Staffing,DC=testcompany,,DC=local'
}elseIf($department -eq “Client Services”){
$OU = 'OU=Client Services,OU=London (LDN),OU=Europe,OU=Company Staffing,DC=testcompany,DC=local'
}else {$OU = 'OU=London (LDN),OU=Europe,OU=Company Staffing,DC=testcompany,DC=local'
}
New-ADUser `
-Department $Department `
-Name "$Firstname $Surname" `
-UserPrincipalName $UPN `
-Path $OU `
-GivenName $FirstName `
-Surname $Surname `
-SamAccountName "$FirstName.$Surname" `
-AccountPassword (Read-Host -AsSecureString "Input User Password") `
-ChangePasswordAtLogon $False `
-Company "Test" `
-Title $JobTitle `
-EmailAddress "$FirstName.$Surname@testcompany.com" `
-State "LDN" `
-Country "GB" `
-Office "LDN" `
-City "London" `
-DisplayName "$FirstName $Surname" `
-Enabled $True