简体   繁体   中英

Modify the contents of a file in powershell

I have a situation where I need to modify the contents of a file using PowerShell. The string already there will be similar to ToolsVersion="3.5" . However I can not be positive that "3.5" will always be what is inside the quotes. I need to change the value inside the quotes to "12.0" . Is there a way to find the "ToolsVersion=" in the file, then modify the value inside the quotes that follows it?

您可以使用Get-Content-replaceOut-File

(Get-Content C:\path\to\file.txt) -replace 'ToolsVersion=".*?"', 'ToolsVersion="12.0"' | Out-File C:\path\to\file.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM