2015-03-02 113 views
0

我有一個用於設置環境變量的文本文件。我需要更改'config'變量的值。下面是該文件內容使用powershell腳本替換單詞

env.mode:上
配置:ENV
服務器:2
分貝:MSSQL
.........
...... ...

env的值可以是任何值。它應該被替換爲prod。 (config:prod)。我知道我們可以使用powershell get-content替換這個詞。由於單詞不是靜態的,因此需要使用Powershell來設置該值。有人能幫我嗎?

回答

0

試試這個:

$file = 'c:\myconfig.config' 
$configValue = 'prod' 
(Get-Content $file) -replace '^config:.*', "config: $configValue" | Set-Content $file 
+0

它works..thanks很多:) – Ela 2015-03-06 04:17:33