10

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

1

2 Answers 2

25

Use Set-Content instead of Add-Content.

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

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

Sign up to request clarification or add additional context in comments.

Comments

9

You can do an Out-File as well

'Some content' | Out-File -FilePath c:\windows\temp\file.log

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.