Code Monkey home page Code Monkey logo

updateservicesdsc's Introduction

UpdateServicesDsc

Build Status Azure DevOps coverage (branch) Azure DevOps tests PowerShell Gallery (with prereleases) PowerShell Gallery

The UpdateServicesDsc module contains DSC resources for deployment and configuration of Windows Server Update Services.

Code of Conduct

This project has adopted this code of conduct.

Support

This module is community maintained as a best-effort open source project and has no expressed support from any individual or organization.

Releases

For each merge to the branch master a preview release will be deployed to PowerShell Gallery. Periodically a release version tag will be pushed which will deploy a full release to PowerShell Gallery.

Contributing

Please check out common DSC Community contributing guidelines.

Installation

From GitHub source code

To manually install the module, download the source code from GitHub and unzip the contents to the '$env:ProgramFiles\WindowsPowerShell\Modules' folder.

From PowerShell Gallery

To install from the PowerShell gallery using PowerShellGet (in PowerShell 5.0) run the following command:

Find-Module -Name UpdateServicesDsc | Install-Module

To confirm installation, run the below command and ensure you see the SQL Server DSC resources available:

Get-DscResource -Module UpdateServicesDsc

Requirements

The minimum Windows Management Framework (PowerShell) version required is 5.0 or higher, which ships with Windows 10 or Windows Server 2016, but can also be installed on Windows 7 SP1, Windows 8.1, Windows Server 2008 R2 SP1, Windows Server 2012 and Windows Server 2012 R2.

Details

UpdateServicesApprovalRule resource has following properties

  • Ensure: An enumerated value that describes if the ApprovalRule is available
  • Name: Name of the approval rule.
  • Classifications: Classifications in the approval rule.
  • Products: Products in the approval rule.
  • ComputerGroups: Computer groups the approval rule applies to.
  • Enabled: Whether the approval rule is enabled.
  • Synchronize: Synchronize after creating or updating the approval rule.

UpdateServicesCleanup resource has following properties:

  • Ensure: An enumerated value that describes if the WSUS cleanup task exists.
  • DeclineSupersededUpdates: Decline updates that have not been approved for 30 days or more, are not currently needed by any clients, and are superseded by an approved update.
  • DeclineExpiredUpdates: Decline updates that aren't approved and have been expired by Microsoft.
  • CleanupObsoleteUpdates: Delete updates that are expired and have not been approved for 30 days or more, and delete older update revisions that have not been approved for 30 days or more.
  • CompressUpdates: Compress updates.
  • CleanupObsoleteComputers: Delete computers that have not contacted the server in 30 days or more.
  • CleanupUnneededContentFiles: Delete update files that aren't needed by updates or downstream servers.
  • CleanupLocalPublishedContentFiles: Cleanup local published content files.
  • TimeOfDay Time of day to start cleanup.

UpdateServicesServer resource has following properties:

  • Ensure: An enumerated value that describes if WSUS is configured.
  • SetupCredential: Credential to be used to perform the initial configuration.
  • SQLServer: SQL Server for the WSUS database, omit for Windows Internal Database.
  • ContentDir: Folder for WSUS update files.
  • UpdateImprovementProgram: Join the Microsoft Update Improvement Program.
  • UpstreamServerName: Upstream WSUS server, omit for Microsoft Update.
  • UpstreamServerPort: Port of upstream WSUS server.
  • UpstreamServerSSL: Use SSL with upstream WSUS server.
  • UpstreamServerReplica: Replica of upstream WSUS server.
  • ProxyServerName: Proxy server to use when synchronizing, omit for no proxy.
  • ProxyServerPort: Proxy server port.
  • ProxyServerCredential: Proxy server credential, omit for anonymous.
  • ProxyServerCredentialUsername: Proxy server credential username.
  • ProxyServerBasicAuthentication: Allow proxy server basic authentication.
  • Languages: Update languages, * for all.
  • Products: Update products, * for all.
  • Classifications: Update classifications, * for all.
  • SynchronizeAutomatically: Synchronize automatically.
  • SynchronizeAutomaticallyTimeOfDay: First synchronization.
  • SynchronizationsPerDay: Synchronizations per day.
  • Synchronize: Begin initial synchronization.
  • ClientTargetingMode: An enumerated value that describes if how the Target Groups are populated.

Versions

Plese refer to the Changelog

updateservicesdsc's People

Contributors

berglundth avatar dscbot avatar firefishy avatar gaelcolas avatar mgreenegit avatar nicolasbn avatar quaeritate avatar rdbartram avatar robwi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

updateservicesdsc's Issues

Readme.md error ?

I assume on Read.me under xWSUSApprovalRule
the "Ensure: An enumerated value that describes if WSUS is configured."
is just a small error in description as its probably "..describes if the ApprovalRule is available". ?

UpdateServicesServer: WSUS.cab file is missing products

Details of the scenario you tried and the problem that is occurring

The initial sync WSUS.cab file is out of date and is missing Windows Server 2019 and other products.

The following snippet fails because Windows Server 2019 is not a known product.

UpdateServicesServer 'UpdateServices' {
  Synchronize = $false # Default, use WSUS.cab
  Products = @(
    'Windows Server 2019'
  )
 ...

Verbose logs showing the problem

[[UpdateServicesServer]UpdateServices] Products test failed
[[UpdateServicesServer]UpdateServices] Test-TargetResouce returned false after calling set. | ErrorType: MSFT_UpdateServicesServer.TestFailedAfterSet

After a full sync, Windows Server 2019 product can be used.

Suggested solution to the issue

Please update bundled WSUS metadata export in WSUS.cab

The DSC configuration that is used to reproduce the issue (as detailed as possible)

See above.

The operating system the target node is running

Windows Server 2019

Version and build of PowerShell the target node is running

5.1.17763.1007

Version of the DSC module that was used

UpdateServicesDsc 1.1.0.0

UpdateServicesServer, UpdateServicesApprovalRule: Allow use of friendly names or GUIDs in Products, Classifications

Details of the scenario you tried and the problem that is occurring

This is for both the UpdateServicesServer and UpdateServicesApprovalRule resources:
The Products property currently accepts friendly names while Classifications accepts GUIDs. GUIDs are not overly easy to work with. Given that there's already code to translate Titles to GUIDs for Products, the same approach could be used for Classifications as well.

I am aware that this has already been discussed in #18

Verbose logs showing the problem

Suggested solution to the issue

To avoid language dependency, as well as to avoid the introduction of breaking change, the properties could be made to accept both friendly names as well as GUIDs. The desired values could be compared against Title or ID.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

# This works OK
Configuration WSUSProduct {
    Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
    Import-DscResource -ModuleName 'UpdateServicesDsc' -ModuleVersion 1.2.1
    
    Node localhost {
 
        UpdateServicesServer WSUS {
            Ensure = 'Present'
            Languages = 'en'

            # Classification must be a GUID
            Classifications = '0fa1201d-4330-4fa8-8ae9-b877473b6441' # Security Updates

            # Products use Title
            Products = 'Windows Server 2016'
        }
    }
}

# This does not work
Configuration WSUSProduct {
    Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
    Import-DscResource -ModuleName 'UpdateServicesDsc' -ModuleVersion 1.2.1
    
    Node localhost {
 
        UpdateServicesServer WSUS {
            Ensure = 'Present'
            Languages = 'en'

            # Title can't be used in Classifications
            Classifications = 'Security Updates'

            # GUIDs can't be used in Products 
            Products = '569e8e8f-c6cd-42c8-92a3-efbb20a0f6f5' # Windows Server 2016
        }
    }
}

The operating system the target node is running

OsName               : Microsoft Windows Server 2019 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1809
WindowsBuildLabEx    : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running

Name                           Value                                                                                                                                                    
----                           -----                                                                                                                                                    
PSVersion                      5.1.17763.1490                                                                                                                                           
PSEdition                      Desktop                                                                                                                                                  
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                  
BuildVersion                   10.0.17763.1490                                                                                                                                          
CLRVersion                     4.0.30319.42000                                                                                                                                          
WSManStackVersion              3.0                                                                                                                                                      
PSRemotingProtocolVersion      2.3                                                                                                                                                      
SerializationVersion           1.1.0.1 

Version of the DSC module that was used

Name              Version Path                                                                                       
----              ------- ----                                                                                       
UpdateServicesDsc 1.2.1   C:\Program Files\WindowsPowerShell\Modules\UpdateServicesDsc\1.2.1\UpdateServicesDsc.psd1

Rename request

Can you please rename the repo by clicking Settings, typing in "WSUSDsc", then clicking Rename.

DeleteInstallApprovalRule requires ruleId not Name

On attempting to remove a rule I got this error:

VERBOSE: [SESTO869]: LCM:  [ Start  Resource ]  [[UpdateServicesApprovalRule]RemoveDefaultApprovalRule]
VERBOSE: [SESTO869]: LCM:  [ Start  Test     ]  [[UpdateServicesApprovalRule]RemoveDefaultApprovalRule]
VERBOSE: [SESTO869]:                            [[UpdateServicesApprovalRule]RemoveDefaultApprovalRule] Identified WSUS
 server information: Microsoft.UpdateServices.Internal.BaseApi.UpdateServer
VERBOSE: [SESTO869]:                            [[UpdateServicesApprovalRule]RemoveDefaultApprovalRule] Ensure test
failed
VERBOSE: [SESTO869]: LCM:  [ End    Test     ]  [[UpdateServicesApprovalRule]RemoveDefaultApprovalRule]  in 0.4360
seconds.
VERBOSE: [SESTO869]: LCM:  [ Start  Set      ]  [[UpdateServicesApprovalRule]RemoveDefaultApprovalRule]
VERBOSE: [SESTO869]:                            [[UpdateServicesApprovalRule]RemoveDefaultApprovalRule] Failed during
creation of approval rule Default Automatic Approval Rule
VERBOSE: [SESTO869]: LCM:  [ End    Set      ]  [[UpdateServicesApprovalRule]RemoveDefaultApprovalRule]  in 0.2810
seconds.
PowerShell DSC resource MSFT_UpdateServicesApprovalRule  failed to execute Set-TargetResource functionality with error
message: Cannot convert argument "ruleId", with value: "Default Automatic Approval Rule", for "DeleteInstallApprovalRul
e" to type "System.Int32": "Cannot convert value "Default Automatic Approval Rule" to type "System.Int32". Error: "Inpu
t string was not in a correct format.""
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : SESTO869

When looking at the function signature of DeleteInstallApprovalRule it seems like it accepts the ruleId and not the name:

TypeName   : Microsoft.UpdateServices.Internal.BaseApi.UpdateServer
Name       : DeleteInstallApprovalRule
MemberType : Method
Definition : void DeleteInstallApprovalRule(int ruleId), void IUpdateServer.DeleteInstallApprovalRule(int ruleId)

And here's the calling code
DSCResources/MSFT_UpdateServicesApprovalRule/MSFT_UpdateServicesApprovalRule.psm1 - Row 242

                "Absent"
                {
                    $WsusServer.DeleteInstallApprovalRule($Name)
                }

[UpdateServicesServer]: master branch resource mistype in if statement for #ClientTargetingMode check

Details of the scenario you tried and the problem that is occurring

UpdateServicesServer: Set-TargetResource mistype in check #ClientTargetingMode
spaces in "Client Targeting Mode", wherefore test is failing and DSC is throwing error

#ClientTargetingMode
        if($PSBoundParameters.ContainsKey("Client Targeting Mode"))

Verbose logs showing the problem

Suggested solution to the issue

Merge dev branch which has correct syntax to master branch.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

The operating system the target node is running

Version and build of PowerShell the target node is running

Version of the DSC module that was used ('dev' if using current dev branch)

master

[UpdateServicesServer]Products test failed

Details of the scenario you tried and the problem that is occurring

I have a specific array of Windows Products that I have entered for the "Products" portion in the UpdateServicesServer resource. When I attempt to load the DSC configuration, I get the following error during test/set:

Products test failed.
Cannot validate argument on parameter 'ErrorRecord'. The argument is null. Provide a valid value for the argument, and then try running the command again. At line:1 char:21 + $params = $args[0]; Set-TargetResource @params -Verbose + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Verbose logs showing the problem

See above

Suggested solution to the issue

Uncertain at this time. I switched to a single product for the configuration resource & it completed successfully. I believe it has something to do with my product list.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

See the code here: https://github.com/microsoft/WindowsServerUpdateServicesConfig/blob/master/WindowsServerUpdateServicesConfig.ps1#L70-L73

The operating system the target node is running

N/A

Version and build of PowerShell the target node is running

Should be running PS 5.1

Version of the DSC module that was used

'UpdateServicesDsc' Version 1.2.1

[UpdateServicesServer] Languages test return false after set

Details of the scenario you tried and the problem that is occurring

The issue seems to happen when I try to put more than one language using a string array. It works fine for one language or "*" but as soon as I use an array with multiple languages the following happens :

  • No matter if the inital test of the ressource is true or false, it will go for the set script (even if languages are already in the desired state, in which case each language can be seen in the verbose log).

  • When the set script is applied, it goes without errors and WSUS configuration is actually changed to the desired language parameter.

  • The final test script returns false in any case, making the whole run return in error.

Verbose logs showing the problem

VERBOSE: [MyServerName]: LCM:  [ Start  Resource ]  [[UpdateServicesServer]WSUS_Service]
VERBOSE: [MyServerName]: LCM:  [ Start  Test     ]  [[UpdateServicesServer]WSUS_Service]
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer is Present
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer configuration
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer subscription
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer SQL Server
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer SQL Server is MICROSOFT##WID
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer content directory
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer content directory is F:\WSUS
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer update improvement program
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer content update improvement program is False
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer upstream server
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer upstream server is upstream.domain.com,
                port 8530, use SSL False, replica True
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer languages
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer languages are fr
en
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer classifications
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer classifications are e6cf1350-c01b-414d-a61f-263d14d133b4 e0789628-ce08-4437-be74-2495b842f43b 0fa1201d-4330-4fa8-8ae9-b877473b6441
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer products
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer products are Office Windows
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer synchronization settings
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer synchronize automatically is True
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer synchronize automatically time of day is 00:00:00
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer number of synchronizations per day is 1
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer client targeting mode is Client
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Languages test failed
VERBOSE: [MyServerName]: LCM:  [ End    Test     ]  [[UpdateServicesServer]WSUS_Service]  in 2.2350 seconds.
VERBOSE: [MyServerName]: LCM:  [ Start  Set      ]  [[UpdateServicesServer]WSUS_Service]
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Configuring WSUS
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Check for previous configuration change
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Configuring WSUS Update Improvement Program
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Configuring WSUS Upstream Server
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Configuring WSUS no proxy server
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Setting WSUS languages
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Setting WSUS products
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Setting WSUS classifications
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Setting WSUS synchronization schedule
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer is Present
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer configuration
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer subscription
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer SQL Server
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer SQL Server is MICROSOFT##WID
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer content directory
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer content directory is F:\WSUS
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer update improvement program
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer content update improvement program is False
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer upstream server
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer upstream server is upstream.domain.com,
                port 8530, use SSL False, replica True
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer languages
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer languages are fr
en
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer classifications
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer classifications are e6cf1350-c01b-414d-a61f-263d14d133b4 e0789628-ce08-4437-be74-2495b842f43b 0fa1201d-4330-4fa8-8ae9-b877473b6441
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer products
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer products are Office Windows
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Getting WSUSServer synchronization settings
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer synchronize automatically is True
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer synchronize automatically time of day is 00:00:00
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer number of synchronizations per day is 1
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] WSUSServer client targeting mode is Client
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Languages test failed
VERBOSE: [MyServerName]:                            [[UpdateServicesServer]WSUS_Service] Test-TargetResouce returned false after calling set. | ErrorType: MSFT_UpdateServicesServer.TestFailedAfterSet
VERBOSE: [MyServerName]: LCM:  [ End    Set      ]  [[UpdateServicesServer]WSUS_Service]  in 0.7030 seconds.
PowerShell DSC resource MSFT_UpdateServicesServer  failed to execute Set-TargetResource functionality with error message: Test-TargetResouce returned false after calling set.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : localhost

Suggested solution to the issue

The DSC configuration that is used to reproduce the issue (as detailed as possible)

UpdateServicesServer "WSUS_Service" {
            Ensure                            = "Present"
            ContentDir                        = "F:\WSUS"
            Languages                         = $Languages  # This is a verified string array
            UpdateImprovementProgram          = $false
            SynchronizeAutomatically          = $true
            SynchronizationsPerDay            = 1
            SynchronizeAutomaticallyTimeOfDay = (New-TimeSpan -Hours 0).ToString()
            UpstreamServerName                = "upstream.domain.com"
            UpstreamServerPort                = 8530
            UpstreamServerReplica             = $true
            DependsOn                         = @("[WindowsFeature]WSUS_Feature", "[File]WSUS_Folder")
        }

In the previous DSC log the desired languages are "fr" and "en".

The operating system the target node is running

OsName               : Microsoft Windows Server 2019 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1809
WindowsBuildLabEx    : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running

Name                           Value
----                           -----
PSVersion                      5.1.17763.771
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.771
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

1.1.0.0

UpdateServicesServer: Null value passed to New-InvalidResultException

Details of the scenario you tried and the problem that is occurring

On line 663 in the Set-TargetResource function, the following call is made:

New-InvalidResultException -Message $errorMessage -ErrorRecord $_

However, unlike previous calls to similar commands (see line 416), this command is not inside a try/catch block. Therefore, the $_ variable is null and the function errors out without detailing the resource failure. Instead, it leads the user on a wild goose chase tracking down $null values. See #58 for an example.

Verbose logs showing the problem

Suggested solution to the issue

Proposals:

  1. Replace $_ with a meaningful value such as "Set-TargetResource has been run. However, the resource is not in the desired state. The following parameters are not set to the desired values: ..."
  2. Remove lines 660-664 altogether, as testing is in its own function

I prefer option 2, as the Set function has already performed its work and the state has already changed. The Unit and Integration tests should be providing feedback as to the effectiveness of the Set function, not the Set function itself. If, on subsequent execution of the configuration block, the test continues to fail and Set-TargetResource continues to be called, then an issue with the Set-TargetResource function should be filed and addressed.

Additionally, Issues #45 and #47 are related to apparent false negatives related to the Set-TargetResource calling Test-TargetResource

The DSC configuration that is used to reproduce the issue (as detailed as possible)

See #58

The operating system the target node is running

See #58

Version and build of PowerShell the target node is running

Version of the DSC module that was used

v1.2.1

UpdateServicesServer - Download Properties

Description

The current interface doesn't allow the Download Properties to be set. It so happens that the defaults work correctly but since these settings are critical to our image build process, they should be strictly defined - any in any case, other users may have different requirements.

Proposed properties

  • HostBinariesOnMicrosoftUpdate (Default: False)
  • DownloadExpressPackages (Default: False)
  • DownloadUpdateBinariesAsNeeded: (Default: True)

These are equivalent to the following Powershell properties:

(Get-WsusServer).GetConfiguration().HostBinariesOnMicrosoftUpdate
(Get-WsusServer).GetConfiguration().DownloadExpressPackages 
(Get-WsusServer).GetConfiguration().DownloadUpdateBinariesAsNeeded

Special considerations or limitations

UpdateServicesServer unable to handle duplicate product name values

Details of the scenario you tried and the problem that is occurring

Loading new products into an array under "UpdateServicesServer" DSC resource has failed due to WSUS now containing multiple product titles with the same name.

Verbose logs showing the problem

ERROR - An error occurred running method 'Set' in resource 'UpdateServicesServer' for resourceID '[UpdateServicesServer]UpdateServices': System.Management.Automation.MethodException: Cannot find an overload for "GetUpdateCategory" and the argument count: "1".

Suggested solution to the issue

Modify this code block to handle product names with the same title Code Reference

The DSC configuration that is used to reproduce the issue (as detailed as possible)

Not sharing the DSC configuration, since it's an array of products. But here is the example of multiple products returned from the $AllWsusProducts = $WsusServer.GetUpdateCategories() line that is pulling duplicate product titles.

Title                                                                               Description
-----                                                                               -----------
Windows Server 2016                                                                 Windows 10 Server
Windows Server 2016                                                                 Windows Server 2016
Windows Server 2019 and later, Servicing Drivers                                    Windows Server 2019 and later, Servicing Drivers
Windows Server 2019 and later, Upgrade & Servicing Drivers                          Windows Server 2019 and later, Upgrade & Servicing Drivers
Windows Server 2019 Datacenter: Azure Edition Hotpatch                              Windows Server 2019 Datacenter: Azure Edition
Windows Server 2019                                                                 Category for Windows Server 2019
Windows Server 2019                                                                 Windows Server 2019 (RS5 Server) and above

The operating system the target node is running

OsName               : Microsoft Windows Server 2019 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1809
WindowsBuildLabEx    : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running

Name                           Value
----                           -----
PSVersion                      5.1.17763.1490
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.1490
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Version of the DSC module that was used

1.2.0

UpdateServicesDsc - Email

The Email settings are missing:
example:

EmailNotifySmtpServer [string]
EmailNotifySmtpPort [int]
EmailNotifySmtpSenderName [string]
EmailNotifySmtpSenderEmail [string]
EmailNotifyWhenNewUpdatesAreSync [boolean]
EmailNotifyWhenNewUpdatesAreSyncRecipients [string[]]
EmailNotifySendStatusReports [boolean]
EmailNotifySendStatusReportsFrecuency
EmailNotifySendStatusReportsTime[string]
EmailNotifySendStatusReportsRecipients [string[]]

email - general
emailserverfields

WSUS Cleanup task is defined with incorrect script block

There is a bug in definition of scheduled task:

https://github.com/mgreenegit/UpdateServicesDsc/blob/889f186172d10a57e23f3473a2016ddfb569d6e6/DSCResources/MSFT_UpdateServicesCleanup/MSFT_UpdateServicesCleanup.psm1#L188-L197

Some of the variables in that block are escaped resulting in:

$true;$CleanupUnneededContentFiles = $true;$CleanupLocalPublishedContentFiles = $true; = Get-WsusServer                              
if()                                                                                                                                 
{                                                                                                                                    
    'WSUS Server found...' | Out-File (Join-Path -Path ([IO.Path]::GetTempPath()) -ChildPath 'WsusCleanup.txt') -Append              
     = $WsusServer.GetCleanupManager()                                                                                               
    if()                                                                                                                             
    {                                                                                                                                
        'WSUS Cleanup Manager found...' | Out-File (Join-Path -Path ([IO.Path]::GetTempPath()) -ChildPath 'WsusCleanup.txt') -Append 
         = New-Object Microsoft.UpdateServices.Administration.CleanupScope(True,True,True,True,True,True,True)                       
         = .PerformCleanup()                                                                                                         
        if()                                                                                                                         
        {                                                                                                                            
         | Out-File (Join-Path -Path ([IO.Path]::GetTempPath()) -ChildPath 'WsusCleanup.txt') -Append                                
        }                                                                                                                            
    }                                                                                                                                
}                                                                                                                                    

Also: having an argument like that makes it hard to maintain. Perhaps generate a script instead and call it with -file parameter?

[UpdateServicesServer] Upstream Server triggers reconfigure when not specified

Details of the scenario you tried and the problem that is occurring

Configured WSUS using DSC. SCCM then used the configured instance, and set the Upstream Server. Expected that DSC would ignore this as the option is not specified in the declared configuration. Found that DSC performed a reconfigure of WSUS back to Microsoft Update. SCCM then reconfigured again, and we went round in a circle.

Verbose logs showing the problem

[[UpdateServicesServer]SccmCasHa-WsusConfig::[SccmCasHa]xSccmCasHa] Upstream Server Name test failed

Suggested solution to the issue

Only return $false from Test Resource if the Upstream Server Name does not match the current server name, and the UpstreamServerName option has been specified in the declared configuration.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

    UpdateServicesServer SccmCasHa-WsusConfig {
        Ensure = "Present"
        ContentDir = $WsusContentDir
        SqlServer = $WsusSqlInstance
        SetupCredential = $WsusSqlInstanceAdmin
        UpdateImprovementProgram = $false
        DependsOn = @(
            "[WindowsFeature]SccmCasHa-WsusServicesSql",
            "[WindowsFeature]SccmCasHa-WsusServices"
        )
    }

The operating system the target node is running

OsName : Microsoft Windows Server 2016 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture : 64-bit
WindowsBuildLabEx : 14393.3630.amd64fre.rs1_release.200407-1730
OsLanguage : en-US
OsMuiLanguages : {en-US}

Version and build of PowerShell the target node is running

Name Value


PSVersion 5.1.14393.3471
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.3471
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Version of the DSC module that was used

1.2.1

UpdateServicesServer: Verbose output broken for Languages

Details of the scenario you tried and the problem that is occurring

Verbose output of Languages property is broken in Test-TargetResource, it returns System.Collections.Specialized.StringCollection instead of list of languages

Verbose logs showing the problem

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Mi
crosoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer SRV1 with user sid S-1-5-21-2574420874-2490326428-1586090461-500.
VERBOSE: [SRV1]: LCM:  [ Start  Set      ]
VERBOSE: [SRV1]: LCM:  [ Start  Resource ]  [[UpdateServicesServer]WSUS]
VERBOSE: [SRV1]: LCM:  [ Start  Test     ]  [[UpdateServicesServer]WSUS]
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUS server.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS server is Present.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUS server configuration.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WUSS server subscription.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUS SQL server.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server SQL Server is MICROSOFT##WID.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUSServer content directory.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server content directory is E:\.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUSServer update improvement program.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server content update improvement program is False.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUS Server languages.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server languages are System.Collections.Specialized.StringCollection.

...

Suggested solution to the issue

Write-Verbose -Message $script:localizedData.GettingWsusLanguage
if ($WsusConfiguration.AllUpdateLanguagesEnabled)
{
$Languages = @('*')
}
else
{
$Languages = $WsusConfiguration.GetEnabledUpdateLanguages()
}
Write-Verbose -Message ($script:localizedData.WsusLanguages -f $Languages)

Adjust line 124 to:

$Languages = ($WsusConfiguration.GetEnabledUpdateLanguages()) -join ','

...to transform the string collection into a simple string.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

Configuration WSUSProduct {
    Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
    Import-DscResource -ModuleName 'UpdateServicesDsc' -ModuleVersion 1.2.1
    
    Node localhost {
 
        UpdateServicesServer WSUS {
            Ensure = 'Present'
            Languages = 'en'
            Products = 'Windows Server 2016'
        }
    }
}

The operating system the target node is running

OsName               : Microsoft Windows Server 2019 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1809
WindowsBuildLabEx    : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running

Name                           Value                                                                                                                                                    
----                           -----                                                                                                                                                    
PSVersion                      5.1.17763.1490                                                                                                                                           
PSEdition                      Desktop                                                                                                                                                  
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                  
BuildVersion                   10.0.17763.1490                                                                                                                                          
CLRVersion                     4.0.30319.42000                                                                                                                                          
WSManStackVersion              3.0                                                                                                                                                      
PSRemotingProtocolVersion      2.3                                                                                                                                                      
SerializationVersion           1.1.0.1 

Version of the DSC module that was used

Name              Version Path                                                                                       
----              ------- ----                                                                                       
UpdateServicesDsc 1.2.1   C:\Program Files\WindowsPowerShell\Modules\UpdateServicesDsc\1.2.1\UpdateServicesDsc.psd1

UpdateServicesServer - Languages

The Languages field is unable to handle multiple languages when configuring WSUS.
The code sample at the bottom of this issue causes the following error to be returned:
failed to execute Set-TargetResource functionality with error message: Test-TargetResouce returned false after calling set

Have done some investigation of this with @RandomNoun7 and will submit a PR shortly to address it.

Multiple languages (e.g. "en","ja","fr") are being set correctly, but the subsequent test fails to validate the setting because of a data mismatch in the comparison which causes the language test to fail if more than one language is set.

The code sample that demonstrates this fault is below:

$script:ErrorActionPreference = 'Stop'
$script:WarningPreference     = 'SilentlyContinue'

function new-pscredential{
  [CmdletBinding()]
  param (
    [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
    [string]$user,
    [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
    [string]$password
  )

  $secpasswd   = ConvertTo-SecureString $password -AsPlainText -Force
  $credentials = New-Object System.Management.Automation.PSCredential ($user, $secpasswd)
  return $credentials
}

$response = @{
  indesiredstate = $false
  rebootrequired = $false
  errormessage   = ''
}

$invokeParams = @{
Name       = 'UpdateServicesServer'
ModuleName = 'UpdateServicesDsc'
Method     = 'set'
Property   = @{
'ensure' = 'present';
'contentdir' = 'C:\WSUS';
'languages' = @('en', 'fr', 'ja');
'products' = @('Windows 10 LTSB', 'Windows 10', 'Windows 7', 'Windows 8.1', 'Windows 8', 'Windows Server 2008 R2', 'Windows Server 2008', 'Windows Server 2012 R2', 'Windows Server 2012', 'Windows Server 2016', 'Windows Server 2019');
'classifications' = @('E6CF1350-C01B-414D-A61F-263D14D133B4', 'E0789628-CE08-4437-BE74-2495B842F43B', '0FA1201D-4330-4FA8-8AE9-B877473B6441', '68C5B0A3-D1A6-4553-AE49-01D3A7827828', '28BC880E-0592-4CBF-8F95-C79B17911D5F');
'synchronizeautomatically' = $true;
'synchronizeautomaticallytimeofday' = '15:30:00'
}
}

try{
  $result = Invoke-DscResource @invokeParams
}catch{
  $response.errormessage = $_.Exception.Message
  return ($response | ConvertTo-Json -Compress)
}

# keep the switch for when Test passes back changed properties
switch($invokeParams.Method){
  'Test'{
    $response.indesiredstate = $result.InDesiredState
    return ($response | ConvertTo-Json -Compress)
  }
  'Set'{
    $response.indesiredstate = $true
    $response.rebootrequired = $result.RebootRequired
    return ($response | ConvertTo-Json -Compress)
  }
}

[UpdateServicesServer] Products test return false after set

Details of the scenario you tried and the problem that is occurring

Some Wsus products have non ASCII characters in their Title. In particular "Windows Server Manager โ€“ Windows Server Update Services (WSUS) Dynamic Installer" dash (" - ") is not in ASCII format therefore comparison is failing subsequently test and set is failing.

Verbose logs showing the problem

Suggested solution to the issue

Suggested solution to strip all none alphanumerical characters using this method: ToCharArray().Where{ $_ -imatch "[a-z0-9]" } -join '' i.e. like this:

foreach ($Product in $Products) {
                   # Due to none ASCII characters used in Product titles in particular "Windows Server Manager โ€“ Windows Server Update Services (WSUS) Dynamic Installer" dash (" - ") is not in ASCII format
                   # had to strip all none alphanumerical characters to compare the titles. to do so used this method: ToCharArray().Where{ $_ -imatch "[a-z0-9]" } -join '' 
                   if ($WsusProduct = $AllWsusProducts | Where-Object { ($_.Title.ToCharArray().Where{ $_ -imatch "[a-z0-9]" } -join '') -eq ($Product.ToCharArray().Where{ $_ -imatch "[a-z0-9]" } -join '') }) {
                       Write-Verbose "Setting WSUS Product: $($Product)"
                       $null = $ProductCollection.Add($WsusServer.GetUpdateCategory($WsusProduct.Id))
                   }
               }

The DSC configuration that is used to reproduce the issue (as detailed as possible)

products                          = @(
            'ASP.NET Web and Data Frameworks'
            'ASP.NET Web Frameworks'
            'Azure File Sync agent updates for Windows Server 2016'
            'Windows Server 2016 and Later Servicing Drivers'
            'Windows Server 2016'
            'Windows Server Manager - Windows Server Update Services (WSUS) Dynamic Installer'
        )

The operating system the target node is running

Version and build of PowerShell the target node is running

Version of the DSC module that was used ('dev' if using current dev branch)

master branch
version: 1.1.0.0

UpdateServicesServer: Products fails for "Windows Admin Center"

Details of the scenario you tried and the problem that is occurring

The UpdateServicesServer resource fails to configure Products when there are multiple entries returned for a given name (e.g. "Windows Admin Center" is a Product Family as well as Product):

$WsusServer = Get-WsusServer
$AllWsusProducts = $WsusServer.GetUpdateCategories()
$ProductCollection = New-Object Microsoft.UpdateServices.Administration.UpdateCategoryCollection
$Product = 'Windows Admin Center'
$WsusProduct = $AllWsusProducts | Where-Object -FilterScript { $_.Title -eq $Product }

# WsusProduct now contains 2 members:
$WsusProduct


Type                      : ProductFamily
ProhibitsSubcategories    : False
ProhibitsUpdates          : True
UpdateSource              : MicrosoftUpdate
UpdateServer              : Microsoft.UpdateServices.Internal.BaseApi.UpdateServer
Id                        : a871ee2d-7499-6719-3781-8c63a1642990
Title                     : Windows Admin Center
Description               : Product Family for Windows Admin Center
ReleaseNotes              : 
DefaultPropertiesLanguage : 
DisplayOrder              : 2147483647
ArrivalDate               : 2/12/2021 4:37:45 PM

Type                      : Product
ProhibitsSubcategories    : True
ProhibitsUpdates          : False
UpdateSource              : MicrosoftUpdate
UpdateServer              : Microsoft.UpdateServices.Internal.BaseApi.UpdateServer
Id                        : b1b8f641-1ff2-4ae6-b247-4fe7503787be
Title                     : Windows Admin Center
Description               : Windows Admin Center
ReleaseNotes              : 
DefaultPropertiesLanguage : 
DisplayOrder              : 2147483647
ArrivalDate               : 2/12/2021 4:37:45 PM

This causes the following code to fail:

if ($WsusProduct = $AllWsusProducts | Where-Object -FilterScript { $_.Title -eq $Product })
{
$null = $ProductCollection.Add($WsusServer.GetUpdateCategory($WsusProduct.Id))
}

$null = $ProductCollection.Add($WsusServer.GetUpdateCategory($WsusProduct.Id))

Cannot find an overload for "GetUpdateCategory" and the argument count: "1".
At line:1 char:1
+ $null = $ProductCollection.Add($WsusServer.GetUpdateCategory($WsusPro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Verbose logs showing the problem

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Mi
crosoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer SRV1 with user sid S-1-5-21-2574420874-2490326428-1586090461-500.
VERBOSE: [SRV1]: LCM:  [ Start  Set      ]
VERBOSE: [SRV1]: LCM:  [ Start  Resource ]  [[UpdateServicesServer]WSUS]
VERBOSE: [SRV1]: LCM:  [ Start  Test     ]  [[UpdateServicesServer]WSUS]
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUS server.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS server is Present.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUS server configuration.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WUSS server subscription.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUS SQL server.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server SQL Server is MICROSOFT##WID.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUSServer content directory.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server content directory is E:\.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUSServer update improvement program.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server content update improvement program is False.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUS Server languages.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server languages are System.Collections.Specialized.StringCollection.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUS Server Classifications.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server Classifications are e6cf1350-c01b-414d-a61f-263d14d133b4.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUS Server products.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server products are Windows Server 2016.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUSServer synchronization settings.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server synchronize automatically is False.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server synchronize automatically time of day is 06:33:59.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUSServer number of synchronizations per day is 1.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUSServer client targeting mode is Server.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Products test failed.
VERBOSE: [SRV1]: LCM:  [ End    Test     ]  [[UpdateServicesServer]WSUS]  in 1.4690 seconds.
VERBOSE: [SRV1]: LCM:  [ Start  Set      ]  [[UpdateServicesServer]WSUS]
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Configuring Wsus.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Check for previous configuration change.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Configuring WSUS Update Improvement Program.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Configuring WSUS for Microsoft Update.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Configuring WSUS no proxy server.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Setting WSUS languages.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Setting WSUS products.
Cannot find an overload for "GetUpdateCategory" and the argument count: "1".
    + CategoryInfo          : NotSpecified: (:) [], CimException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest
    + PSComputerName        : localhost
 
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Setting WSUS classifications.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Setting WSUS synchronization schedule.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUS server.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS server is Present.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUS server configuration.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WUSS server subscription.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUS SQL server.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server SQL Server is MICROSOFT##WID.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUSServer content directory.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server content directory is E:\.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUSServer update improvement program.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server content update improvement program is False.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUS Server languages.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server languages are System.Collections.Specialized.StringCollection.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUS Server Classifications.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server Classifications are e6cf1350-c01b-414d-a61f-263d14d133b4.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUS Server products.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server products are *.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Getting WSUSServer synchronization settings.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server synchronize automatically is False.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUS Server synchronize automatically time of day is 06:33:59.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUSServer number of synchronizations per day is 1.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] WSUSServer client targeting mode is Server.
VERBOSE: [SRV1]:                            [[UpdateServicesServer]WSUS] Products test failed.
Cannot validate argument on parameter 'ErrorRecord'. The argument is null. Provide a valid value for the argument, and then try running the command again.
    + CategoryInfo          : InvalidData: (:) [], CimException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,New-InvalidResultException
    + PSComputerName        : localhost
 
VERBOSE: [SRV1]: LCM:  [ End    Set      ]  [[UpdateServicesServer]WSUS]  in 0.6250 seconds.
The PowerShell DSC resource '[UpdateServicesServer]WSUS' with SourceInfo '::7::9::UpdateServicesServer' threw one or more non-terminating errors while running the Set-TargetResource 
functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : NonTerminatingErrorFromProvider
    + PSComputerName        : localhost
 
VERBOSE: [SRV1]: LCM:  [ End    Set      ]
The SendConfigurationApply function did not succeed.
    + CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : MI RESULT 1
    + PSComputerName        : localhost
 
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 2.749 seconds

Suggested solution to the issue

Adjust the code to process multiple entries in $WsusProduct separately:

            if ($WsusProduct = $AllWsusProducts | Where-Object -FilterScript { $_.Title -eq $Product })
            {
                $WsusProduct | Foreach-Object -Process {
                    $null = $ProductCollection.Add($_)
                }
            }

Similar change would likely be needed as part of solution to #13

The DSC configuration that is used to reproduce the issue (as detailed as possible)

Configuration WSUSProduct {
    Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
    Import-DscResource -ModuleName 'UpdateServicesDsc' -ModuleVersion 1.2.1
    
    Node localhost {

        UpdateServicesServer WSUS {
            Ensure = 'Present'
            Languages = 'en'
            Products = 'Windows Admin Center'
        }
    }
}

The operating system the target node is running

OsName               : Microsoft Windows Server 2019 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1809
WindowsBuildLabEx    : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running

Name                           Value                                                                                                                                                    
----                           -----                                                                                                                                                    
PSVersion                      5.1.17763.1490                                                                                                                                           
PSEdition                      Desktop                                                                                                                                                  
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                  
BuildVersion                   10.0.17763.1490                                                                                                                                          
CLRVersion                     4.0.30319.42000                                                                                                                                          
WSManStackVersion              3.0                                                                                                                                                      
PSRemotingProtocolVersion      2.3                                                                                                                                                      
SerializationVersion           1.1.0.1                                                                                                                                                  

Version of the DSC module that was used

Name              Version Path                                                                                       
----              ------- ----                                                                                       
UpdateServicesDsc 1.2.1   C:\Program Files\WindowsPowerShell\Modules\UpdateServicesDsc\1.2.1\UpdateServicesDsc.psd1

Parameterize WSUS Cleanup Task name

Would it be possible to make the task name for the Scheduled WSUS cleanup a parameter instead of a hardcoded value of 'WSUS Cleanup'? This way, the cleanup job can be broken out into multiple tasks, if desired.

(I personally structure my WSUS Cleanup into three jobs: Decline, Delete DB, and Delete Files. It minimizes the timeouts that way)

Feature Request - Post Install

It would be great to be able to have the post install feature in desired state. Currently using the dirty DSC script resource below to do the job.

Script WSUSPostInstall 
{
    DependsOn = '[File]WSUSContentDirectory'
    GetScript = {
        @{
            GetScript = $GetScript
            SetScript = $SetScript
            TestScript = $TestScript
            Result = ($null -ne (Get-Website -Name 'WSUS Administration') -and (Test-Path -Path "$($Using:Node.ServicesVolume)\WSUS\WsusContent\anonymousCheckFile.txt"))
        }           
    }

    SetScript = {
        & 'C:\Program Files\Update Services\Tools\WsusUtil.exe' postinstall CONTENT_DIR=$($Using:Node.ServicesVolume)\WSUS
    }

    TestScript = {
        $Status = ($null -ne (Get-Website -Name 'WSUS Administration') -and (Test-Path -Path "$($Using:Node.ServicesVolume)\WSUS\WsusContent\anonymousCheckFile.txt"))
        $Status -eq $True
    }
}

UpdateServicesServer - Products

As an example i'm trying to update all SQL servers using Update Services
I will need to create a list like this

Microsoft SQL Server 2008 R2 - PowerPivot for Microsoft Excel 2010
Microsoft SQL Server 2012
Microsoft SQL Server 2014
Microsoft SQL Server 2016
Microsoft SQL Server PowerPivot for Excel
SQL Server 2000
SQL Server 2005
SQL Server 2008 R2
SQL Server 2008
SQL Server 2012 Product Updates for Setup
SQL Server 2014-2016 Product Updates for Setup
SQL Server Feature Pack
SQL Server

if($WsusProduct = $AllWsusProducts | Where-Object {$_.Title -eq $Product})

If the above like could be changes to

if($WsusProduct = $AllWsusProducts | Where-Object {$_.Title -like $Product})

it will allow me to do just the following keyword "SQL Server"

Add Examples

Examples should be added to show how to use the resources.

UpdateServicesServer: Incorrect Type for Language in return value for Get-TargetResource

Details of the scenario you tried and the problem that is occurring

Assuming the current state config of WSUS server:

 Name                           Value                                                                                                                                                                                                                
----                           -----                                                                                                                                                                                                                
Products                       {Office, Windows}                                                                                                                                                                                                    
UpstreamServerSSL                                                                                                                                                                                                                                   
SynchronizeAutomatically       True                                                                                                                                                                                                                 
ContentDir                     C:\WSUS                                                                                                                                                                                                              
UpstreamServerName                                                                                                                                                                                                                                  
UpstreamServerReplica                                                                                                                                                                                                                               
SynchronizationsPerDay         1                                                                                                                                                                                                                    
UpstreamServerPort                                                                                                                                                                                                                                  
ProxyServerBasicAuthentication                                                                                                                                                                                                                      
Ensure                         Present                                                                                                                                                                                                              
Classifications                {e6cf1350-c01b-414d-a61f-263d14d133b4, e0789628-ce08-4437-be74-2495b842f43b}                                                                                                                                         
ProxyServerName                                                                                                                                                                                                                                     
SQLServer                      MICROSOFT##WID                                                                                                                                                                                                       
Languages                      {fr, en}                                                                                                                                                                                                             
ProxyServerPort                                                                                                                                                                                                                                     
UpdateImprovementProgram       False                                                                                                                                                                                                                
ClientTargetingMode            Client                                                                                                                                                                                                               
SynchronizeAutomaticallyTim... 21:00:00                                                                                                                                                                                                             
ProxyServerCredentialUsername   

When running the following code:

 $InvokeParams = @{Name = 'UpdateServicesServer'; Method = 'get'; Property = @{ensure = 'present' }; ModuleName = @{ModuleName = 'C:/Program Files/WindowsPowerShell/Modules/UpdateServicesDsc/1.2.1/UpdateServicesDsc.psd1'; RequiredVersion = '1.2.1' } }

$Result = Invoke-DscResource @InvokeParams -Verbose

$Result 

An error comes up as follows

 A general error occurred that is not covered by a more specific error code.
    + CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : MI RESULT 1
    + PSComputerName        : localhost 

It was identified that the issue was due to the return value for the language being of type StringCollection rather than String[] as per the schema for the UpdateServicesServer resource:

[Write, Description("Update languages, * for all.")] String Languages[]; 

But the current return value is equivalent to the following:

 PS C:\Users\Administrator> (Get-WsusServer).GetConfiguration().GetEnabledUpdateLanguages().GetType()

IsPublic IsSerial Name                                     BaseType                                                                                                                                                                                 
-------- -------- ----                                     --------                                                                                                                                                                                 
True     True     StringCollection                         System.Object    

Verbose logs showing the problem

  VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = Resourceget,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer EC2AMAZ-DUA1E4V with user sid S-1-5-21-2052935279-2926737905-346181576-500.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] Getting WSUS server.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] WSUS server is Present.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] Getting WSUS server configuration.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] Getting WUSS server subscription.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] Getting WSUS SQL server.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] WSUS Server SQL Server is MICROSOFT##WID.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] Getting WSUSServer content directory.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] WSUS Server content directory is C:\WSUS.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] Getting WSUSServer update improvement program.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] WSUS Server content update improvement program is False.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] Getting WSUS Server languages.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] WSUS Server languages are System.Collections.Specialized.StringCollection.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] Getting WSUS Server Classifications.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] WSUS Server Classifications are e6cf1350-c01b-414d-a61f-263d14d133b4.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] Getting WSUS Server products.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] WSUS Server products are Office.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] Getting WSUSServer synchronization settings.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] WSUS Server synchronize automatically is True.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] WSUS Server synchronize automatically time of day is 21:00:00.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] WSUSServer number of synchronizations per day is 1.
VERBOSE: [EC2AMAZ-DUA1E4V]:                            [[UpdateServicesServer]DirectResourceAccess] WSUSServer client targeting mode is Client.
A general error occurred that is not covered by a more specific error code.
    + CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : MI RESULT 1
    + PSComputerName        : localhost
 
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 3.862 seconds 

Suggested solution to the issue

The DSC configuration that is used to reproduce the issue (as detailed as possible)

The following code in the function Get-TargetResource has been found to be the cause of the issue:

if ($WsusConfiguration.AllUpdateLanguagesEnabled)
{
  $Languages = @('*')
}
else
{
  $Languages = $WsusConfiguration.GetEnabledUpdateLanguages()
}

Write-Verbose -Message ($script:localizedData.WsusLanguages -f $Languages) 

The suggested fix to the issue is as follows:

if ($WsusConfiguration.AllUpdateLanguagesEnabled)
{
  $Languages = @('*')
}
else
{
  $Languages = [String[]]$WsusConfiguration.GetEnabledUpdateLanguages()
}

Write-Verbose -Message ($script:localizedData.WsusLanguages -f ($Languages -join ',')) 

The operating system the target node is running

OsName               : Microsoft Windows Server 2019 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1809
WindowsBuildLabEx    : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage           : en-US
OsMuiLanguages       : {en-US} 

Version and build of PowerShell the target node is running

 Name                           Value                                                                                                                                                                                                                
----                           -----                                                                                                                                                                                                                
PSVersion                      5.1.17763.3770                                                                                                                                                                                                       
PSEdition                      Desktop                                                                                                                                                                                                              
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                                              
BuildVersion                   10.0.17763.3770                                                                                                                                                                                                      
CLRVersion                     4.0.30319.42000                                                                                                                                                                                                      
WSManStackVersion              3.0                                                                                                                                                                                                                  
PSRemotingProtocolVersion      2.3                                                                                                                                                                                                                  
SerializationVersion           1.1.0.1  

Version of the DSC module that was used

 Name              Version Path                                                                                     
----              ------- ----                                                                                     
UpdateServicesDsc 1.2.1   C:\Program Files\WindowsPowerShell\Modules\UpdateServicesDsc\1.2.1\UpdateServicesDsc.psd1 

UpdateServicesApprovalRule: Broken verbose output

Details of the scenario you tried and the problem that is occurring

Verbose output of Get-TargetResource returns Microsoft.UpdateServices.Internal.BaseApi.UpdateServer instead of WSUS server name

Verbose logs showing the problem

VERBOSE: [SRV1]: LCM:  [ Start  Resource ]  [[UpdateServicesApprovalRule]Approval]
VERBOSE: [SRV1]: LCM:  [ Start  Test     ]  [[UpdateServicesApprovalRule]Approval]
VERBOSE: [SRV1]:                            [[UpdateServicesApprovalRule]Approval] Identified WSUS server information: Microsoft.UpdateServices.Internal.BaseApi.UpdateServer
VERBOSE: [SRV1]: LCM:  [ End    Test     ]  [[UpdateServicesApprovalRule]Approval]  in 0.0470 seconds.
VERBOSE: [SRV1]: LCM:  [ Skip   Set      ]  [[UpdateServicesApprovalRule]Approval]
VERBOSE: [SRV1]: LCM:  [ End    Resource ]  [[UpdateServicesApprovalRule]Approval]

Suggested solution to the issue

Write-Verbose -Message ('Identified WSUS server information: {0}' -f $WsusServer)

Change the line to:

Write-Verbose -Message ('Identified WSUS server information: {0}' -f $WsusServer.Name)

The DSC configuration that is used to reproduce the issue (as detailed as possible)

Configuration WSUSProduct {
    Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
    Import-DscResource -ModuleName 'UpdateServicesDsc' -ModuleVersion 1.2.1
    
    Node localhost {

        UpdateServicesApprovalRule Approval {
            Ensure = 'Present'
            Name = 'Test Approval Rule'
            Classifications = @(
                # Updates
                'cd5ffd1e-e932-4e3a-bf74-18bf0b1bbd83'
            )
            Products = 'Windows Server 2016'
            ComputerGroups = 'All Computers'
            Enabled = $true
        }
    }
}

The operating system the target node is running

OsName               : Microsoft Windows Server 2019 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1809
WindowsBuildLabEx    : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running

Name                           Value                                                                                                                                                    
----                           -----                                                                                                                                                    
PSVersion                      5.1.17763.1490                                                                                                                                           
PSEdition                      Desktop                                                                                                                                                  
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                  
BuildVersion                   10.0.17763.1490                                                                                                                                          
CLRVersion                     4.0.30319.42000                                                                                                                                          
WSManStackVersion              3.0                                                                                                                                                      
PSRemotingProtocolVersion      2.3                                                                                                                                                      
SerializationVersion           1.1.0.1 

Version of the DSC module that was used

Name              Version Path                                                                                       
----              ------- ----                                                                                       
UpdateServicesDsc 1.2.1   C:\Program Files\WindowsPowerShell\Modules\UpdateServicesDsc\1.2.1\UpdateServicesDsc.psd1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.