Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

How to control/validate the value of an AD user attribute compared against the value inside of a csv ?

I have the following:
Import-Csv $MasterFile | ForEach-Object {
$existsCOMPANY = Get-ADUser -LDAPFilter "(employeeNumber=$ClockNumber)" -SearchScope Subtree -SearchBase "OU=COMPANY,DC=DOMAIN,DC=COM"
.
.
.
}

Open in new window

If I am not wrong existsCOMPANY will hold the AD Users as long as they match the Clock Number pulled from the $Masterfile, correct?
If so, In the csv file, if i enter an employee with a clock number that matches a clock number of a user in AD, of course that user will not be part of $existsCOMPANY :(

How do I spit out that duplicate record (clock number) into a report?
Thanks for your help
0
namerg
Asked:
namerg
  • 22
  • 16
1 Solution
 
SubsunCommented:
I presume clocknumber is unique for each user..
If you are trying to get duplicate ClockNumber (header name in csv) values from CSV file.. Try..
Import-Csv $MasterFile | Group-Object ClockNumber | ? {$_.count -gt 1} | Select-Object -ExpandProperty Group

Open in new window

Same method can be used to find the duplicates from AD..
0
 
namergSystems AdministratorAuthor Commented:
Hmm, not quite. Let's say the csv file has the following records:
Khan,Salman,1500
Roshan,Hrithik,2500
Hamid,Bill,Annandale,3017
Holden,Stuart,Houston,3018
Howard,Tim,North Brunswick,3019

And, in AD in a specific OU i have AD Users but there might the posibility that a new employee from the master file, let's say Roshan,Hrithik,2500 has the same clock number as the AD user Maradona,Diego,Napoli,2500.
Not good, so of course the script will not create Roshan,Hrithik as an AD User, instead will create a report saying, sorry the following AD user has the same employeeNumber/clock number as Roshan,Hrithik,2500, AD user not created.

And, of course i do not want to break and change the whole code that we have been working :)

Thanks for your help,
0
 
SubsunCommented:
OK then try this..
PS : the header name of employeeNumber value should be ClockNumber..
$DupClock = @()
Import-Csv $MasterFile | ForEach-Object {
$existsCOMPANY = Get-ADUser -Filter 'employeeNumber -eq $_.ClockNumber' -SearchScope Subtree -SearchBase "OU=COMPANY,DC=DOMAIN,DC=COM"

	If ($existsCOMPANY)
	{
	$DupClock += $_
	}
}
$DupClock

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
namergSystems AdministratorAuthor Commented:
The header of the CSV must be Clock Number. I am getting errors:
Get-ADUser : A positional parameter cannot be found that accepts argument 'Clock'.
ERROR: At C:\scripts\ceridian\Ceridian_Create_AD_Users.ps1:33 char:35
ERROR: +    $DupClockNumberCOMPANY = Get-ADUser <<<<  -Filter "employeeNumber -eq $_."Clock Number"" -SearchScope Subtree -SearchBase "OU=COMPANY,DC=DOMAIN,DC=COM"
ERROR:     + CategoryInfo          : InvalidArgument: (:) [Get-ADUser], ParameterBindingException
ERROR:     + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser
ERROR:
0
 
SubsunCommented:
Try.. (Notice the single quotes)
Get-ADUser -Filter 'employeeNumber -eq $($_."Clock Number")'

Open in new window

or
$ClockNumber = $_."Clock Number"
Get-ADUser -Filter 'employeeNumber -eq $ClockNumber'

Open in new window

0
 
namergSystems AdministratorAuthor Commented:
I think I am getting confused, this is what i have:
$DupClock = @()
Import-Csv $MasterFile | ForEach-Object {
	$LastName = $_."Last Name" -replace "\s"
	$sam = $LastName.ToLower() + $_."First Name".substring(0,1).ToLower()
	$ClockNumber = $_."Clock Number"
	$SName = $sam
	$Count = 0
	While ($(try {Get-ADUser -Identity $sam}catch{}) -ne $null) {
		$Count++
		$sam  = $SName + $Count
	}
	$DupClockNumberCOMPANY = Get-ADUser -SearchBase "OU=COMPANY,DC=domain,DC=com" -Filter "(employeeNumber = $_.ClockNumber)
	If ($DupClockNumberCOMPANY)	{
		$DupClock += $_
	}
	Try {
		$existsCOMPANY = Get-ADUser -LDAPFilter "(employeeNumber=$ClockNumber)" -SearchScope Subtree -SearchBase "OU=upi,DC=domain,DC=com"
	#$existsUPI_OU = existsUPI_OU
		$existsNewUsers = Get-ADUser -LDAPFilter "(employeeNumber=$ClockNumber)" -SearchScope Subtree -SearchBase "OU=COMPANY - New Users,DC=comain,DC=com"
	}
	.
	.
	.
}
$DupClock | Sort-Object -Property sn, givenName | Select SamAccountName,Surname,GivenName,Name,Department,Title,TelephoneNumber,EmployeeNumber | Export-Csv $DupClockNumberCOMPANYLog -NoTypeInformation

Open in new window

0
 
namergSystems AdministratorAuthor Commented:
still getting errors. I tried both of your suggestions. :(
0
 
namergSystems AdministratorAuthor Commented:
I got it.
 $DupClockNumberUPI = Get-ADUser -SearchBase "OU=COMPANY,DC=DOMAIN,DC=COM" -Filter 'employeeNumber -eq $ClockNumber'
   If ($DupClockNumberCOMPANY)	{
   		$DupClock += $_
	}

Open in new window

It did create the file 06-06-2013_Ceridian_Dup_ClockNumberCOMPANY_LOG.csv but empty :(
0
 
SubsunCommented:
Try..
$DupClock = @()
Import-Csv $MasterFile | ForEach-Object {
$CsvLine = $_
	$LastName = $_."Last Name" -replace "\s"
	$sam = $LastName.ToLower() + $_."First Name".substring(0,1).ToLower()
	$ClockNumber = $_."Clock Number"
	$SName = $sam
	$Count = 0
	While ($(try {Get-ADUser -Identity $sam}catch{}) -ne $null) {
		$Count++
		$sam  = $SName + $Count
	}
	$DupClockNumberCOMPANY = Get-ADUser -SearchBase "OU=COMPANY,DC=domain,DC=com" -Filter "(employeeNumber = $ClockNumber)"
	If ($DupClockNumberCOMPANY)	{
		$DupClock += $CsvLine
	}
#Rest of the code
}
$DupClock | Sort-Object -Property sn, givenName | Select * | Export-Csv $DupClockNumberCOMPANYLog -NoTypeInformation

Open in new window

0
 
namergSystems AdministratorAuthor Commented:
:( It creates the file but empty.
It shoud output something like:
*****Same Clock Number AD User, Maradona,Diego,Napoli,2500.
*****Same Clock Number for New User,Roshan,Hrithik,2500
New User, cannot be created, please take proper action

Thanks for your help.
0
 
SubsunCommented:
What result you get for
Get-ADUser -SearchBase "OU=COMPANY,DC=domain,DC=com" -Filter "(employeeNumber = "2500")"

Open in new window

0
 
namergSystems AdministratorAuthor Commented:
By the way if I use (=) sign, it breaks I have to use -eq
0
 
namergSystems AdministratorAuthor Commented:
I do not think the following line is not doing anything.
$DupClockNumberUPI = Get-ADUser -SearchBase "OU=COMPANY,DC=DOMAIN,DC=COM" -Filter 'employeeNumber -eq "2500" '

Open in new window

or
$DupClockNumberUPI = Get-ADUser -SearchBase "OU=COMPANY,DC=DOMAIN,DC=COM" -Filter 'employeeNumber -eq 2500 '

Open in new window

0
 
SubsunCommented:
Try without using a any var's (I am not sure if you are using same Var's in condition..)
If (Get-ADUser -Filter 'employeeNumber -eq $ClockNumber')	{$DupClock += $CsvLine}

Open in new window


$DupClock = @()
Import-Csv $MasterFile | ForEach-Object {
$CsvLine = $_
	$LastName = $_."Last Name" -replace "\s"
	$sam = $LastName.ToLower() + $_."First Name".substring(0,1).ToLower()
	$ClockNumber = $_."Clock Number"
	$SName = $sam
	$Count = 0
	While ($(try {Get-ADUser -Identity $sam}catch{}) -ne $null) {
		$Count++
		$sam  = $SName + $Count
	}
	If (Get-ADUser -Filter 'employeeNumber -eq $ClockNumber'){$DupClock += $CsvLine}
#Rest of the code
}
$DupClock | Sort-Object -Property sn, givenName | Select * | Export-Csv $DupClockNumberCOMPANYLog -NoTypeInformation

Open in new window

0
 
namergSystems AdministratorAuthor Commented:
Nada... :(
The beginning of the whole function
Function createUsers
{
  $Out0 = "Created following users (on " + $date + "): " + "," + "LastName" + "," + "FirstName" + "," + "ClockNumber" + "," + "SamAccount" + "," + "Pass"
  Add-Content -Value $Out0 -Path $NewADUsersLog -Encoding UTF8
  $Out1 = "--------------------------------------------"
  Add-Content -Value $Out1 -Path $NewADUsersLog -Encoding UTF8
  $DupClock = @()  
  Import-Csv $MasterFile | ForEach-Object {
  $CsvLine = $_
  $LastName = $_."Last Name" -replace "\s"
  $sam = $LastName.ToLower() + $_."First Name".substring(0,1).ToLower()
  $ClockNumber = $_."Clock Number"
  $SName = $sam
  $Count = 0
   While ($(try {Get-ADUser -Identity $sam}catch{}) -ne $null) {
	  $Count++
	  $sam  = $SName + $Count
	}
	$DupClockNumberCOMPANY = Get-ADUser -SearchBase "OU=COMPANY,DC=domain,DC=com" -Filter 'employeeNumber -eq $ClockNumber'
	If ($DupClockNumberCOMPANY)	{
		$DupClock += $CsvLine
	}
   Try   {
      	$existsCOMPANY = Get-ADUser -LDAPFilter "(employeeNumber=$ClockNumber)" -SearchScope Subtree -SearchBase "OU=COMPANY,DC=domain,DC=com"
      	$existsNewUsers = Get-ADUser -LDAPFilter "(employeeNumber=$ClockNumber)" -SearchScope Subtree -SearchBase "OU=COMPANY - New Users,DC=domain,DC=com"
      }
   Catch { }
   .
   .
   .
   .
   }
	"----------------------------------------" + "`n" | Out-File $NewADUsersLog -append
  $DupClock | Sort-Object -Property sn, givenName | select SamAccountName,Surname,GivenName,Name,Department,Title,TelephoneNumber,EmployeeNumber | Export-Csv $DupClockNumberCOMPANYLog -NoTypeInformation
}   

Open in new window

0
 
SubsunCommented:
Change line 34 to following and see if you get anything in output file..
$DupClock | select * | Export-Csv $DupClockNumberCOMPANYLog -NoTypeInformation

Open in new window

0
 
namergSystems AdministratorAuthor Commented:
Now we are talking... :) but it logged a bunch of users, it should have logged only one AD user, the one with the duplicate clock number.
0
 
SubsunCommented:
We didn't add the AD user yet.. Once we fix the result then we can add the log..

Remove the following lines and
$DupClockNumberCOMPANY = Get-ADUser -SearchBase "OU=COMPANY,DC=domain,DC=com" -Filter 'employeeNumber -eq $ClockNumber'
	If ($DupClockNumberCOMPANY)	{
		$DupClock += $CsvLine
	}

Open in new window


Add
If (Get-ADUser -SearchBase "OU=COMPANY,DC=domain,DC=com" -Filter 'employeeNumber -eq $ClockNumber') {$DupClock += $CsvLine}

Open in new window


and check the result...
0
 
namergSystems AdministratorAuthor Commented:
+-
I got a result but less users now, 5 users.It should be only one.
0
 
SubsunCommented:
Hmm... Are you sure?? I just tested it and it's working for me as expected.. Did you check this 5 user's  employeeNumber  already exist in AD?
0
 
namergSystems AdministratorAuthor Commented:
Yes, I am sure...let me be more descriptive. I will paste the contents of the master file and the contents of the dump file.....give me a sec...
0
 
namergSystems AdministratorAuthor Commented:
Master CSV File
Last Name,First Name,Job Title,Clock Number
Holden,Stuart,Houston,3018
D,T,Senior Specialist,1474
C,J,Senior Payment Specialist,1559
Howard,Tim,North Brunswick,3019
Maradona,Diego,Napoli,2208
Johnson,Eddie,Palm Coast,3020
Johnson,Fabian,Munich,3021
F,M,Decision Support Manager,1664
Johnson,Sean,Lilburn,3022
G,Michelle,Applications Support Manager,1737
Morgan, Anna, Seattle Sounders,3052
Morgan, Anna, Seattle Sounders,3053

Open in new window


DUP File
"Last Name","First Name","Job Title","Clock Number"
"D","T","Senior Specialist","1474"
"C","J","Senior Payment Specialist","1559"
"Maradona","Diego","Napoli","2208"
"F","M","Decision Support Manager","1664"
"G","M","Applications Support Manager","1737"

Open in new window


So, the DUP file must contain "Maradona","Diego","Napoli","2208" and B,K,HR Manager,2208
The fact that the employeeNumber 2208 in AD for B,K,HR matches the "Clock Number" 2208 for  "Maradona","Diego","Napoli","2208", it will not let me create the AD user (expected) for Maradona and will output the report.
0
 
SubsunCommented:
Ok for testing you just run the following code against the above input csv.. and see the result..
$DupClock = @()
Import-Csv C:\test.csv | ForEach-Object {
  $CsvLine = $_
  $ClockNumber = $_."Clock Number"
	$ADU = Get-ADUser -SearchBase "OU=COMPANY,DC=domain,DC=com" -Filter 'employeeNumber -eq $ClockNumber' -Properties *
	If ($ADU) {
	$DupClock += $CsvLine | Select "Last Name","First Name","Job Title","Clock Number",@{N="Type";E={"CSV User"}}
	$DupClock += $ADU | Select @{N="Last Name";E={$_.Surname}},@{N="First Name";E={$_.GivenName}},@{N="Job Title";E={$_.Title}},@{N="Clock Number";E={$_.EmployeeNumber}},@{N="Type";E={"AD User"}}
	}
}
$DupClock | select * | Export-Csv C:\dupclock.csv -NoTypeInformation

Open in new window

0
 
namergSystems AdministratorAuthor Commented:
Ok, i am on my way home. I will test it once i am at home. Thanks for all your help.
0
 
namergSystems AdministratorAuthor Commented:
Almost, getting in there. 2208 are the right ones.

I got the following result:
"Last Name","First Name","Job Title","Clock Number","Type"
"D","T","Senior Specialist","1474","CSV User"
"D","T","Senior Specialist","1474","AD User"
"C","J","Senior Payment Specialist","1559","CSV User"
"C","J","Senior Payment Specialist","1559","AD User"

Open in new window

"Maradona","Diego","Napoli","2208","CSV User"
"B","K","HR Manager","2208","AD User"
"F","M","Decision Support Manager","1664","CSV User"
"F","M","Decision Support Manager","1664","AD User"
"G","M","Applications Support Manager","1737","CSV User"
"G","M","Applications Support Manager","1737","AD User"

Open in new window

0
 
SubsunCommented:
"AD User" are picking from AD query.. that means they exist in AD..
0
 
namergSystems AdministratorAuthor Commented:
Yes, they do exist in AD except "Maradona","Diego","Napoli","2208","CSV User"
Maybe, I am not explaining well what I am trying to accomplish ?
0
 
SubsunCommented:
The code check CSV file for "Clock Number" and check the same exist in AD or not, If yes it will log the details to log file.. Is that what you want?

As per the result 1474,1559,2208,1664 & 1737 exist in AD and so you don't want to add those accounts with  "Clock Number" to AD.. Please correct me if I am wrong...
0
 
namergSystems AdministratorAuthor Commented:
The first stage of the whole code is, that will read a master file, which is the CSV.
This file always is going to have the current employees and new employees to be added into AD.
Let's call employees are AD Users.. So, the file will always contain the existing AD Users and new employees to be converted AD Users, this part is the whole AD user creation.(I have this part) The primary key of everything in my scenario is the "Clock Number" that comes from the Master/CSV file and employeeNumber in AD in a certain OU.

Examples/Scenarios of what we are working on this thread
Scenario1:
CSV file has the following records:
Maradona,Diego,Napoli,2208
B,K,HR Manager,2209
.
.
n record

Open in new window

The code will check the first record from the CSV file and compared the existence of that first record against AD User certain OU. Code will say "It looks I do not have no AD user with clock number ####, so go ahead and create AD user. Continue for the other records in CSV file and so on
Scenario2:
CSV file has the following records:
Maradona,Diego,Napoli,2208
B,K,HR Manager,2209
My,Self,Powershell Dummy,2211
Subsun,Powershell Guru,EE,2210
.
.
n record

Open in new window

AD in a certain OU contains:
Maradona,Diego,Napoli,2208
B,K,HR Manager,2209
Subsun,Powershell Guru,EE,2210.
Messi,Lionel,Argentina,2211
.
.
n AD User

Open in new window

The code will check the first record from the CSV file and compared the existence of that first record against AD, certain OU. Code will say "It looks I do not have no AD user with clock number ####, so go ahead and create AD user and so on for the other records in CSV file. But, on this scenario when the pointer is on My,Self,Powershell Dummy,2211 and doing the comparison against AD, is going to find Messi,Lionel,Argentina,2211, so code will scream "CAN NOT CREATE My,Self,Powershell Dummy,2211 because there is already a user in AD with clock number 2211--> Messi,Lionel,Argentina,2211 and code will continue with the CSV records comparing against AD User certain OU clock number

Do you understand me ?
0
 
SubsunCommented:
So to compare whether it is the same user in csv we can add the filter for First name and last name.. Try this and see if it works as expected..
$DupClock = @()
Import-Csv C:\test.csv | ForEach-Object {
 $CsvLine = $_
 $LastName = $_."Last Name" -replace "\s"
 $FirstName = $_."First Name"
  $ClockNumber = $_."Clock Number"
	$ADU = Get-ADUser -SearchBase "OU=COMPANY,DC=domain,DC=com" -Filter 'employeeNumber -eq $ClockNumber' -Properties * | ? {$_.GivenName -ne $FirstName -and $_.Surname -ne $LastName}
	If ($ADU) {
	$DupClock += $CsvLine | Select "Last Name","First Name","Job Title","Clock Number",@{N="Type";E={"CSV User"}}
	$DupClock += $ADU | Select @{N="Last Name";E={$_.Surname}},@{N="First Name";E={$_.GivenName}},@{N="Job Title";E={$_.Title}},@{N="Clock Number";E={$_.EmployeeNumber}},@{N="Type";E={"AD User"}}
	}
}
$DupClock | select * | Export-Csv C:\dupclock.csv -NoTypeInformation

Open in new window

0
 
namergSystems AdministratorAuthor Commented:
OMG, YOU GOT IT. I did test it with the testcode and test file. All good.
I will bullet prof test it tomorrow with the rest of the code. Hope does not break. I do not think will break.
The output was:
"Last Name","First Name","Job Title","Clock Number","Type"
"Maradona","Diego","Napoli","2208","CSV User"
"B","K","HR Manager","2208","AD User"

Open in new window

0
 
SubsunCommented:
Good.. I didn't know you have existing users in the csv, that created the confision.. :-)
0
 
namergSystems AdministratorAuthor Commented:
I am just laughing now...namaste. T2y 2morrow
0
 
namergSystems AdministratorAuthor Commented:
It is working like a charm. One last thing, I created a funtion for it, but instead of creating two logs one for the COMPANY ou and the other one for COMPANY - New Users OU, how do i append the CSV file ? I think i have to modify the lines of the IF, but do not want to break it :(

This is what I have:
$DupClockNumberLog = "C:\scripts\ceridian\06-07-2013_Ceridian_Dup_ClockNumber_LOG.csv"
Function checkdupclock
{
	$DupClock = @()
	Import-Csv "C:\scripts\ceridian\05-22-2013_CeridianExport.csv" | ForEach-Object {
 	$CsvLine = $_
 	$LastName = $_."Last Name" -replace "\s"
 	$FirstName = $_."First Name"
  	$ClockNumber = $_."Clock Number"
  	$ADU = Get-ADUser -SearchBase "OU=COMPANY,DC=domain,DC=com" -Filter 'employeeNumber -eq $ClockNumber' -Properties * | ? {$_.GivenName -ne $FirstName -and $_.Surname -ne $LastName}
  	If ($ADU) {
		$DupClock += $CsvLine | Select "Last Name","First Name","Job Title","Clock Number",@{N="Type";E={"New Employee - Ceridian"}}
		$DupClock += $ADU | Select @{N="Last Name";E={$_.Surname}},@{N="First Name";E={$_.GivenName}},@{N="Job Title";E={$_.Title}},@{N="Clock Number";E={$_.EmployeeNumber}},@{N="Type";E={"AD User - COMPANY OU"}}
	}
   }
   $DupClock | select * | Export-Csv $DupClockNumberLog -NoTypeInformation
   #COMPANY - New Users OU
   $DupClock = @()
   $ADU = @()
   Import-Csv "C:\scripts\ceridian\05-22-2013_CeridianExport.csv" | ForEach-Object {
   $CsvLine = $_
   $LastName = $_."Last Name" -replace "\s"
   $FirstName = $_."First Name"
   $ClockNumber = $_."Clock Number"
   $ADU = Get-ADUser -SearchBase "OU=COMPANY - New Users,DC=domain,DC=com" -Filter 'employeeNumber -eq $ClockNumber' -Properties * | ? {$_.GivenName -ne $FirstName -and $_.Surname -ne $LastName}
   If ($ADU) {
		$DupClock += $CsvLine | Select "Last Name","First Name","Job Title","Clock Number",@{N="Type";E={"New Employee - Ceridian"}}
		$DupClock += $ADU | Select @{N="Last Name";E={$_.Surname}},@{N="First Name";E={$_.GivenName}},@{N="Job Title";E={$_.Title}},@{N="Clock Number";E={$_.EmployeeNumber}},@{N="Type";E={"AD User @ COMPANY - New Users OU"}}
	}
   }
   $DupClock | select * | Export-Csv $DupClockNumberLog -NoTypeInformation
}

Open in new window

0
 
namergSystems AdministratorAuthor Commented:
I am all set. You Rock Subsun. thanks for your help.
I came up with the following:
$DupClock = @()
	Import-Csv "C:\scripts\ceridian\05-22-2013_CeridianExport.csv" | ForEach-Object {
 	$CsvLine = $_
 	$LastName = $_."Last Name" -replace "\s"
 	$FirstName = $_."First Name"
  	$ClockNumber = $_."Clock Number"
  	$ADU = Get-ADUser -SearchBase "OU=COMPANY,DC=domain,DC=com" -Filter 'employeeNumber -eq $ClockNumber' -Properties * | ? {$_.GivenName -ne $FirstName -and $_.Surname -ne $LastName}
  	$ADN = Get-ADUser -SearchBase "OU=COMPANY - New Users,DC=domain,DC=com" -Filter 'employeeNumber -eq $ClockNumber' -Properties * | ? {$_.GivenName -ne $FirstName -and $_.Surname -ne $LastName}
  	If ($ADU) {
		$DupClock += $CsvLine | Select "Last Name","First Name","Job Title","Clock Number",@{N="Type";E={"New Employee - Ceridian"}}
		$DupClock += $ADU | Select @{N="Last Name";E={$_.Surname}},@{N="First Name";E={$_.GivenName}},@{N="Job Title";E={$_.Title}},@{N="Clock Number";E={$_.EmployeeNumber}},@{N="Type";E={"AD User in COMPANY OU"}}
	}
   }
   If ($ADN) {
		$DupClock += $CsvLine | Select "Last Name","First Name","Job Title","Clock Number",@{N="Type";E={"New Employee - Ceridian"}}
		$DupClock += $ADN | Select @{N="Last Name";E={$_.Surname}},@{N="First Name";E={$_.GivenName}},@{N="Job Title";E={$_.Title}},@{N="Clock Number";E={$_.EmployeeNumber}},@{N="Type";E={"AD User in COMPANY - New User OU"}}
	}
   $DupClock | select * | Export-Csv $DupClockNumberLog -NoTypeInformation

Open in new window

0
 
SubsunCommented:
Hmm... Why searching the ad user two times? ($ADU and $ADN) also If ($ADN) condition is placed outside the foreach loop. is it intentional?
0
 
namergSystems AdministratorAuthor Commented:
hmm, in order to add the AD user from COMPANY OU AND COMPANY - New Users OU into the same file.  ?
0
 
SubsunCommented:
That can be done in single search, make the SearchBase DC=domain,DC=com and you can find the OU name using the DistinguishedName attribute.. Also with current script you need to keep the condition for $ADN inside the foreach loop...
0

Featured Post

Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

  • 22
  • 16
Tackle projects and never again get stuck behind a technical roadblock.
Join Now