{"id":15292649,"url":"https://github.com/mkht/dscr_filecontent","last_synced_at":"2025-04-13T11:32:54.100Z","repository":{"id":57668218,"uuid":"155001435","full_name":"mkht/DSCR_FileContent","owner":"mkht","description":"PowerShell DSC Resource to create TEXT / INI / JSON files.","archived":false,"fork":false,"pushed_at":"2024-01-02T19:05:29.000Z","size":98,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-09T22:33:34.617Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkht.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-27T19:28:32.000Z","updated_at":"2023-09-06T14:07:25.000Z","dependencies_parsed_at":"2024-09-30T16:25:23.809Z","dependency_job_id":"d6bbe87d-5467-45f8-b0e9-dffe739a9c7d","html_url":"https://github.com/mkht/DSCR_FileContent","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkht%2FDSCR_FileContent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkht%2FDSCR_FileContent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkht%2FDSCR_FileContent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkht%2FDSCR_FileContent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkht","download_url":"https://codeload.github.com/mkht/DSCR_FileContent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248705982,"owners_count":21148622,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-30T16:25:21.760Z","updated_at":"2025-04-13T11:32:54.073Z","avatar_url":"https://github.com/mkht.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"DSCR_FileContent\n====\n\nPowerShell DSC Resource to create TEXT / INI / JSON files.\n\n## Install\nYou can install resource from [PowerShell Gallery](https://www.powershellgallery.com/packages/DSCR_FileContent/).\n```Powershell\nInstall-Module -Name DSCR_FileContent -Scope AllUsers\n```\n\n### Dependencies\nAlso, this module depends with [PSAdvancedJsonCmdlet](https://www.powershellgallery.com/packages/PSAdvancedJsonCmdlet/) module.  \nIt will be installed through PowerShell Gallery automatically, but you can also install explicitly.\n```Powershell\nInstall-Module -Name PSAdvancedJsonCmdlet -Scope AllUsers\n```\n\n----\n## DSC Resources\n\n### TextFile\nPowerShell DSC Resource to create text file.\n\n#### Properties\n+ [string] **Ensure** (Write):\n    + Specify the file exists or not.\n    + The default value is `Present`. (`Present` | `Absent`)\n\n+ [string] **Path** (Key):\n    + The path of the file.\n\n+ [string] **Contents** (Write):\n    + The contents of file.\n\n+ [string] **Encoding** (Write):\n    + You can choose text encoding for the file.\n    + `UTF8NoBOM` (default) / `UTF8BOM` / `utf32` / `unicode` / `bigendianunicode` / `ascii` / `sjis`\n\n+ [string] **NewLine** (Write):\n    + You can choose new line code for the file.\n    + `CRLF` (default) / `LF`\n\n\n### Examples\n+ **Example 1**\n```Powershell\nConfiguration Example1 {\n    Import-DscResource -ModuleName DSCR_FileContent\n    TextFile SampleTxt {\n        Path = \"C:\\TestTxt.txt\"\n        Contents = \"This is sample txt\"\n        Encoding = 'utf8NoBOM'\n        NewLine = 'LF'\n    }\n}\n```\n\n### IniFile\nPowerShell DSC Resource to create ini file.\n\n#### Properties\n+ [string] **Ensure** (Write):\n    + Specify the key exists or not.\n    + The default value is `Present`. (`Present` | `Absent`)\n\n+ [string] **Path** (Key):\n    + The path of the INI file.\n\n+ [string] **Key** (Key):\n    + Key element.\n    + If you specified key as empty string, IniFile only check the section.\n\n+ [string] **Value** (Write):\n    + The value corresponding to the key.\n    + If this param not specified, will set empty string.\n\n+ [string] **Section** (Key):\n    + The section to which the key belongs.\n    + **If the key doesn't need to belong section, you should set the value for an empty string.**\n\n+ [string] **Encoding** (Write):\n    + You can choose text encoding for the INI file.\n    + `UTF8NoBOM` (default) / `UTF8BOM` / `utf32` / `unicode` / `bigendianunicode` / `ascii` / `sjis`\n\n+ [string] **NewLine** (Write):\n    + You can choose new line code for the INI file.\n    + `CRLF` (default) / `LF`\n\n\n### Examples\n+ **Example 1**\n```Powershell\nConfiguration Example1 {\n    Import-DscResource -ModuleName DSCR_FileContent\n    IniFile Apple {\n        Path = \"C:\\Test.ini\"\n        Section = \"\"\n        Key = \"Fruit_A\"\n        Value = \"Apple\"\n    }\n    IniFile Banana {\n        Path = \"C:\\Test.ini\"\n        Section = \"\"\n        Key = \"Fruit_B\"\n        Value = \"Banana\"\n    }\n    IniFile Ant {\n        Path = \"C:\\Test.ini\"\n        Section = \"Animals\"\n        Key = \"Animal_A\"\n        Value = \"Ant\"\n    }\n}\n```\n\nThe result of executing the above configuration, the following ini file will output to `C:\\Test.ini`\n```\nFruit_A=Apple\nFruit_B=Banana\n\n[Animals]\nAnimal_A=Ant\n```\n\n\n### JsonFile\nPowerShell DSC Resource to create JSON file.\n\n### Properties\n+ [string] **Ensure** (Write):\n    + Specify the key exists or not.\n    + The default value is `Present`. (`Present` | `Absent`)\n\n+ [string] **Path** (Key):\n    + The path of the JSON file.\n\n+ [string] **Key** (Key):\n    + Key element.\n    + A slash delimiter can be used to specify a dictionary subkey. (See Example2)\n\n+ [string] **Value** (Key):\n    + The value corresponding to the key.\n    + The value of this parameter must be a JSON formatted string.\n\n+ [string] **Encoding** (Write):\n    + You can choose text encoding for the JSON file.\n    + `UTF8NoBOM` (default) / `UTF8BOM` / `utf32` / `unicode` / `bigendianunicode` / `ascii` / `sjis`\n\n+ [string] **NewLine** (Write):\n    + You can choose new line code for the JSON file.\n    + CRLF (default) / LF\n\n+ [bool] **UseLegacy** (Write):\n    + From `3.0.0`, This module uses Newtonsoft.Json based JSON serializer provided by [PSAdvancedJsonCmdlet](https://www.powershellgallery.com/packages/PSAdvancedJsonCmdlet) instead of PowerShell built-in cmdlets.\n    + If `UseLegacy` specifies as `$true`, It will use built-in cmdlets.\n    + Default value is `$false`.\n\n### Examples\n+ **Example 1**\n```Powershell\nConfiguration Example1 {\n    Import-DscResource -ModuleName DSCR_FileContent\n    JsonFile String {\n        Path = 'C:\\Test.json'\n        Key = 'StringValue'\n        Value = '\"Apple\"'\n    }\n    JsonFile Bool {\n        Path = 'C:\\Test.json'\n        Key = 'BoolValue'\n        Value = 'true'\n    }\n    JsonFile Array {\n        Path = 'C:\\Test.json'\n        Key = \"ArrayValue\"\n        Value = '[true, 123, \"banana\"]'\n    }\n}\n```\n\nThe result of executing the above configuration, the following JSON file will output to `C:\\Test.json`\n```json\n{\n  \"StringValue\": \"Apple\",\n  \"BoolValue\": true,\n  \"ArrayValue\": [\n    true,\n    123,\n    \"banana\"\n  ]\n}\n```\n\n+ **Example 2**\n```Powershell\nConfiguration Example2 {\n    Import-DscResource -ModuleName DSCR_FileContent\n    JsonFile Dictionary {\n        Path = 'C:\\Test2.json'\n        Key = 'KeyA'\n        Value = '{\"Ame\":false,\"Gura\":true}'\n    }\n    JsonFile SubDictionary {\n        Path = 'C:\\Test2.json'\n        Key = 'KeyB/SubKeyB'\n        Value = 'Ina'\n    }\n    #If the key name contains a slash, please escape it with a backslash\n    JsonFile SubDictionaryWithSlash {\n        Path = 'C:\\Test2.json'\n        Key = 'KeyB/Sub\\/\\/Key'\n        Value = 'Kiara'\n    }\n}\n```\n\nThe result of executing the above configuration, the following JSON file will output to `C:\\Test2.json`\n```json\n{\n  \"KeyA\": {\n    \"Ame\": false,\n    \"Gura\": true\n  },\n  \"KeyB\": {\n    \"SubKeyB\": {\n      \"Ina\": true,\n      \"Calli\": true\n    },\n    \"Sub//Key\": \"Kiara\"\n  }\n}\n```\n\n----\n## Functions\n\n### Get-IniFile\nLoad ini file and convert to the dictionary object\n\n+ **Syntax**\n```PowerShell\nGet-IniFile [-Path] \u003cstring\u003e [-Encoding { \u003cutf8\u003e | \u003cutf8BOM\u003e | \u003cutf32\u003e | \u003cunicode\u003e | \u003cbigendianunicode\u003e | \u003cascii\u003e | \u003csjis\u003e | \u003cDefault\u003e }]\n```\n\n\n### ConvertTo-IniString\nConvert dictionary object to ini expression string\n\n+ **Syntax**\n```PowerShell\nConvertTo-IniString [-InputObject] \u003cSystem.Collections.Specialized.OrderedDictionary\u003e\n```\n\n+ **Example**\n```PowerShell\nPS\u003e $Dictionary = [ordered]@{ Section1 = @{ Key1 = 'Value1'; Key2 = 'Value2' } }\nPS\u003e ConvertTo-IniString -InputObject $Dictionary\n[Section1]\nKey1=Value1\nKey2=Value2\n```\n\n\n### Set-IniKey\nSet a key value pair to the dictionary\n\n+ **Syntax**\n```PowerShell\nSet-IniKey [-InputObject] \u003cSystem.Collections.Specialized.OrderedDictionary\u003e -Key \u003cstring\u003e [-Value \u003cstring\u003e] [-Section \u003cstring\u003e] [-PassThru]\n```\n\n+ **Example**\n```PowerShell\nPS\u003e $Dictionary = [ordered]@{ Section1 = @{ Key1 = 'Value1'; Key2 = 'Value2' } }\nPS\u003e $Dictionary | Set-IniKey -Key 'Key2' -Value 'ModValue2' -Section 'Section1' -PassThru | ConvertTo-IniString\n[Section1]\nKey1=Value1\nKey2=ModValue2\n```\n\n\n### Remove-IniKey\nRemove a key value pair from dictionary\n\n+ **Syntax**\n```PowerShell\nRemove-IniKey [-InputObject] \u003cSystem.Collections.Specialized.OrderedDictionary\u003e -Key \u003cstring\u003e [-Section \u003cstring\u003e] [-PassThru]\n```\n\n+ **Example**\n```PowerShell\nPS\u003e $Dictionary = [ordered]@{ Section1 = @{ Key1 = 'Value1'; Key2 = 'Value2' } }\nPS\u003e $Dictionary | Remove-IniKey -Key 'Key2' -Section 'Section1' -PassThru | ConvertTo-IniString\n[Section1]\nKey1=Value1\n```\n\n----\n## ChangeLog\n### 3.0.2\n+ [JsonFile] Fixed an issue where JSON containing dictionaries within array elements was not correctly parsed.\n+ Revised the structure of the test code\n+ Added automated test execution using GitHub Actions Workflow\n\n### 3.0.1\n+ [JsonFile] Fixed an issue that the arrays with a single element mistakenly treated as a single value.\n\n### 3.0.0\n+ Changed JSON parser from PowerShell built-in cmdlets to [PSAdvancedJsonCmdlet](https://www.powershellgallery.com/packages/PSAdvancedJsonCmdlet) module.  \n  This change improves handling for non-compliant JSON format. (e.g., JSON with comments) and consistency of behavior between PS 7 and PS 5.1.\n+ The minimum supported version of PowerShell changed from `5.0` to `5.1`.\n\n### 2.4.2\n+ Fixed an issue that line feeds may not be added correctly when an array of strings is input to `Set-NewContent` from the pipeline.\n\n### 2.4.1\n+ Export new functions `Convert-NewLine` \u0026 `Set-NewContent`\n\n### 2.3.0\n+ [JsonFile] Subkeys of dictionary can now be specified as keys using slash delimiter.\n+ [JsonFile] Fix some security issues.\n\n### 2.2.0\n+ Add `sjis` (Japanese Shift_JIS) encoding support.\n+ Improve compatibility with PowerShell 7. (Since this version, supports PS7)\n\n### 2.1.1\n + [IniFile] Fixed an issue where extra blank lines might be inserted in the first line of ini file.\n\n### 2.1.0\n + The functions `ConvertTo-IniString`, `Set-IniKey`, `Remove-IniKey` accept not only `[System.Collections.Specialized.OrderedDictionary]` but also `[hashtable]` input types.\n + [IniFile] Add a blank line to the beginning of sections.\n + [IniFile] Improved performance when dealing with large files.\n + Misc fixes.\n\n### 2.0.0\n + [JsonFile] Fixed an issue that Get-TargetResource throws an exception when the array contains NULL. \n + [JsonFile] Fixed an issue that empty string and NULL could not be set. [#4](https://github.com/mkht/DSCR_FileContent/issues/4)\n + [JsonFile] Improved to preserve key order when modifying JSON file.\n + [JsonFile] Fixed issue that creating a child key may fail when the parent key has value. [#3](https://github.com/mkht/DSCR_FileContent/issues/3) \n + [JsonFile] (***BREAKING CHANGES***) Changes the behavior when specifying a value that bool or bool parsable to the `Value` parameter. (See [#2](https://github.com/mkht/DSCR_FileContent/issues/2))\n + Add unit tests for helper functions.\n\n### 1.0.3\n + Fixed an issue where character at the end of line may not be output correctly when `CRLF` is specified for NewLine.\n\n### 1.0.1\n + Fixed regression issue.\n\n### 1.0.0\n + Add `TextFile` resource.\n + DSCR_FileContent is integrated module of [DSCR_IniFile](https://github.com/mkht/DSCR_IniFile) and [DSCR_JsonFile](https://github.com/mkht/DSCR_JsonFile).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkht%2Fdscr_filecontent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkht%2Fdscr_filecontent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkht%2Fdscr_filecontent/lists"}