DaveJames
DaveJames

Reputation: 37

Overwrite and Append Csv output in PowerShell

I have a few custom objects which I am exporting all to the same csv so I use the -Append switch, however, I want it to overwrite the existing file with the same name, how can I do this?

(Get-Content filelocation) | set-content filelocation
Filelocation

At the end of my custom objects I use this code

$CSV | Export-Csv filelocation -NoTypeInformation -Append

Currently doing this exports it all to the same CSV every time I run the script, making it so I have to delete the Csv before running the script again.

How can I sort this?

Upvotes: 0

Views: 6116

Answers (1)

Isaac
Isaac

Reputation: 804

Using the -Force flag after you specify the FileLocation will make it overwrite.

Upvotes: 1

Related Questions