< Back

Split-CIni

Sun Jan 12, 2020 11:17 pm

NAME Split-CIni



SYNOPSIS

Reads an INI file and returns its contents.





SYNTAX

Split-CIni -Path <String> [-AsHashtable] [-CaseSensitive] [-WhatIf] [-Confirm] [<CommonParameters>]





DESCRIPTION

A configuration file consists of sections, led by a "[section]" header and followed by "name = value" entries:



[spam]

eggs=ham

green=

eggs



[stars]

sneetches = belly



By default, the INI file will be returned as `Carbon.Ini.IniNode` objects for each name/value pair. For example,

given the INI file above, the following will be returned:



Line FullName Section Name Value

---- -------- ------- ---- -----

2 spam.eggs spam eggs ham

3 spam.green spam green eggs

7 stars.sneetches stars sneetches belly



It is sometimes useful to get a hashtable back of the name/values. The `AsHashtable` switch will return a

hashtable where the keys are the full names of the name/value pairs. For example, given the INI file above, the

following hashtable is returned:



Name Value

---- -----

spam.eggs Carbon.Ini.IniNode;

spam.green Carbon.Ini.IniNode;

stars.sneetches Carbon.Ini.IniNode;

}



Each line of an INI file contains one entry. If the lines that follow are indented, they are treated as

continuations of that entry. Leading whitespace is removed from values. Empty lines are skipped. Lines beginning

with "#" or ";" are ignored and may be used to provide comments.



Configuration keys can be set multiple times, in which case Split-CIni will use the value that was configured

last. As an example:



[spam]

eggs=large

ham=serrano

eggs=small



This would set the configuration key named "eggs" to "small".



It is also possible to define a section multiple times. For example:



[foo]

eggs=large

ham=serrano

eggs=small



[bar]

eggs=ham

green=

eggs



[foo]

ham=prosciutto

eggs=medium

bread=toasted



This would set the "eggs", "ham", and "bread" configuration keys of the "foo" section to "medium", "prosciutto",

and "toasted", respectively. As you can see, the only thing that matters is the last value that was set for each

of the configuration keys.



Be default, operates on the INI file case-insensitively. If your INI is case-sensitive, use the `-CaseSensitive`

switch.





PARAMETERS

-Path <String>

The path to the mercurial INI file to read.



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-AsHashtable [<SwitchParameter>]

Pass each parsed setting down the pipeline instead of collecting them all into a hashtable.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-CaseSensitive [<SwitchParameter>]

Parses the INI file in a case-sensitive manner.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-WhatIf [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Confirm [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Split-CIni -Path C:\\Users\\rspektor\\mercurial.ini



Given this INI file:



[ui]

username = Regina Spektor <regina@reginaspektor.com>



[extensions]

share =

extdiff =



`Split-CIni` returns the following objects to the pipeline:



Line FullName Section Name Value

---- -------- ------- ---- -----

2 ui.username ui username Regina Spektor <regina@reginaspektor.com>

5 extensions.share extensions share

6 extensions.extdiff extensions extdiff









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Split-CIni -Path C:\\Users\\rspektor\\mercurial.ini -AsHashtable



Given this INI file:



[ui]

username = Regina Spektor <regina@reginaspektor.com>



[extensions]

share =

extdiff =



`Split-CIni` returns the following hashtable:



@{

ui.username = Carbon.Ini.IniNode (

FullName = 'ui.username';

Section = "ui";

Name = "username";

Value = "Regina Spektor <regina@reginaspektor.com>";

LineNumber = 2;

);

extensions.share = Carbon.Ini.IniNode (

FullName = 'extensions.share';

Section = "extensions";

Name = "share"

Value = "";

LineNumber = 5;

)

extensions.extdiff = Carbon.Ini.IniNode (

FullName = 'extensions.extdiff';

Section = "extensions";

Name = "extdiff";

Value = "";

LineNumber = 6;

)

}









-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Split-CIni -Path C:\\Users\\rspektor\\mercurial.ini -AsHashtable -CaseSensitive



Demonstrates how to parse a case-sensitive INI file.



Given this INI file:



[ui]

username = user@example.com

USERNAME = user2example.com



[UI]

username = user3@example.com





`Split-CIni -CaseSensitive` returns the following hashtable:



@{

ui.username = Carbon.Ini.IniNode (

FullName = 'ui.username';

Section = "ui";

Name = "username";

Value = "user@example.com";

LineNumber = 2;

);

ui.USERNAME = Carbon.Ini.IniNode (

FullName = 'ui.USERNAME';

Section = "ui";

Name = "USERNAME";

Value = "user2@example.com";

LineNumber = 3;

);

UI.username = Carbon.Ini.IniNode (

FullName = 'UI.username';

Section = "UI";

Name = "username";

Value = "user3@example.com";

LineNumber = 6;

);

}











RELATED LINKS

Set-CIniEntry

Remove-CIniEntry