Author Posts

February 1, 2018 at 11:54 am

First off this is my first post. Very new to powershell
I am attempting to edit a oracle config file

Path \\server name\c$\MW\MW\user_projects\domains\db name\config\fmwconfig\servers\WLS_FORMS\applications\formsapp_11.1.2\config\default.env.

I wish to replace the default line:
FORMS_PATH=C:\MW\MW\Oracle_FRHome1\forms;C:\MW\MW\asinst_1\FormsComponent\forms

with

FORMS_PATH=C:\path
FORMS_NMAP=False
FORMS_TIMEOUT=10
NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252

I have tried the following which fails:

(get-content "C:\path\default.env") | foreach-object {$_ -replace "FORMS_PATH=C:\MW\MW\Oracle_FRHome1\forms;C:\MW\MW\asinst_1\FormsComponent\forms", "FORMS_PATH=C:\path;FORMS_NMAP=False;FORMS_TIMEOUT=10;NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252"} | set-content "C:\path\default.env"

February 1, 2018 at 6:30 pm

Hi. Please let us know what errors you get when posting requests for help otherwise we have to guess at the problem.

My guess is that you're getting an invalid regex error message?

I don't know the structure of the file you're replacing the content in but I've been lazy and not matched the whole string explicitly. I've told it to just replace any string that starts with FORMS and ends with a bunch of other stuff. We can get a bit more specific with the regex if that's going to be a problem (i.e. if more than one line in the file starts with FORMS).

This should do what you need:

(Get-Content E:\temp\env.txt) -replace "^FORMS.*","FORMS_PATH=C:\path`r`nFORMS_NMAP=False`r`nFORMS_TIMEOUT=10`r`nNLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252" | Set-Content E:\temp\env.txt

Note the use of `r`n to insert the carriage returns.