Hello everyone,<\/p>\n
I’m stuck on the last part of my powershell script, exporting a variable to a csv column. I have the following example:<\/p>\n
$file1 = examplecsv1.csv\n$file2 = examplecsv2.csv\n\nforeach ($line in $file1) {\n foreach ($row in $file2) {\n if ($line.col1 -eq $row.col1){\n #this is the part im having issues with:\n $row.col2 | Add-Content examplecsv3.csv #how to export to col3 of examplecsv.csv?\n }\n }\n}\n<\/code><\/pre>\n
Advertisement
I just want to export $row.col2 to a specific column in the examplecsv3.csv<\/p>","upvoteCount":7,"answerCount":8,"datePublished":"2020-02-06T10:24:49.000Z","author":{"@type":"Person","name":"matthewlight0943","url":"https://community.spiceworks.com/u/matthewlight0943"},"acceptedAnswer":{"@type":"Answer","text":"
Instead of:<\/p>\n
$row.col2 | Add-Content examplecsv3.csv #how to export to col3 of examplecsv.csv?\n<\/code><\/pre>\ntry<\/p>\n
$row.col2= $line.col3\n<\/code><\/pre>\nof course, you must save the array to a CSV.<\/p>","upvoteCount":1,"datePublished":"2020-02-06T10:28:49.000Z","url":"https://community.spiceworks.com/t/powershell-export-variable-to-csv-column/750082/3","author":{"@type":"Person","name":"DoctorDNS","url":"https://community.spiceworks.com/u/DoctorDNS"}},"suggestedAnswer":[{"@type":"Answer","text":"
Hello everyone,<\/p>\n
I’m stuck on the last part of my powershell script, exporting a variable to a csv column. I have the following example:<\/p>\n
$file1 = examplecsv1.csv\n$file2 = examplecsv2.csv\n\nforeach ($line in $file1) {\n foreach ($row in $file2) {\n if ($line.col1 -eq $row.col1){\n #this is the part im having issues with:\n $row.col2 | Add-Content examplecsv3.csv #how to export to col3 of examplecsv.csv?\n }\n }\n}\n<\/code><\/pre>\nI just want to export $row.col2 to a specific column in the examplecsv3.csv<\/p>","upvoteCount":7,"datePublished":"2020-02-06T10:24:49.000Z","url":"https://community.spiceworks.com/t/powershell-export-variable-to-csv-column/750082/1","author":{"@type":"Person","name":"matthewlight0943","url":"https://community.spiceworks.com/u/matthewlight0943"}},{"@type":"Answer","text":"
Hey … I believe you need to use get-content<\/p>\n
$file1 = Get-Content './examplecsv1.csv'\n$file2 = Get-Content './examplecsv2.csv'\n<\/code><\/pre>\nRegards<\/p>","upvoteCount":0,"datePublished":"2020-02-06T10:28:00.000Z","url":"https://community.spiceworks.com/t/powershell-export-variable-to-csv-column/750082/2","author":{"@type":"Person","name":"spiceuser-28ht3","url":"https://community.spiceworks.com/u/spiceuser-28ht3"}},{"@type":"Answer","text":"
Thank you for your reply!<\/p>\n
how would i save the array and where should i put the save array command? within the foreach loop with -append?<\/p>","upvoteCount":0,"datePublished":"2020-02-06T10:36:55.000Z","url":"https://community.spiceworks.com/t/powershell-export-variable-to-csv-column/750082/4","author":{"@type":"Person","name":"matthewlight0943","url":"https://community.spiceworks.com/u/matthewlight0943"}},{"@type":"Answer","text":"
Export-csv
\nYes, append can work<\/p>\n