Cant Edit this INI file.

This topic contains 5 replies, has 4 voices, and was last updated by Profile photo of Jonnie H@CK Jonnie H@CK 2 years, 1 month ago.

  • Author
    Posts
  • #19985
    Profile photo of Jonnie H@CK
    Jonnie H@CK
    Participant

    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..

  • #19987
    Profile photo of Ondrej Zilinec
    Ondrej Zilinec
    Participant

    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?

  • #19988
    Profile photo of Jonnie H@CK
    Jonnie H@CK
    Participant

    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...

  • #19990
    Profile photo of fair64
    fair64
    Participant

    Shouldn't it be{$_ -Replace "MYOPTION", "MYNEWOPTION"} instead of {S_ -Replace "MYOPTION", "MYNEWOPTION"}

  • #19992
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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")
    
  • #19994
    Profile photo of Jonnie H@CK
    Jonnie H@CK
    Participant

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

    This one is solved, thank you!

You must be logged in to reply to this topic.