Adding & Verifying existing AD Users in OU and create a CSV file
hello working on following:
if user or users master file exists in company ou , not exist in new - users ou, not need create ad user , creates existingcompanyusersreport
if user or users master file not exist in company ou , not exist in new user ou, need create ad user , creates new-users report.
have code creates report , create ad users.
i import csv through following line , pipe loop , query ad
import-csv $masterfile | foreach-object {
$lastname = $_."last name" -replace "\s" $sam = $lastname.tolower() + $_."first name".substring(0,1).tolower() $clocknumber = $_."clock number" $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" if (!($existscompany) -and !($existsnewusers)) { #create new ad user , create new users report } elseif (!($existscompany)) { #create existing company users report }
if have scenario existscompany has user belongs master file , company ou, second if ignored , should not be, opposite of !($existscompany) ?
thoughts / help.
opposite of !($existscompany) or -not($existscompany)
would without ! or -not ($existscompany) means if variable contains data continue
Windows Server > Windows PowerShell
Comments
Post a Comment