Split-Ini

Reads an ini file and returns its contents as a hashtable.

Syntax

Split-Ini -Path <String> [-PassThru] [-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

This file will be returned as a hash like this:

@{
    spam.eggs =  @{
                    Section = 'spam';
                    Name = 'eggs';
                    Value = 'ham';
                    LineNumber = 1;
                  };
    spam.green = @{
                    Section = 'spam';
                    Name = 'green';
                    Value = "`neggs";
                    LineNumber = 2;
                  };
    stars.sneetches = @{
                            Section = 'stars';
                            Name = 'sneetches';
                            Value = 'belly'
                            LineNumber = 6;
                       }
}

Each line 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-Ini 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 there only thing that matters is the last value that was set for each of the configuration keys.

Parameters

Name Type Description Required? Pipeline Input Default Value
Path String The path to the mercurial INI file to read. true false
PassThru SwitchParameter Pass each parsed setting down the pipeline instead of collecting them all into a hashtable. false false
WhatIf SwitchParameter false false
Confirm SwitchParameter false false
CommonParameters This cmdlet supports common parameters. For more information type
Get-Help about_CommonParameters.

EXAMPLE 1

Split-Ini -Path C:\Users\rspektor\mercurial.ini

Given this INI file:

[ui]
username = Regina Spektor <regina@reginaspektor.com>

[extensions]
share = 
extdiff =

Split-Ini returns the following hashtable:

@{
    ui.username = @{
                        FullName = 'ui.username';
                        Section = "ui";
                        Name = "username";
                        Value = "Regina Spektor <regina@reginaspektor.com>";
                        LineNumber = 1;
                    };
    extensions.share = @{
                            FullName = 'extensions.share';
                            Section = "extensions";
                            Name = "share"
                            Value = "";
                            LineNumber = 4;
                        };
    extensions.extdiff = @{
                               FullName = 'extensions.extdiff';
                               Section = "extensions";
                               Name = "extdiff";
                               Value = "";
                               LineNumber = 5;
                          };
}

EXAMPLE 2

Split-Ini -Path C:\Users\rspektor\mercurial.ini -PassThru

Given this INI file:

[ui]
username = Regina Spektor <regina@reginaspektor.com>

[extensions]
share = 
extdiff =

Split-Ini returns the following hashtables to the pipeline:

@{
    FullName = 'ui.username';
    Section = "ui";
    Name = "username";
    Value = "Regina Spektor <regina@reginaspektor.com>";
    LineNumber = 1;
}
@{
    FullName = 'extensions.share';
    Section = "extensions";
    Name = "share"
    Value = "";
    LineNumber = 4;
}
@{
   FullName = 'extensions.extdiff';
   Section = "extensions";
   Name = "extdiff";
   Value = "";
   LineNumber = 5;
}