Cant Edit this INI file.

Hi There.

Probably a basic task for the Gurus but I cant seem to figure this out.

I have a SQL Configuration file. It begins with:

;SQL Server 2012 Configuration File
[OPTIONS]

And underneath [OPTIONS] there are settings.

I need to change one of these settings but it seems when I use my usual method of

Get-Content = .\ConfigurationFile.ini | ForEach {S_ -Replace "MYOPTION", "MYNEWOPTION"} | Set-Content=.\NewConfigurationFile.ini

… doesn’t work… the Get-Content doesn’t see anything under the ‘[OPTIONS]’ section.

Did a bit of googling (pretty pressed for time on this) and tried

Get-Content = .\ConfigurationFile[“OPTIONS”] - Didn’t work… (i did other silly things I’m not going to post, but have failed.

A point in the right direction would be appreciated please…

I had a.ini file:

; Microsoft SQL Server Configuration file
[OPTIONS]
; Specifies a Setup work flow, like INSTALL, UNINSTALL, or UPGRADE. This is a required parameter. 
ACTION="Install"
; Specifies features to install, uninstall, or upgrade. The list of top-level features include SQL, AS, RS, IS, and Tools. The SQL feature will install the database engine, replication, and full-text. The Tools feature will install Management Tools, Books online, SQL Server Data Tools, and other shared components. 

FEATURES=SQL,Tools

and I ran:

Get-Content .\a.ini | foreach { $_ -replace "Install", "Remove" } | Set-Content b.ini

and in b.ini I have:

; Microsoft SQL Server Configuration file
[OPTIONS]
; Specifies a Setup work flow, like Remove, UNRemove, or UPGRADE. This is a required parameter. 
ACTION="Remove"
; Specifies features to Remove, unRemove, or upgrade. The list of top-level features include SQL, AS, RS, IS, and Tools. The SQL feature will Remove the database engine, replication, and full-text. The To
ols feature will Remove Management Tools, Books online, SQL Server Data Tools, and other shared components. 

FEATURES=SQL,Tools

Can you, please, give us exact powershell script and exact ini files?

My script is above. I’m not doing anything different.
INI File Attached.

I’m trying to change “SERVER\Administrator” to something else.

Feel free…

Shouldn’t it be{$_ -Replace “MYOPTION”, “MYNEWOPTION”} instead of {S_ -Replace “MYOPTION”, “MYNEWOPTION”}

I suspect that your problem is that the -replace operator takes a regular expression, and the backslash is a special character which needs to be escaped. Try this:

$_ -replace "SERVER\\Administrator", "Something\Else"

Note that you do not need to escape the backslash on the right side of the comma, only in the pattern on the left. Alternatively, you can use the string.Replace() method, which does not use regex:

$_.Replace("SERVER\Administrator", "Something\Else")

Dave, thank you! you are correct. the Double \ worked.

This one is solved, thank you!