Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to overwrite file content with power shell

I am new to powershell. how do you over write file in powershell? write now below code is appending. I want to completely over write file with below new info.

$someinfo | Add-Content $FileName

like image 774
NoStressDeveloper Avatar asked Jan 12 '18 00:01

NoStressDeveloper


2 Answers

Use Set-Content instead of Add-Content.

Difference between Set-Content and Add-Content:
Add-Content=> Append
Set-Content=> replace content

Reference:
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-content?view=powershell-5.1

like image 54
Shiko Avatar answered Sep 20 '22 01:09

Shiko


You can do an Out-File as well

'Some content' | Out-File -FilePath c:\windows\temp\file.log
like image 34
Prasoon Karunan V Avatar answered Sep 18 '22 01:09

Prasoon Karunan V