Append to an existing CSV


I am attempting to import a CSV file that includes columns of AD information (DisplayName, Title, Department, Manager), run a query against the DisplayName to grab the samaccountname, and then export the original data with a new filled in samaccountname column into a new CSV file.
I have been working through various scripts found online, but am stuck.

Any help would be appreciated.

$Sam = @() $names = Import-csv "C:scriptsAD Properties CleanupAD-UserList.csv" foreach ($name in $names.displayname) { $sam += get-aduser -filter {name -like $name} -properties samaccountname | Add-Member -MemberType NoteProperty -Name sAMAccountName - Value $sam -PassThru } $Sam | Export-CSV "C:scriptsAD Properties CleanupAD-UserList-2.csv" 

Add-Member : Cannot add a member with the name “sAMAccountName” because a member with that name already exists. To overwrite the member anyway, add the Force parameter to your command. At line:6 char:77 + $sam += get-aduser -filter {name -like $name} -properties samaccountname | Add- … + ~~~~ + CategoryInfo : InvalidOperation: (CN=Zoch, Jacob…C=domain,DC=org:PSObject) [Add-Member], InvalidOperationException + FullyQualifiedErrorId : MemberAlreadyExists,Microsoft.PowerShell.Commands.AddMemberCommand

submitted by /u/LBEB80
[link] [comments]

Leave a Reply