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
Post a Comment