From e57ad97ea750b21bb022e5c64b6eb1a6f431dce5 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Peters Date: Wed, 22 Nov 2023 09:19:51 +0100 Subject: [PATCH] Add DNS suffixes resource (#217) * Add DNS suffixes resource * Add missing parameter attribtue --- CHANGELOG.md | 2 ++ .../DSCResources/DnsSuffixes/DnsSuffixes.psd1 | 15 +++++++++++ .../DnsSuffixes/DnsSuffixes.schema.psm1 | 26 +++++++++++++++++++ .../Assets/Config/DnsSuffixes.yml | 3 +++ 4 files changed, 46 insertions(+) create mode 100644 source/DSCResources/DnsSuffixes/DnsSuffixes.psd1 create mode 100644 source/DSCResources/DnsSuffixes/DnsSuffixes.schema.psm1 create mode 100644 tests/Unit/DSCResources/Assets/Config/DnsSuffixes.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index cc80d48..6c74411 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - RenameNetworkAdapters - Add composite to rename network adapters - Add documentation +- DnsSuffixes + - new resource to configure connection-specific DNS suffixes ### Changed diff --git a/source/DSCResources/DnsSuffixes/DnsSuffixes.psd1 b/source/DSCResources/DnsSuffixes/DnsSuffixes.psd1 new file mode 100644 index 0000000..dc54ef3 --- /dev/null +++ b/source/DSCResources/DnsSuffixes/DnsSuffixes.psd1 @@ -0,0 +1,15 @@ +@{ + RootModule = 'DnsSuffixes.schema.psm1' + + ModuleVersion = '0.0.1' + + GUID = '20392fe9-270d-4295-af2c-2401dd015596' + + Author = 'NA' + + CompanyName = 'NA' + + Copyright = 'NA' + + DscResourcesToExport = @('DnsSuffixes') +} diff --git a/source/DSCResources/DnsSuffixes/DnsSuffixes.schema.psm1 b/source/DSCResources/DnsSuffixes/DnsSuffixes.schema.psm1 new file mode 100644 index 0000000..4ec2267 --- /dev/null +++ b/source/DSCResources/DnsSuffixes/DnsSuffixes.schema.psm1 @@ -0,0 +1,26 @@ +configuration DnsSuffixes +{ + param + ( + [Parameter(Mandatory = $true)] + [hashtable[]] + $Suffixes + ) + + Import-DscResource -ModuleName NetworkingDsc -Name DnsConnectionSuffix + + foreach ($suffix in $Suffixes) + { + # Remove Case Sensitivity of ordered Dictionary or Hashtables + $suffix = @{} + $suffix + + if (-not $suffix.ContainsKey('Ensure')) + { + $suffix.Ensure = 'Present' + } + + $executionName = "dnssuffix_$($suffix.InterfaceAlias)_$($suffix.ConnectionSpecificSuffix)" -replace '[()-.:\s]', '_' + + (Get-DscSplattedResource -ResourceName DnsConnectionSuffix -ExecutionName $executionName -Properties $suffix -NoInvoke).Invoke($suffix) + } +} diff --git a/tests/Unit/DSCResources/Assets/Config/DnsSuffixes.yml b/tests/Unit/DSCResources/Assets/Config/DnsSuffixes.yml new file mode 100644 index 0000000..4aead39 --- /dev/null +++ b/tests/Unit/DSCResources/Assets/Config/DnsSuffixes.yml @@ -0,0 +1,3 @@ +Suffixes: + - InterfaceAlias: en0 + ConnectionSpecificSuffix: contoso.com