I have a script that imports a CSV, compares the list to AD and creates usernames and passwords. The scripts starts out like this:
$CSV = Import-CSV C:\Scripts\Add_AD_Users.csv
$CSV | ForEach-Object{
if(user does exist){
# skip it
}
elseif(user doesn't exist){
# create user and export password, email, and username to csv.
}
In the elseif
statement I would like to get the current ForEach-object
"object" and export that to a CSV. Is that possible? The CSV contains 3 headers that I want to take $_.SamAccountName $_.EmailAddress $_.Password
.
Is there a way to do this, so that I only have the newly created users? This can't be done with a -PassThru
on Get-Aduser
.