Set-IniEntry

Sets an entry in an INI file.

Syntax

Set-IniEntry [-Path] <String> [-Name] <String> [[-Value] <String>] [[-Section] <String>] [-WhatIf] [-Confirm] [<CommonParameters>]

Description

A configuration file consists of sections, led by a [section] header and followed by name = value entries. This function creates or updates an entry in an INI file. Something like this:

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

[extensions]
share = 
extdiff =

Names are not allowed to contains the equal sign, =. Values can contain any character. The INI file is parsed using Split-Ini. See its documentation for more examples.

Related Commands

Parameters

Name Type Description Required? Pipeline Input Default Value
Path String The path to the INI file to set. true false
Name String The name of the INI entry being set. true false
Value String The value of the INI entry being set. false false
Section String The section of the INI where the entry should be set. 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

Set-IniEntry -Path C:\Users\rspektor\mercurial.ini -Section extensions -Name share -Value ''

If the C:\Users\rspektor\mercurial.ini file is empty, adds the following to it:

[extensions]
share =

EXAMPLE 2

Set-IniEntry -Path C:\Users\rspektor\music.ini -Name genres -Value 'alternative,rock'

If the music.ini file is empty, adds the following to it:

genres = alternative,rock

EXAMPLE 3

Set-IniEntry -Path C:\Users\rspektor\music.ini -Name genres -Value 'alternative,rock,world'

If the music.ini file contains the following:

genres = r&b

After running this command, music.ini will look like this:

genres = alternative,rock,world