May 20, 2011 at 1:55 pm
Is there anyway to append the csv file instead of overwriting its contents?
May 20, 2011 at 2:35 pm
If you mean keep appending output to a CSV file, the export-csv cmdlet doesn't directly support this, however you could use the convertto-csv cmdlt and remove the header row as follows:
get-psdrive | export-csv ./psdrives.csv -NoTypeInformation
get-psdrive | ConvertTo-Csv -NoTypeInformation |
foreach {$start=$true} {if ($start) {$start=$false} else {$_}} |
Out-File .\psdrives.csv -Append -Encoding ASCII
The code snippet above is based on a more complete solution described by Dmitry Sotnikov:
May 21, 2011 at 7:16 am
thanks for the reply. I'll take a look at that broader solution for that snippet. I actually got it working by saving my outgoing data into a variable, importing the contents of the csv file into another variable and appending the two together. My powershell scripting is quite novice so if you see any issues with this let me know 🙂
Here is the code I used:
$Temp = Get-SqlData $srcServer 'master' $qry
$Last = import-csv "C:\filename.csv"
$out = $Temp + $Last | export-csv -noTypeInformation -path "C:\filename.csv"
April 17, 2013 at 12:20 am
@SSC Veteran : Thanks . Its working now by using the above commands
April 17, 2013 at 4:51 pm
jcrawf02 (12/16/2008)
corey lawson (12/15/2008)
That's a good article, except for a couple of things.Why do people still literally use commas as field separators (unless they have to, because the tool/function/utility doesn't support anything else)? Gaaaahhh! The example even uses the field separator parameter...
And, well, it's PowerShell. I'd rather do this stuff in INTERCAL, but to each their own...
Of course, BCP does this stuff as well...
In search of enlightenment, what should we be using as field separators?
How about it, Corey? What do you people should be using?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 16 through 19 (of 19 total)
You must be logged in to reply to this topic. Login to reply