-
Notifications
You must be signed in to change notification settings - Fork 5
KeyValuePairFile
Daniel Scott-Raynsford edited this page Jun 18, 2017
·
7 revisions
Parameter | Attribute | DataType | Description | Allowed Values |
---|---|---|---|---|
Path | Key | String | The path to the key value pair text file. | |
Name | Key | String | The name of the key. | |
Ensure | Write | String | Specifies the if the key value pair with the specified key should exist in the file. | Present, Absent |
Type | Write | String | Specifies the value type to use as the replacement string. Defaults to 'Text'. | Text, Secret |
Text | Write | String | The text to replace the value with in the identified key. Only used when Type is set to 'Text'. | |
Secret | write | String | The secret text to replace the value with in the identified key. Only used when Type is set to 'Secret'. | |
IgnoreNameCase | Write | Boolean | Ignore the case of the name of the key. Defaults to $False. | |
IgnoreValueCase | Write | Boolean | Ignore the case of any text or secret when determining if it they need to be updated. Defaults to $False. |
The KeyValuePairFile resource is used to add, remove or set key/value pairs in a text file containing key/value pair entries.
This resource is intended to be used to set key/value pair values in configuration or data files where no partitions or headings are used to separate entries and each line contains only a single entry.
This resource should not be used to configure INI files. The IniSettingFile resource should be used instead.
Set all Core.Logging
keys to Information
or add it
if it is missing in the file c:\myapp\myapp.conf
.
Configuration Example
{
param
(
[Parameter()]
[System.String[]]
$NodeName = 'localhost'
)
Import-DSCResource -ModuleName FileContentDsc
Node $NodeName
{
KeyValuePairFile SetCoreLogging
{
Path = 'c:\myapp\myapp.conf'
Name = 'Core.Logging'
Ensure = 'Present'
Text = 'Information'
}
}
}
Remove all Core.Logging
keys in the file c:\myapp\myapp.conf
.
Configuration Example
{
param
(
[Parameter()]
[System.String[]]
$NodeName = 'localhost'
)
Import-DSCResource -ModuleName FileContentDsc
Node $NodeName
{
KeyValuePairFile RemoveCoreLogging
{
Path = 'c:\myapp\myapp.conf'
Name = 'Core.Logging'
Ensure = 'Absent'
}
}
}
Set all Core.Password
keys to the password provided in the $Secret
credential object or add it if it is missing in the file c:\myapp\myapp.conf
.
Configuration Example
{
param
(
[Parameter()]
[System.String[]]
$NodeName = 'localhost',
[Parameter()]
[ValidateNotNullorEmpty()]
[PSCredential]
$Secret
)
Import-DSCResource -ModuleName FileContentDsc
Node $NodeName
{
KeyValuePairFile SetCoreLogging
{
Path = 'c:\myapp\myapp.conf'
Name = 'Core.Password'
Ensure = 'Present'
Type = 'Secret'
Secret = $Secret
}
}
}