INI file editing, Save format

0

So i have a working code. i just learned about this today but am wondering if there is a way to save the formatting. (found it on here btw).

$ini = Get-IniContent c:\temp\ini.ini 
$ini["posscreen"]["BitmapFile"] = "C:\Temp\FileC.bmp"  
$ini | Out-IniFile -FilePath c:\temp\ini2.ini

This is how it looks normally:

 [ShapePageFnt]
 Position=1.73 -2.76 -15.00
 Scale=0.35 0.36 0.38
 ZoneDepth=0
 StringLength=9600
 Font=VerdanaBold
 Color=0xFF000000
 Kerning=0.270000
 String=1/10
 StringAlignment=Left 

 [sgcArialBlack]
 FontFile=ArialBlack.png
 DataFile=ArialBlack.ftd
 StringLength=0
 StringStack=0
 StringAlignment=Center
 Kerning=0.25
 Color=0xFF00AAFF
 Position=0 0 -1000
 Dimension=1 1
 Scale=1 1 1
 String=

 [sgcXtraLabel]
 Position=-3.25 -5.61 -15.00
 Dimension=1.00 1.00
 Scale=0.33 0.33 0.33
 ZoneDepth=-101
 StringLength=20
 Font=VerdanaBold
 Color=0xFFFFFFFF
 String=Xtra Games
 StringAlignment=Center

After running the code:

[ShapePageFnt]
Position=1.73 -2.76 -15.00
Scale=0.35 0.36 0.38
ZoneDepth=0
StringLength=9600
Font=VerdanaBold
Color=0xFF000000
Kerning=0.270000
String=1/10
StringAlignment=Left 
[sgcArialBlack]
FontFile=ArialBlack.png
DataFile=ArialBlack.ftd
StringLength=0
StringStack=0
StringAlignment=Center
Kerning=0.25
Color=0xFF00AAFF
Position=0 0 -1000
Dimension=1 1
Scale=1 1 1
String=
[sgcXtraLabel]
Position=-3.25 -5.61 -15.00
Dimension=1.00 1.00
Scale=0.33 0.33 0.33
ZoneDepth=-101
StringLength=20
Font=VerdanaBold
Color=0xFFFFFFFF
String=Xtra Games
StringAlignment=Center

Any help would be appreciated.

** i tried -format and -table just for kicks and didn't do anything but pop up errors.** Is there a /? for stuff in power shell to check if these conditions are even available?

End goal: to have the code ran and have it output the same way it inputs with the spaces. (the code replaces a set item in the .ini)

powershell
format
ini
editing
asked on Stack Overflow Oct 19, 2019 by david weaver • edited Oct 19, 2019 by david weaver

2 Answers

1

I downloaded the script and had a look at the parameters for the Out-IniFile function. I found two switch parameters there:

  • Pretty which adds an extra linebreak between Sections
  • Loose which adds spaces around the equal sign when writing the key = value

To use them, your command to write the ini file would be:

$ini | Out-IniFile -FilePath c:\temp\ini2.ini -Pretty -Loose

The author of that script forgot to add descriptions of the parameters in the comment-based help info, so that's why Get-Help didn't show it..

answered on Stack Overflow Oct 20, 2019 by Theo • edited Oct 20, 2019 by Theo
0

I am unable to comment on the other answer, as I don't have enough reputation points.

@Theo answer is correct; with the exception that the 2 parameters are indeed documented: https://github.com/lipkau/PsIni/blob/master/PSIni/Functions/Out-IniFile.ps1#L98-L106

I ♥ PS> help Out-IniFile -Parameter pretty, loose

-Pretty [<SwitchParameter>]
    Writes the file as "pretty" as possible

    Adds an extra linebreak between Sections

    Required?                    false
    Position?                    named
    Default value                False
    Accept pipeline input?       false
    Accept wildcard characters?  false


-Loose [<SwitchParameter>]
    Adds spaces around the equal sign when writing the key = value

    Required?                    false
    Position?                    named
    Default value                False
    Accept pipeline input?       false
    Accept wildcard characters?  false

Also, the git repository of that module is https://github.com/lipkau/PsIni. You can create issues there for missing functionality or general questions

answered on Stack Overflow Oct 22, 2019 by lipkau

User contributions licensed under CC BY-SA 3.0