Powershell – Import CSV, add data and re-export

Tags:
Microsoft
Powershell
Scripting
Hello all, I'm curious if I have any fellow scripters here.  I have a csv populated with user id's, most of which appear more than once.  I need to extract that data, add data too it and recompose.  My issue is that I do not want to run work on a duplicate entry.  For example, the userid in A1 is the same as B1, C1, and D1.  I want to take that value from A1, run a task against it to populate a2,a3,a4 and continue down B1,C1,D1,.... until I find the next UNIQUE value.  This is a little tricky to explain so hopefully my code will be more apparent...
$csv= "\Servername.fq.dnjunk.csv" 
$users=@(import-csv $csv | select-object -Property UserID -Unique)


Import-CSV $csv | select 'Computer','UserID',`
@{ n = 'FirstName'; e = { ((Get-Qaduser $_.UserID).FirstName) } },`
@{ n = 'LastName'; e = { ((Get-Qaduser $_.UserID).LastName) } },`
@{ n = 'Email'; e = { ((Get-Qaduser $_.UserID).Email) } },`
@{ n = 'Cost Center'; e = { ((Get-Qaduser $_.UserID).physicalDeliveryOfficeName) } },`
'Date',`
'DeviceID',`
'ProviderName',`
'DriveType' | Export-CSV -Path "C:foldernamemaster_final.csv" -Append -NoTypeInformation
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: