Please use DSCR_FileContent module.
PowerShell DSC Resource to create JSON format file.
You can install Resource through PowerShell Gallery.
Install-Module -Name DSCR_JsonFile
-
[string] Ensure (Write):
- Specify the key exists or not.
- The default value is
Present
. (Present
|Absent
)
-
[string] Path (Key):
- The path of the JSON file.
-
[string] Key (Key):
- Key element.
-
[string] Value (Key):
- The value corresponding to the key.
- The value of this parameter must be a JSON formatted string.
-
[string] Encoding (Write):
- You can choose text encoding for the JSON file.
- utf8NoBOM (default) / utf8BOM / utf32 / unicode / bigendianunicode / ascii
-
[string] NewLine (Write):
- You can choose new line code for the JSON file.
- CRLF (default) / LF
- Example 1: Sample configuration
Configuration Example1 {
Import-DscResource -ModuleName DSCR_JsonFile
cJsonFile String {
Path = 'C:\Test.json'
Key = 'StringValue'
Value = '"Apple"'
}
cJsonFile Bool {
Path = 'C:\Test.json'
Key = 'BoolValue'
Value = 'true'
}
cJsonFile Array {
Path = 'C:\Test.json'
Key = "ArrayValue"
Value = '[true, 123, "banana"]'
}
}
The result of executing the above configuration, the following JSON file will output to C:\Test.json
{
"BoolValue": true,
"StringValue": "Apple",
"ArrayValue": [
true,
123,
"banana"
]
}
- Fixed an issue that Set-TargetResource fails when the parent folder of the
Path
is not exist.
- Fix casing miss of the module name
- Remove unnecessary files in the published package
- Initial public release