regex - Replace a whole line in a INI-file using Powershell -


i have problem replacing whole line in ini-file, seems add result thesame line.

here ini-file:

    [environment] app_user=domain\user1 

i wish replace app_user=domain\user1 example app_user=domain\user2.

here code:

$user = [system.security.principal.windowsidentity]::getcurrent().name           (get-content d:\test\test.ini) | foreach-object { $_ -replace "app_user=" , "app_user=$user" } | set-content d:\test\test.ini 

i result when use above code:

    [environment] app_user=domain\user2domain\user1 

help appreciated.

//regard pms

to match whole line:

-replace "app_user=.+","app_user=$user" 

the .+ match rest of line.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -