From e0b196cbb3b9cf0b7649699b4a30f8fb0cb070ed Mon Sep 17 00:00:00 2001 From: Cory Wood Date: Wed, 27 Sep 2023 00:24:25 -0500 Subject: [PATCH] Add support for overwriting the hostname and/or certificate thumbprint on the listener - Fixes #23 (#101) * Added support for changing the hostname and/or certificate thumbprint on the listener. * Updated changelog. --- CHANGELOG.md | 3 +++ .../DSC_WSManListener/DSC_WSManListener.psm1 | 20 +++++++++++++++++++ .../en-US/DSC_WSManListener.strings.psd1 | 2 ++ 3 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c09cf6..da4f19f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- WSManDsc + - Added support for changing the hostname and/or certificate thumbprint on the listener - fixes [Issue #23](https://github.com/dsccommunity/WSManDsc/issues/23). + ### Added - Added build task `Generate_Conceptual_Help` to generate conceptual help diff --git a/source/DSCResources/DSC_WSManListener/DSC_WSManListener.psm1 b/source/DSCResources/DSC_WSManListener/DSC_WSManListener.psm1 index 75631c8..6f41b43 100644 --- a/source/DSCResources/DSC_WSManListener/DSC_WSManListener.psm1 +++ b/source/DSCResources/DSC_WSManListener/DSC_WSManListener.psm1 @@ -462,6 +462,26 @@ function Test-TargetResource ) -join '' ) $desiredConfigurationMatch = $false } + + if ($PSBoundParameters.ContainsKey('Hostname') -and $listener.Hostname -ne $Hostname) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($script:localizedData.ListenerOnWrongHostnameMessage) ` + -f $Transport, $listener.Hostname, $Hostname + ) -join '' ) + $desiredConfigurationMatch = $false + } + + if ($PSBoundParameters.ContainsKey('CertificateThumbprint') -and $listener.CertificateThumbprint -ne $CertificateThumbprint) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($script:localizedData.ListenerOnWrongCertificateThumbprintMessage) ` + -f $Transport, $listener.CertificateThumbprint, $CertificateThumbprint + ) -join '' ) + $desiredConfigurationMatch = $false + } } else { diff --git a/source/DSCResources/DSC_WSManListener/en-US/DSC_WSManListener.strings.psd1 b/source/DSCResources/DSC_WSManListener/en-US/DSC_WSManListener.strings.psd1 index 7e66415..a28a7b1 100644 --- a/source/DSCResources/DSC_WSManListener/en-US/DSC_WSManListener.strings.psd1 +++ b/source/DSCResources/DSC_WSManListener/en-US/DSC_WSManListener.strings.psd1 @@ -12,6 +12,8 @@ ConvertFrom-StringData @' TestingListenerMessage = Testing Listener. ListenerOnWrongPortMessage = {0} Listener is on port {1}, should be on {2}. Change required. ListenerOnWrongAddressMessage = {0} Listener is bound to {1}, should be {2}. Change required. + ListenerOnWrongHostnameMessage = {0} Listener Hostname is {1}, should be {2}. Change required. + ListenerOnWrongCertificateThumbprintMessage = {0} Listener Certificate Thumbprint is {1}, should be {2}. Change required. ListenerDoesNotExistButShouldMessage = {0} Listener does not exist but should. Change required. ListenerExistsButShouldNotMessage = {0} Listener exists but should not. Change required. ListenerDoesNotExistAndShouldNotMessage = {0} Listener does not exist and should not. Change not required.