Asked by:
change values in a file using Powershell

Question
-
Hi,
I'm new to Powershell. Currently I want to modify some values in a txt file. I want:
When run the script, it will ask the user to input some specified question and the answers will finally change the values in a txt file in my computer or a network share. Thanks
Wednesday, November 7, 2018 2:55 AM
All replies
-
We do not write scripts on request. Please post your script with a specific question about the script.
Please carefully review the following links to set your expectation for posting in technical forums.
This Forum is for Scripting Questions Rather than script requests
- Script Gallery.
- Forum for Script requests
- Posting guidelines
- Handy tips for posting to this forum
- How to ask questions in a technical forum
- Rubber duck problem solving
- How to write a bad forum post
- Help Vampires: A Spotter's Guide
- This forum is for scripting questions rather than script requests
\_(ツ)_/
Wednesday, November 7, 2018 2:57 AM -
Hi,
Thanks for your question.
I will give you a example about how to change value in a file.
$replace=Read-Host "please enter something to replace white" ((get-content C:\test1\1108.txt -Raw) -replace 'white',$replace)| Set-Content -Path C:\test1\1108.txt
You can use "Get-Content" and "Set-Content" cmdlets to solve your problem.
Refer the link below:
https://mcpmag.com/articles/2018/08/08/replace-text-with-powershell.aspx
Best Regards,
Just do it.
- Proposed as answer by LeeSeenLiMicrosoft contingent staff Tuesday, November 27, 2018 2:20 AM
Thursday, November 8, 2018 5:58 AM -
Maybe a csv will be good for the text file.
Thursday, November 8, 2018 3:56 PM -
Hi,
Was your issue resolved?
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Best Regards,
Lee
Just do it.
Tuesday, November 27, 2018 2:20 AM -
Hi,
Was your issue resolved?
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Best Regards,
Lee
Just do it.
Tuesday, December 4, 2018 2:38 AM