\n Hi, and welcome to the PowerShell forum! \n\n\nDon’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask! \n\n\nUse a descriptive subject. Don’t say “Need help” or “PowerShell Help”, actually summarize what the problem is. It helps the rest of us keep track of which problem is which. \n\n\nDon’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy…\n <\/blockquote>\n<\/aside>\n","upvoteCount":1,"datePublished":"2023-02-14T17:07:49.000Z","url":"https://community.spiceworks.com/t/scripting-ideas/946258/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"I tried the Import-csv and was kinda successful.<\/p>\n
As an example:<\/p>\n
File1 has the following headers: 1st_name,lst_name<\/p>\n
File 2 has the following headers: FN,LN<\/p>\n
All I need is for File 2 to have the same headers as File 1 and not worry about the columns information<\/p>\n
Import-Csv -Path File1 | select header names | Export-Csv -Append -Path File2 -Force\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2023-02-14T17:24:14.000Z","url":"https://community.spiceworks.com/t/scripting-ideas/946258/3","author":{"@type":"Person","name":"spiceuser-31qkz","url":"https://community.spiceworks.com/u/spiceuser-31qkz"}},{"@type":"Answer","text":"Another option that might work, depending on how you are looking to work with the content, is using PowerQuery. This is built into Excel, and you can point to existing files, and just pull or query the content desired. \nIf your desire is to already be in Excel to make changes, this may be a useful method…<\/p>\n
Hope this helps.<\/p>","upvoteCount":0,"datePublished":"2023-02-14T17:24:16.000Z","url":"https://community.spiceworks.com/t/scripting-ideas/946258/4","author":{"@type":"Person","name":"sbux2k","url":"https://community.spiceworks.com/u/sbux2k"}},{"@type":"Answer","text":"\n\n
<\/div>\n
spiceuser-31qkz:<\/div>\n
\nI tried the Import-csv and was kinda successful.<\/p>\n
As an example:<\/p>\n
File1 has the following headers: 1st_name,lst_name<\/p>\n
File 2 has the following headers: FN,LN<\/p>\n
All I need is for File 2 to have the same headers as File 1 and not worry about the columns information<\/p>\n
Import-Csv -Path File1 | select header names | Export-Csv -Append -Path File2 -Force\n<\/code><\/pre>\n<\/blockquote>\n<\/aside>\nIn that case I’d use ‘get-content’.<\/p>\n
You can not use ‘append’ as append will add it to the end of the file.<\/p>\n
\n\nread file 1<\/p>\n<\/li>\n
\nread file 2<\/p>\n<\/li>\n
\nreplace line 1 (or zero…) in file 2 with the info from file 1<\/p>\n<\/li>\n<\/ol>\n
give it a shot.<\/p>","upvoteCount":0,"datePublished":"2023-02-14T17:30:57.000Z","url":"https://community.spiceworks.com/t/scripting-ideas/946258/5","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Would this work?<\/p>\n
Get-Content File1 |\nSelect-Object - line1 |\nAdd-Content File\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2023-02-14T17:43:05.000Z","url":"https://community.spiceworks.com/t/scripting-ideas/946258/6","author":{"@type":"Person","name":"spiceuser-31qkz","url":"https://community.spiceworks.com/u/spiceuser-31qkz"}},{"@type":"Answer","text":"Meant: Add-Content File2<\/p>","upvoteCount":0,"datePublished":"2023-02-14T17:45:21.000Z","url":"https://community.spiceworks.com/t/scripting-ideas/946258/7","author":{"@type":"Person","name":"spiceuser-31qkz","url":"https://community.spiceworks.com/u/spiceuser-31qkz"}},{"@type":"Answer","text":"\n\n
<\/div>\n
spiceuser-31qkz:<\/div>\n
\nWould this work?<\/p>\n
Get-Content File1 |\nSelect-Object - line1 |\nAdd-Content File\n<\/code><\/pre>\n<\/blockquote>\n<\/aside>\nDid you try it? If not, create two test files and try it…<\/p>","upvoteCount":0,"datePublished":"2023-02-14T17:47:49.000Z","url":"https://community.spiceworks.com/t/scripting-ideas/946258/8","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
This is the error I get:<\/p>\n
Select-Object - line1 | \n| ~~~~~~~~~~~~~~~~~~~~~ \n| A positional parameter cannot be found that accepts argument ‘line1’.<\/p>","upvoteCount":0,"datePublished":"2023-02-14T17:55:36.000Z","url":"https://community.spiceworks.com/t/scripting-ideas/946258/9","author":{"@type":"Person","name":"spiceuser-31qkz","url":"https://community.spiceworks.com/u/spiceuser-31qkz"}},{"@type":"Answer","text":"\n\n
<\/div>\n
spiceuser-31qkz:<\/div>\n
\nThis is the error I get:<\/p>\n
Select-Object - line1 | \n| ~~~~~~~~~~~~~~~~~~~~~ \n| A positional parameter cannot be found that accepts argument ‘line1’.<\/p>\n<\/blockquote>\n<\/aside>\n
there is no ‘line1’ property.<\/p>\n
Select-Object -First 1\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2023-02-14T17:58:20.000Z","url":"https://community.spiceworks.com/t/scripting-ideas/946258/10","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"I’d do something like so…<\/p>\n
$one = Get-Content \"one.csv\"\n$two = Get-Content \"two.csv\"\n$two[0] = $one[0]\n$two | out-file \"two.csv\" -Force\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2023-02-14T17:58:58.000Z","url":"https://community.spiceworks.com/t/scripting-ideas/946258/11","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"I replaced the line1 with -First 1<\/strong> and the script ran successfully but put the headers at the bottom of File2 and did not change line 1 of File2<\/p>","upvoteCount":0,"datePublished":"2023-02-14T18:06:56.000Z","url":"https://community.spiceworks.com/t/scripting-ideas/946258/12","author":{"@type":"Person","name":"spiceuser-31qkz","url":"https://community.spiceworks.com/u/spiceuser-31qkz"}},{"@type":"Answer","text":"\n\n
<\/div>\n
spiceuser-31qkz:<\/div>\n
\nI replaced the line1 with -First 1<\/strong> and the script ran successfully but put the headers at the bottom of File2 and did not change line 1 of File2<\/p>\n<\/blockquote>\n<\/aside>\nRight, add-content appends, which adds to the bottom.<\/p>","upvoteCount":0,"datePublished":"2023-02-14T18:09:54.000Z","url":"https://community.spiceworks.com/t/scripting-ideas/946258/13","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
what’s the trick to replace the top line with the content from File1?<\/p>","upvoteCount":0,"datePublished":"2023-02-14T18:11:26.000Z","url":"https://community.spiceworks.com/t/scripting-ideas/946258/14","author":{"@type":"Person","name":"spiceuser-31qkz","url":"https://community.spiceworks.com/u/spiceuser-31qkz"}},{"@type":"Answer","text":"
If I’m understanding correctly, I think this is what you’re asking for:<\/p>\n
$Header = Get-Content -Path \"Drive:\\Path\\FirstFile.csv\" | Select-Object -First 1\n$Content = Get-Content -Path \"Drive:\\Path\\SecondFile.csv\" | Select-Object -Skip 1\n\n$Header | Set-Content -Path \"Drive:\\Path\\NewFile.csv\"\n$Content | Add-Content -Path \"Drive:\\Path\\NewFile.csv\"\n<\/code><\/pre>\nIt’s a little more terse, but hopefully is easier to understand what and where you need to edit to complete your task<\/p>","upvoteCount":2,"datePublished":"2023-02-14T18:22:56.000Z","url":"https://community.spiceworks.com/t/scripting-ideas/946258/15","author":{"@type":"Person","name":"saidbrandon","url":"https://community.spiceworks.com/u/saidbrandon"}},{"@type":"Answer","text":"\n\n
<\/div>\n
spiceuser-31qkz:<\/div>\n
\nwhat’s the trick to replace the top line with the content from File1?<\/p>\n<\/blockquote>\n<\/aside>\n
$one = Get-Content \"one.csv\"\n$two = Get-Content \"two.csv\"\n$two[0] = $one[0]\n$two | out-file \"two.csv\" -Force\n<\/code><\/pre>\nget-content reads an an array [0] is the first element in the array, so the first line in the file.it’s basically telling it, hey set line 1 from file 1 as line 1 in file 2<\/p>","upvoteCount":1,"datePublished":"2023-02-14T18:25:06.000Z","url":"https://community.spiceworks.com/t/scripting-ideas/946258/16","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
that did the trick. thanks for all the help.<\/p>","upvoteCount":1,"datePublished":"2023-02-14T18:53:05.000Z","url":"https://community.spiceworks.com/t/scripting-ideas/946258/17","author":{"@type":"Person","name":"spiceuser-31qkz","url":"https://community.spiceworks.com/u/spiceuser-31qkz"}}]}}
Neally
(Neally)
February 14, 2023, 5:07pm
2
Sure. What have you tried? where are you stuck?
import-csv to get the CSV / header info (or get-content) whatever you want to do
and you can use ‘out-file’ or export-csv or whatever cmdlet of your choice to export it again.
Details depend what you want it to do in the 2nd CSV file with the header info.
Give it a shot. Feel free to post the code you have tried when you get stuck and we’ll go from there.
If you post code, please use the ‘Insert Code’ button. Please and thank you!
Hi, and welcome to the PowerShell forum!
Don’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask!
Use a descriptive subject. Don’t say “Need help” or “PowerShell Help”, actually summarize what the problem is. It helps the rest of us keep track of which problem is which.
Don’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy…
1 Spice up