• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Powershell: Process CSV to remove not-needed fields

Scarpozzi

Lifer
I'm trying to teach myself powershell and have never used it for anything.

I have a large CSV file called people.txt that contains USERNAME,FIRST,MIDDLE,LAST,SUFFIX,IDNUMBER,ZIPCODE


I've been looking at Import-Csv, but don't know how to exclude or append data. Basically, what I want to do is use the information in this file to generate another file that contains the following:

USERNAME@company.com FIRST LAST

and repeats to the end of the file. (yeah...this is to generate a company email list)

I'm wanting to do this in powershell to get my feet wet because I'll be rewriting a lot of other scripts soon enough and have never taken a class on it. (if you have any good books, please give me suggestions)

Thanks,
 
I think I got it

$p = Import-Csv c:\Automation\people.txt |foreach {
& "C:\windows\system32\xcopy.exe " + $_.USERNAME + " " $_.FIRST + " " + $_.LAST
(""+ $_.USERNAME + "@company.com " + $_.FIRST + " " + $_.LAST)
}
$p | Out-File -FilePath c:\Automation\output.txt

Example output is:
username@company.com firstname lastname
username@company.com firstname lastname
username@company.com firstname lastname
username@company.com firstname lastname

I'm glad you found an answer, but I'm not sure why the xcopy was in there in the first place?

I would have just created a new array of objects with the info you wanted then used export-csv to write them to a new file.
 
Back
Top