Solved

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

Posted on 2013-06-06
38
213 Views
Last Modified: 2013-06-07
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
Comment
Question by:namerg
  • 22
  • 16
38 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 39226378
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
 

Author Comment

by:namerg
ID: 39226412
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
 
LVL 40

Expert Comment

by:Subsun
ID: 39226511
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
 

Author Comment

by:namerg
ID: 39226589
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
 
LVL 40

Expert Comment

by:Subsun
ID: 39226645
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
 

Author Comment

by:namerg
ID: 39226678
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
 

Author Comment

by:namerg
ID: 39226869
still getting errors. I tried both of your suggestions. :(
0
 

Author Comment

by:namerg
ID: 39226927
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
 
LVL 40

Expert Comment

by:Subsun
ID: 39227194
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
 

Author Comment

by:namerg
ID: 39227265
:( 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
 
LVL 40

Expert Comment

by:Subsun
ID: 39227281
What result you get for
Get-ADUser -SearchBase "OU=COMPANY,DC=domain,DC=com" -Filter "(employeeNumber = "2500")"

Open in new window

0
 

Author Comment

by:namerg
ID: 39227294
By the way if I use (=) sign, it breaks I have to use -eq
0
 

Author Comment

by:namerg
ID: 39227316
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
 
LVL 40

Expert Comment

by:Subsun
ID: 39227345
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
 

Author Comment

by:namerg
ID: 39227382
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
 
LVL 40

Expert Comment

by:Subsun
ID: 39227402
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
 

Author Comment

by:namerg
ID: 39227421
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
 
LVL 40

Expert Comment

by:Subsun
ID: 39227447
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
 

Author Comment

by:namerg
ID: 39227483
+-
I got a result but less users now, 5 users.It should be only one.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 40

Expert Comment

by:Subsun
ID: 39227499
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
 

Author Comment

by:namerg
ID: 39227516
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
 

Author Comment

by:namerg
ID: 39227536
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
 
LVL 40

Expert Comment

by:Subsun
ID: 39227600
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
 

Author Comment

by:namerg
ID: 39227610
Ok, i am on my way home. I will test it once i am at home. Thanks for all your help.
0
 

Author Comment

by:namerg
ID: 39227776
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
 
LVL 40

Expert Comment

by:Subsun
ID: 39227781
"AD User" are picking from AD query.. that means they exist in AD..
0
 

Author Comment

by:namerg
ID: 39227808
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
 
LVL 40

Expert Comment

by:Subsun
ID: 39227820
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
 

Author Comment

by:namerg
ID: 39227864
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
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39227915
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
 

Author Comment

by:namerg
ID: 39227966
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
 
LVL 40

Expert Comment

by:Subsun
ID: 39227970
Good.. I didn't know you have existing users in the csv, that created the confision.. :-)
0
 

Author Comment

by:namerg
ID: 39227983
I am just laughing now...namaste. T2y 2morrow
0
 

Author Comment

by:namerg
ID: 39229455
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
 

Author Comment

by:namerg
ID: 39229943
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
 
LVL 40

Expert Comment

by:Subsun
ID: 39230657
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
 

Author Comment

by:namerg
ID: 39230670
hmm, in order to add the AD user from COMPANY OU AND COMPANY - New Users OU into the same file.  ?
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39230685
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now