From 83d3b36bf78117c2faebf5e04cbf06426c79c7a4 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Mon, 27 Apr 2020 16:00:19 +1200 Subject: [PATCH 01/23] Fix Issue #324 and #325 --- CHANGELOG.md | 448 +++++++++++++++++++++++++++++++++++++++++ HISTORIC_CHANGELOG.md | 451 ------------------------------------------ RequiredModules.psd1 | 2 +- azure-pipelines.yml | 4 +- 4 files changed, 451 insertions(+), 454 deletions(-) delete mode 100644 HISTORIC_CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 383b2afc..9698cf11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ```powershell .\build.ps1 -Tasks test -PesterScript 'tests/Integration' -CodeCoverageThreshold 0 ``` +- Change Azure DevOps Pipeline definition to include `source/*` - Fixes [Issue #324](https://github.com/dsccommunity/ComputerManagementDsc/issues/324). +- Updated pipeline to use `latest` version of `ModuleBuilder` - Fixes [Issue #324](https://github.com/dsccommunity/ComputerManagementDsc/issues/324). +- Merge `HISTORIC_CHANGELOG.md` into `CHANGELOG.md` - Fixes [Issue #325](https://github.com/dsccommunity/ComputerManagementDsc/issues/325). ### Fixed @@ -73,3 +76,448 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security - None + +## [7.1.0.0] - 2019-10-30 + +### Changed + +- ComputerManagementDsc: + - Update psd1 description - Fixes [Issue #269](https://github.com/dsccommunity/ComputerManagementDsc/issues/269). +- Fix minor style issues with missing spaces between `param` statements and '('. +- SmbServerConfiguration: + - New resource for configuring the SMB Server settings. + - Added examples for SMB Server Configuration. +- Minor corrections to CHANGELOG.MD. +- ScheduledTask: + - Fixed bug when description has any form of whitespace at beginning or + end the resource would not go into state - Fixes [Issue #258](https://github.com/dsccommunity/ComputerManagementDsc/issues/258). +- SmbShare: + - Fixed bug where the resource would not update the path of a share if the + share exists on a different path. Adds a parameter Force to the SmbShare + resource to allow updating of the path - Fixes [Issue #215](https://github.com/dsccommunity/ComputerManagementDsc/issues/215) + - Removal of duplicate code in Add-SmbShareAccessPermission helper function + fixes [Issue #226](https://github.com/dsccommunity/ComputerManagementDsc/issues/226). + +## [7.0.0.0] - 2019-09-19 + +### Changed + +- ScheduledTask: + - Better compatibility with Group LogonType + when passing BuiltIn groups through ExecuteAsCredential + - Primary use case is 'BUILTIN\Users' + - Use the ExecuteAsCredential property to pass the username + The PSCredential needs a non-null that is ignored + - Delay property not handled properly on AtLogon and AtStartup trigger - Fixes + [Issue #230](https://github.com/dsccommunity/ComputerManagementDsc/issues/230). + - Changed `Get-ScheduledTask` calls to `ScheduledTasks\Get-ScheduledTask` to + avoid name clash with `Carbon` module. Fixes [Issue #248](https://github.com/dsccommunity/ComputerManagementDsc/issues/248). + - Cast `MultipleInstances` value returned by `Get-TargetResource` to `string` - + fixes [Issue #255](https://github.com/dsccommunity/ComputerManagementDsc/issues/255). +- PendingReboot: + - Migrated xPendingReboot from [xPendingReboot](https://github.com/PowerShell/xPendingReboot) + and renamed to PendingReboot. + - Converted to meet HQRM guidelines - Fixes [Issue #12](https://github.com/PowerShell/xPendingReboot/issues/12). + - Changed `SkipCcmClientSDK` parameter to default to `$true` - Fixes [Issue #13](https://github.com/PowerShell/xPendingReboot/issues/13). + - Fixed `Test-TargetResource` so that if ConfigMgr requires a reboot then + the pending reboot will be set - Fixes [Issue #26](https://github.com/PowerShell/xPendingReboot/issues/26). + - Refactored `Test-TargetResource` to reduce code duplication and move to a + data driven design. + - Refactored `Get-TargetResource` by adding a new function `Get-PendingRebootState` + so that `Test-TargetResource` no longer needed to use `Get-TargetResource`. This + eliminated the need to include write parameters in `Get-TargetResource`. + - Converted the call to `Invoke-WmiMethod` to `Invoke-CimMethod`. + - Deleted the code that removes the `regRebootLocations` variable at the end of + the resource as it appears to serve no purpose. +- Correct all tests to meet Pester 4.0 standards. +- RemoteDesktopAdmin: + - New resource for configuring Remote Desktop for Administration - fixes + [Issue #224](https://github.com/dsccommunity/ComputerManagementDsc/issues/224). +- Updated common function `Test-DscParameterState` to support ordered comparison + of arrays by copying function and tests from `NetworkingDsc` - fixes [Issue #250](https://github.com/dsccommunity/ComputerManagementDsc/issues/250). +- BREAKING CHANGE: ScheduledTask: + - Correct output type of `DaysInterval`,`StartTime`,`WeeksDaysOfWeek`, + and `WeeksInterval` parameters from `Get-TargetResource` to match MOF. + - Refactored `Get-TargetResource` to remove parameters that + are not key or required - fixes [Issue #249](https://github.com/dsccommunity/ComputerManagementDsc/issues/249). + - Added function `Test-DateStringContainsTimeZone` to determine if a string + containing a date time includes a time zone. + - Enable verbose preference to be passed through to `Test-DscParameterState`. + - Changed `Test-TargetResource` so that `StartTime` is only compared for + trigger types `Daily`,`Weekly` or `Once`. +- Fix minor style issues in statement case. + +## [6.5.0.0] - 2019-08-08 + +### Changed + +- Computer: + - Fix for 'directory service is busy' error when joining a domain and renaming + a computer when JoinOU is specified - Fixes [Issue #221](https://github.com/dsccommunity/ComputerManagementDsc/issues/221). +- Added new resource SmbShare + - Moved and improved from deprecated module xSmbShare. +- Changes to ComputerManagementDsc.Common + - Updated Test-DscParameterState so it now can compare zero item + collections (arrays). +- Changes to WindowsEventLog + - Minor style guideline cleanup. +- Opt-in to common test to validate localization. Fixed localization strings + in resources - Fixes [Issue #217](https://github.com/dsccommunity/ComputerManagementDsc/issues/217). +- PowerShellExecutionPolicy: + - Removed `SupportsShouldProcess` as it cannot be used with DSC - Fixes + [Issue #219](https://github.com/dsccommunity/ComputerManagementDsc/issues/219). +- Combined all ComputerManagementDsc.ResourceHelper module functions into + ComputerManagementDsc.Common module - Fixes [Issue #218](https://github.com/dsccommunity/ComputerManagementDsc/issues/218). + - Minor code cleanup against style guideline. + - Remove code from `New-InvalidOperationException` because it was a + code path that could never could be used due to the parameter + validation preventing the helper function being called that way. + - Updated all `Get-LocalizationData` to latest version from + [DSCResource.Template](https://github.com/PowerShell/DSCResource.Template). + - Fixed an issue with the helper function `Test-IsNanoServer` that + prevented it to work. Though the helper function is not used, so this + issue was not caught until now when unit tests was added. + - Improved code coverage. + +## [6.4.0.0] - 2019-05-15 + +### Changed + +- ScheduledTask: + - IdleWaitTimeout returned from Get-TargetResource always null - Fixes [Issue #186](https://github.com/dsccommunity/ComputerManagementDsc/issues/186). + - Added BuiltInAccount Property to allow running task as one of the build in + service accounts - Fixes [Issue #130](https://github.com/dsccommunity/ComputerManagementDsc/issues/130). +- Refactored module folder structure to move resource to root folder of + repository and remove test harness - fixes [Issue #188](https://github.com/dsccommunity/ComputerManagementDsc/issues/188). +- Added a CODE\_OF\_CONDUCT.md with the same content as in the README.md and + linked to it from README.MD instead. +- Updated test header for all unit tests to version 1.2.4. +- Updated test header for all integration to version 1.3.3. +- Enabled example publish to PowerShell Gallery by adding `gallery_api` + environment variable to `AppVeyor.yml`. + +## [6.3.0.0] - 2019-04-03 + +### Changed + +- Correct PSSA custom rule violations - fixes [Issue #209](https://github.com/dsccommunity/ComputerManagementDsc/issues/209). +- Correct long example filenames for PowerShellExecutionPolicy examples. +- Opted into Common Tests 'Required Script Analyzer Rules', + 'Flagged Script Analyzer Rules', 'New Error-Level Script Analyzer Rules' + 'Custom Script Analyzer Rules' and 'Relative Path Length' - + fixes [Issue #152](https://github.com/dsccommunity/ComputerManagementDsc/issues/152). +- PowerPlan: + - Added support to specify the desired power plan either as name or guid. + Fixes [Issue #59](https://github.com/dsccommunity/ComputerManagementDsc/issues/59) + - Changed the resource so it uses Windows APIs instead of WMI/CIM + (Workaround for Server 2012R2 Core, Nano Server, Server 2019 and Windows 10). + Fixes [Issue #155](https://github.com/dsccommunity/ComputerManagementDsc/issues/155) + and [Issue #65](https://github.com/dsccommunity/ComputerManagementDsc/issues/65) + +## [6.2.0.0] - 2019-02-20 + +### Changed + +- WindowsEventLog: + - Migrated the xWinEventLog from [xWinEventLog](https://github.com/PowerShell/xWinEventLog) + and renamed to WindowsEventLog. + - Moved strings in localization file. + - LogMode is now set with Limit-EventLog, + - Fixes [Issue #18](https://github.com/dsccommunity/ComputerManagementDsc/issues/18). +- Updated examples to format required for publishing to PowerShell Gallery - fixes + [Issue #206](https://github.com/dsccommunity/ComputerManagementDsc/issues/206). +- Opted into Common Tests 'Validate Example Files To Be Published' and + 'Validate Markdown Links'. + +## [6.1.0.0] - 2019-01-10 + +### Changed + +- Updated LICENSE file to match the Microsoft Open Source Team standard. + Fixes [Issue #197](https://github.com/dsccommunity/ComputerManagementDsc/issues/197). +- Explicitly removed extra hidden files from release package + +## [6.0.0.0] - 2018-10-25 + +### Changed + +- ScheduledTask: + - Added support for Group Managed Service Accounts, implemented using the ExecuteAsGMSA + parameter. Fixes [Issue #111](https://github.com/dsccommunity/ComputerManagementDsc/issues/111) + - Added support to set the Synchronize Across Time Zone option. Fixes [Issue #109](https://github.com/dsccommunity/ComputerManagementDsc/issues/109) +- Added .VSCode settings for applying DSC PSSA rules - fixes [Issue #189](https://github.com/dsccommunity/ComputerManagementDsc/issues/189). +- BREAKING CHANGE: PowerPlan: + - Added IsActive Read-Only Property - Fixes [Issue #171](https://github.com/dsccommunity/ComputerManagementDsc/issues/171). + - InActive power plans are no longer returned with their Name set to null. + Now, the name is always returned and the Read-Only property of IsActive + is set accordingly. + +## [5.2.0.0] - 2018-07-25 + +### Changed + +- PowershellExecutionPolicy: + - Updated to meet HQRM guidelines. + - Migrated the xPowershellExecutionPolicy from [xPowershellExecutionPolicy](https://github.com/PowerShell/xPowerShellExecutionPolicy) + and renamed to PowershellExecutionPolicy. + - Moved strings to localization file. +- Changed the scope from Global to Script in DSC_ScheduledTask.Integration.Tests.ps1 +- Changed the scope from Global to Script ComputerManagementDsc.Common.Tests.ps1 +- ScheduledTask: + - Added support for event based triggers, implemented using the ScheduleType OnEvent + fixes [Issue #167](https://github.com/dsccommunity/ComputerManagementDsc/issues/167) + +## [5.1.0.0] - 2018-06-13 + +### Changed + +- TimeZone: + - Migrated xTimeZone resource from [xTimeZone](https://github.com/PowerShell/xTimeZone) + and renamed to TimeZone - fixes [Issue #157](https://github.com/dsccommunity/ComputerManagementDsc/issues/157). +- Moved Test-Command from ComputerManagementDsc.ResourceHelper to + ComputerManagementDsc.Common module to match what TimeZone requires. + It was not exported in ComputerManagementDsc.ResourceHelper and not + used. +- Add `server` parameter to `Computer` resource - fixes [Issue #161](https://github.com/dsccommunity/ComputerManagementDsc/issues/161) + +## [5.0.0.0] - 2018-05-03 + +### Changed + +- BREAKING CHANGE: + - Renamed ComputerManagement to ComputerManagementDsc - fixes [Issue #119](https://github.com/dsccommunity/ComputerManagementDsc/issues/119). + - Changed all MSFT\_xResourceName to MSFT\_ResourceName. + - Updated DSCResources, Examples, Modules and Tests with new naming. + - Updated Year to 2018 in License and Manifest. + - Updated README.md from xComputerManagement to ComputerManagementDsc. +- OfflineDomainJoin: + - Cleaned up spacing in strings file to make consistent with other + resources. +- VirtualMemory: + - Converted strings to single quotes in integration test. + +## [4.1.0.0] - 2018-03-22 + +### Changed + +- xScheduledTask: + - Update existing Scheduled Task using SetScheduleTask + instead of UnRegister/Register - See [Issue #134](https://github.com/PowerShell/xComputerManagement/issues/134). +- Fix master branch AppVeyor badge link URL in README.MD - See [Issue #140](https://github.com/PowerShell/xComputerManagement/issues/140). +- Fix deletion of scheduled task with unknown or empty task trigger. + Get-TargetResource returns an empty ScheduleType string if the task + trigger is empty or unknown - See [Issue + #137](https://github.com/PowerShell/xComputerManagement/issues/137). +- Added dependency information for xScheduledTask to README.MD. + +## [4.0.0.0] - 2018-02-08 + +### Changed + +- BREAKING CHANGE: xScheduledTask: + - Breaking change because `Get-TargetResource` no longer outputs + `ActionExecutable` and `ScheduleType` properties when the scheduled + task does not exist. It will also include `TaskPath` in output when + scheduled task does not exist. +- xScheduledTask: + - Add support to disable built-in scheduled tasks - See [Issue #74](https://github.com/PowerShell/xComputerManagement/issues/74). + - Fix unit test mocked schedule task object structure. + - Fix error message when trigger type is unknown - See [Issue #121](https://github.com/PowerShell/xComputerManagement/issues/121). + - Moved strings into separate strings file. + - Updated to meet HQRM guidelines. +- xComputer: + - Resolved bug in Get-ComputerDomain where LocalSystem doesn't have + rights to the domain. +- Updated tests to meet Pester V4 guidelines - See [Issue #106](https://github.com/PowerShell/xComputerManagement/issues/106). +- Converted module to use auto documentation format. + +## [3.2.0.0] - 2017-12-20 + +### Changed + +- xScheduledTask: + - Enable Execution Time Limit of task to be set to indefinite + by setting `ExecutionTimeLimit` to '00:00:00' - See [Issue #115](https://github.com/PowerShell/xComputerManagement/issues/115). +- xPowerPlan: + - Updated to meet HQRM guidelines. + - Converted calls to `throw` to use `New-InvalidOperationException` + in CommonResourceHelper. +- Move Common Resource Helper functions into modules folder. +- Changed resources to use Common Resource Helper functions. +- Moved strings for Common Resource Helper functions into separate + strings file. +- Added unit tests for Common Helper functions. + +## [3.1.0.0] - 2017-11-15 + +### Changed + +- xOfflineDomainJoin: + - Updated to meet HQRM guidelines. +- xScheduledTask: + - Applied autoformatting to examples to improve readability. + - Added LogonType and RunLevel parameters for controlling + task execution. + - Correct `Assert-VerifiableMocks` to `Assert-VerifiableMock` + +## [3.0.0.0] - 2017-10-05 + +### Changed + +- xComputer: Added parameter to set the local computer description along with documentation + and unit tests for this change. +- BREAKING CHANGE: xScheduledTask: + - Converted all Interval/Duration type parameters over to be string format + to prevent the Timezone the MOF file was created in from being stored. + This is to fix problems where MOF files are created in one timezone but + deployed nodes to a different timezone - See [Issue #85](https://github.com/PowerShell/xComputerManagement/issues/85) + - Added ConvertTo-TimeSpanFromScheduledTaskString function and refactored + to reduce code duplication. + - Added support for setting repetition duration to `Indefinitely`. +- xComputer: + - Moved strings to localization file. + - Updated to meet HQRM guidelines. +- xVirtualMemory: + - Refactored shared common code into new utility functions to + reduce code duplication and improve testability. + - Moved strings into localizable strings file. + - Converted calls to `throw` to use `New-InvalidOperationException` + in CommonResourceHelper. + - Improved unit test coverage. + - Updated to meet HQRM guidelines. + +## [2.1.0.0] - 2017-08-23 + +### Changed + +- xComputer: Changed comparison that validates if we are in the correct AD + Domain to work correctly if FQDN wasn't used. +- Updated AppVeyor.yml to use AppVeyor.psm1 module in DSCResource.Tests. +- Removed Markdown.md errors. +- Added CodeCov.io support. +- xScheduledTask + - Fixed incorrect TaskPath handling - [Issue #45](https://github.com/PowerShell/xComputerManagement/issues/45) +- Change examples to meet HQRM standards and optin to Example validation + tests. +- Replaced examples in README.MD to links to Example files. +- Added the VS Code PowerShell extension formatting settings that cause PowerShell + files to be formatted as per the DSC Resource kit style guidelines - [Issue #91](https://github.com/PowerShell/xComputerManagement/issues/91). +- Opted into Common Tests 'Validate Module Files' and 'Validate Script Files'. +- Converted files with UTF8 with BOM over to UTF8 - fixes [Issue #90](https://github.com/PowerShell/xComputerManagement/issues/90). +- Updated Year to 2017 in License and Manifest - fixes [Issue #87](https://github.com/PowerShell/xComputerManagement/issues/87). +- Added .github support files - fixes [Issue #88](https://github.com/PowerShell/xComputerManagement/issues/88): + - CONTRIBUTING.md + - ISSUE_TEMPLATE.md + - PULL_REQUEST_TEMPLATE.md +- Resolved all PSScriptAnalyzer warnings and style guide warnings. +- xOfflineDomainJoin: + - Changed to use CommonResourceHelper to load localization strings. + - Renamed en-US to be correct case so that localization strings can be loaded. + - Suppress PSScriptAnalyzer rule PSAvoidGlobalVars for + `$global:DSCMachineStatus = 1`. +- xComputer: + - Suppress PSScriptAnalyzer rule PSAvoidGlobalVars for + `$global:DSCMachineStatus = 1`. +- xVirtualMemory: + - Suppress PSScriptAnalyzer rule PSAvoidGlobalVars for + `$global:DSCMachineStatus = 1`. + +## [2.0.0.0] - 2017-07-12 + +### Changed + +- Updated resources + - BREAKING CHANGE: xScheduledTask: Added nearly all available parameters for tasks +- xVirtualMemory: + - Fixed failing tests. + +## [1.10.0.0] - 2017-05-31 + +### Changed + +- Added resources: + - xVirtualMemory + +## [1.9.0.0] - 2016-12-14 + +### Changed + +- Added resources + - xPowerPlan + +## [1.8.0.0] - 2016-08-10 + +### Changed + +- Converted AppVeyor.yml to pull Pester from PSGallery instead of + Chocolatey. +- Changed AppVeyor.yml to use default image +- xScheduledTask: Fixed bug with different OS versions returning repeat interval + differently + +## [1.7.0.0] - 2016-06-29 + +### Changed + +- Added support for enabling or disabling scheduled tasks +- The Name parameter resolves to $env:COMPUTERNAME when the value is localhost + +## [1.6.0.0] - 2016-05-18 + +### Changed + +- Added the following resources: + - DSC_xOfflineDomainJoin resource to join computers to an AD Domain using an + Offline Domain Join request file. + - DSC_xScheduledTask resource to control scheduled tasks on the local server +- DSC_xOfflineDomainJoin: Corrected localizedData.DomainAlreadyJoinedhMessage name. +- xComputer: Changed credential generation code in tests to avoid triggering + PSSA rule PSAvoidUsingConvertToSecureStringWithPlainText. + Renamed unit test file to match the name of Resource file. + +## [1.5.0.0] - 2016-03-31 + +### Changed + +- Update Unit tests to use the standard folder structure and test templates. +- Added .gitignore to prevent commit of DSCResource.Tests. + +## [1.4.0.0] - 2016-02-03 + +### Changed + +- Added validation to the Name parameter +- Added the JoinOU parameter which allows you to specify the organizational unit + that the computer account will be created in +- Added the CurrentOU read-only property that shows the organizational unit that + the computer account is currently in + +## [1.3.0.0] - 2015-06-08 + +### Changed + +- xComputer + - Fixed issue with Test-TargetResource when not specifying Domain or + Workgroup name + - Added tests + +## [1.2.2.0] - 2015-02-19 + +### Changed + +- Added types to Get/Set/Test definitions to allow xResourceDesigner validation + to succeed + +## [1.2.0.0] - 2014-05-13 + +### Changed + +- Added functionality to enable moving computer from one domain to another +- Modified Test-DscConfiguration logics when testing domain join + +## [1.0.0.0] - 2014-01-01 + +### Changed + +- Initial release with the following resources: + - xComputer diff --git a/HISTORIC_CHANGELOG.md b/HISTORIC_CHANGELOG.md deleted file mode 100644 index 08edee21..00000000 --- a/HISTORIC_CHANGELOG.md +++ /dev/null @@ -1,451 +0,0 @@ -# Historic change log for ComputerManagementDsc - -The release notes in the PowerShell Module manifest cannot exceed 10000 -characters. Due to a bug in the CI deploy pipeline this is not handled. -This file is to temporary move the older change log history to keep the -change log short. - -## [7.1.0.0] - -### Changed - -- ComputerManagementDsc: - - Update psd1 description - Fixes [Issue #269](https://github.com/dsccommunity/ComputerManagementDsc/issues/269). -- Fix minor style issues with missing spaces between `param` statements and '('. -- SmbServerConfiguration: - - New resource for configuring the SMB Server settings. - - Added examples for SMB Server Configuration. -- Minor corrections to CHANGELOG.MD. -- ScheduledTask: - - Fixed bug when description has any form of whitespace at beginning or - end the resource would not go into state - Fixes [Issue #258](https://github.com/dsccommunity/ComputerManagementDsc/issues/258). -- SmbShare: - - Fixed bug where the resource would not update the path of a share if the - share exists on a different path. Adds a parameter Force to the SmbShare - resource to allow updating of the path - Fixes [Issue #215](https://github.com/dsccommunity/ComputerManagementDsc/issues/215) - - Removal of duplicate code in Add-SmbShareAccessPermission helper function - fixes [Issue #226](https://github.com/dsccommunity/ComputerManagementDsc/issues/226). - -## [7.0.0.0] - -### Changed - -- ScheduledTask: - - Better compatibility with Group LogonType - when passing BuiltIn groups through ExecuteAsCredential - - Primary use case is 'BUILTIN\Users' - - Use the ExecuteAsCredential property to pass the username - The PSCredential needs a non-null that is ignored - - Delay property not handled properly on AtLogon and AtStartup trigger - Fixes - [Issue #230](https://github.com/dsccommunity/ComputerManagementDsc/issues/230). - - Changed `Get-ScheduledTask` calls to `ScheduledTasks\Get-ScheduledTask` to - avoid name clash with `Carbon` module. Fixes [Issue #248](https://github.com/dsccommunity/ComputerManagementDsc/issues/248). - - Cast `MultipleInstances` value returned by `Get-TargetResource` to `string` - - fixes [Issue #255](https://github.com/dsccommunity/ComputerManagementDsc/issues/255). -- PendingReboot: - - Migrated xPendingReboot from [xPendingReboot](https://github.com/PowerShell/xPendingReboot) - and renamed to PendingReboot. - - Converted to meet HQRM guidelines - Fixes [Issue #12](https://github.com/PowerShell/xPendingReboot/issues/12). - - Changed `SkipCcmClientSDK` parameter to default to `$true` - Fixes [Issue #13](https://github.com/PowerShell/xPendingReboot/issues/13). - - Fixed `Test-TargetResource` so that if ConfigMgr requires a reboot then - the pending reboot will be set - Fixes [Issue #26](https://github.com/PowerShell/xPendingReboot/issues/26). - - Refactored `Test-TargetResource` to reduce code duplication and move to a - data driven design. - - Refactored `Get-TargetResource` by adding a new function `Get-PendingRebootState` - so that `Test-TargetResource` no longer needed to use `Get-TargetResource`. This - eliminated the need to include write parameters in `Get-TargetResource`. - - Converted the call to `Invoke-WmiMethod` to `Invoke-CimMethod`. - - Deleted the code that removes the `regRebootLocations` variable at the end of - the resource as it appears to serve no purpose. -- Correct all tests to meet Pester 4.0 standards. -- RemoteDesktopAdmin: - - New resource for configuring Remote Desktop for Administration - fixes - [Issue #224](https://github.com/dsccommunity/ComputerManagementDsc/issues/224). -- Updated common function `Test-DscParameterState` to support ordered comparison - of arrays by copying function and tests from `NetworkingDsc` - fixes [Issue #250](https://github.com/dsccommunity/ComputerManagementDsc/issues/250). -- BREAKING CHANGE: ScheduledTask: - - Correct output type of `DaysInterval`,`StartTime`,`WeeksDaysOfWeek`, - and `WeeksInterval` parameters from `Get-TargetResource` to match MOF. - - Refactored `Get-TargetResource` to remove parameters that - are not key or required - fixes [Issue #249](https://github.com/dsccommunity/ComputerManagementDsc/issues/249). - - Added function `Test-DateStringContainsTimeZone` to determine if a string - containing a date time includes a time zone. - - Enable verbose preference to be passed through to `Test-DscParameterState`. - - Changed `Test-TargetResource` so that `StartTime` is only compared for - trigger types `Daily`,`Weekly` or `Once`. -- Fix minor style issues in statement case. - -## [6.5.0.0] - -### Changed - -- Computer: - - Fix for 'directory service is busy' error when joining a domain and renaming - a computer when JoinOU is specified - Fixes [Issue #221](https://github.com/dsccommunity/ComputerManagementDsc/issues/221). -- Added new resource SmbShare - - Moved and improved from deprecated module xSmbShare. -- Changes to ComputerManagementDsc.Common - - Updated Test-DscParameterState so it now can compare zero item - collections (arrays). -- Changes to WindowsEventLog - - Minor style guideline cleanup. -- Opt-in to common test to validate localization. Fixed localization strings - in resources - Fixes [Issue #217](https://github.com/dsccommunity/ComputerManagementDsc/issues/217). -- PowerShellExecutionPolicy: - - Removed `SupportsShouldProcess` as it cannot be used with DSC - Fixes - [Issue #219](https://github.com/dsccommunity/ComputerManagementDsc/issues/219). -- Combined all ComputerManagementDsc.ResourceHelper module functions into - ComputerManagementDsc.Common module - Fixes [Issue #218](https://github.com/dsccommunity/ComputerManagementDsc/issues/218). - - Minor code cleanup against style guideline. - - Remove code from `New-InvalidOperationException` because it was a - code path that could never could be used due to the parameter - validation preventing the helper function being called that way. - - Updated all `Get-LocalizationData` to latest version from - [DSCResource.Template](https://github.com/PowerShell/DSCResource.Template). - - Fixed an issue with the helper function `Test-IsNanoServer` that - prevented it to work. Though the helper function is not used, so this - issue was not caught until now when unit tests was added. - - Improved code coverage. - -## [6.4.0.0] - -### Changed - -- ScheduledTask: - - IdleWaitTimeout returned from Get-TargetResource always null - Fixes [Issue #186](https://github.com/dsccommunity/ComputerManagementDsc/issues/186). - - Added BuiltInAccount Property to allow running task as one of the build in - service accounts - Fixes [Issue #130](https://github.com/dsccommunity/ComputerManagementDsc/issues/130). -- Refactored module folder structure to move resource to root folder of - repository and remove test harness - fixes [Issue #188](https://github.com/dsccommunity/ComputerManagementDsc/issues/188). -- Added a CODE\_OF\_CONDUCT.md with the same content as in the README.md and - linked to it from README.MD instead. -- Updated test header for all unit tests to version 1.2.4. -- Updated test header for all integration to version 1.3.3. -- Enabled example publish to PowerShell Gallery by adding `gallery_api` - environment variable to `AppVeyor.yml`. - -## [6.3.0.0] - -### Changed - -- Correct PSSA custom rule violations - fixes [Issue #209](https://github.com/dsccommunity/ComputerManagementDsc/issues/209). -- Correct long example filenames for PowerShellExecutionPolicy examples. -- Opted into Common Tests 'Required Script Analyzer Rules', - 'Flagged Script Analyzer Rules', 'New Error-Level Script Analyzer Rules' - 'Custom Script Analyzer Rules' and 'Relative Path Length' - - fixes [Issue #152](https://github.com/dsccommunity/ComputerManagementDsc/issues/152). -- PowerPlan: - - Added support to specify the desired power plan either as name or guid. - Fixes [Issue #59](https://github.com/dsccommunity/ComputerManagementDsc/issues/59) - - Changed the resource so it uses Windows APIs instead of WMI/CIM - (Workaround for Server 2012R2 Core, Nano Server, Server 2019 and Windows 10). - Fixes [Issue #155](https://github.com/dsccommunity/ComputerManagementDsc/issues/155) - and [Issue #65](https://github.com/dsccommunity/ComputerManagementDsc/issues/65) - -## [6.2.0.0] - -### Changed - -- WindowsEventLog: - - Migrated the xWinEventLog from [xWinEventLog](https://github.com/PowerShell/xWinEventLog) - and renamed to WindowsEventLog. - - Moved strings in localization file. - - LogMode is now set with Limit-EventLog, - - Fixes [Issue #18](https://github.com/dsccommunity/ComputerManagementDsc/issues/18). -- Updated examples to format required for publishing to PowerShell Gallery - fixes - [Issue #206](https://github.com/dsccommunity/ComputerManagementDsc/issues/206). -- Opted into Common Tests 'Validate Example Files To Be Published' and - 'Validate Markdown Links'. - -## [6.1.0.0] - -### Changed - -- Updated LICENSE file to match the Microsoft Open Source Team standard. - Fixes [Issue #197](https://github.com/dsccommunity/ComputerManagementDsc/issues/197). -- Explicitly removed extra hidden files from release package - -## [6.0.0.0] - -### Changed - -- ScheduledTask: - - Added support for Group Managed Service Accounts, implemented using the ExecuteAsGMSA - parameter. Fixes [Issue #111](https://github.com/dsccommunity/ComputerManagementDsc/issues/111) - - Added support to set the Synchronize Across Time Zone option. Fixes [Issue #109](https://github.com/dsccommunity/ComputerManagementDsc/issues/109) -- Added .VSCode settings for applying DSC PSSA rules - fixes [Issue #189](https://github.com/dsccommunity/ComputerManagementDsc/issues/189). -- BREAKING CHANGE: PowerPlan: - - Added IsActive Read-Only Property - Fixes [Issue #171](https://github.com/dsccommunity/ComputerManagementDsc/issues/171). - - InActive power plans are no longer returned with their Name set to null. - Now, the name is always returned and the Read-Only property of IsActive - is set accordingly. - -## [5.2.0.0] - -### Changed - -- PowershellExecutionPolicy: - - Updated to meet HQRM guidelines. - - Migrated the xPowershellExecutionPolicy from [xPowershellExecutionPolicy](https://github.com/PowerShell/xPowerShellExecutionPolicy) - and renamed to PowershellExecutionPolicy. - - Moved strings to localization file. -- Changed the scope from Global to Script in DSC_ScheduledTask.Integration.Tests.ps1 -- Changed the scope from Global to Script ComputerManagementDsc.Common.Tests.ps1 -- ScheduledTask: - - Added support for event based triggers, implemented using the ScheduleType OnEvent - fixes [Issue #167](https://github.com/dsccommunity/ComputerManagementDsc/issues/167) - -## [5.1.0.0] - -### Changed - -- TimeZone: - - Migrated xTimeZone resource from [xTimeZone](https://github.com/PowerShell/xTimeZone) - and renamed to TimeZone - fixes [Issue #157](https://github.com/dsccommunity/ComputerManagementDsc/issues/157). -- Moved Test-Command from ComputerManagementDsc.ResourceHelper to - ComputerManagementDsc.Common module to match what TimeZone requires. - It was not exported in ComputerManagementDsc.ResourceHelper and not - used. -- Add `server` parameter to `Computer` resource - fixes [Issue #161](https://github.com/dsccommunity/ComputerManagementDsc/issues/161) - -## [5.0.0.0] - -### Changed - -- BREAKING CHANGE: - - Renamed ComputerManagement to ComputerManagementDsc - fixes [Issue #119](https://github.com/dsccommunity/ComputerManagementDsc/issues/119). - - Changed all MSFT\_xResourceName to MSFT\_ResourceName. - - Updated DSCResources, Examples, Modules and Tests with new naming. - - Updated Year to 2018 in License and Manifest. - - Updated README.md from xComputerManagement to ComputerManagementDsc. -- OfflineDomainJoin: - - Cleaned up spacing in strings file to make consistent with other - resources. -- VirtualMemory: - - Converted strings to single quotes in integration test. - -## [4.1.0.0] - -### Changed - -- xScheduledTask: - - Update existing Scheduled Task using SetScheduleTask - instead of UnRegister/Register - See [Issue #134](https://github.com/PowerShell/xComputerManagement/issues/134). -- Fix master branch AppVeyor badge link URL in README.MD - See [Issue #140](https://github.com/PowerShell/xComputerManagement/issues/140). -- Fix deletion of scheduled task with unknown or empty task trigger. - Get-TargetResource returns an empty ScheduleType string if the task - trigger is empty or unknown - See [Issue - #137](https://github.com/PowerShell/xComputerManagement/issues/137). -- Added dependency information for xScheduledTask to README.MD. - -## [4.0.0.0] - -### Changed - -- BREAKING CHANGE: xScheduledTask: - - Breaking change because `Get-TargetResource` no longer outputs - `ActionExecutable` and `ScheduleType` properties when the scheduled - task does not exist. It will also include `TaskPath` in output when - scheduled task does not exist. -- xScheduledTask: - - Add support to disable built-in scheduled tasks - See [Issue #74](https://github.com/PowerShell/xComputerManagement/issues/74). - - Fix unit test mocked schedule task object structure. - - Fix error message when trigger type is unknown - See [Issue #121](https://github.com/PowerShell/xComputerManagement/issues/121). - - Moved strings into separate strings file. - - Updated to meet HQRM guidelines. -- xComputer: - - Resolved bug in Get-ComputerDomain where LocalSystem doesn't have - rights to the domain. -- Updated tests to meet Pester V4 guidelines - See [Issue #106](https://github.com/PowerShell/xComputerManagement/issues/106). -- Converted module to use auto documentation format. - -## [3.2.0.0] - -### Changed - -- xScheduledTask: - - Enable Execution Time Limit of task to be set to indefinite - by setting `ExecutionTimeLimit` to '00:00:00' - See [Issue #115](https://github.com/PowerShell/xComputerManagement/issues/115). -- xPowerPlan: - - Updated to meet HQRM guidelines. - - Converted calls to `throw` to use `New-InvalidOperationException` - in CommonResourceHelper. -- Move Common Resource Helper functions into modules folder. -- Changed resources to use Common Resource Helper functions. -- Moved strings for Common Resource Helper functions into separate - strings file. -- Added unit tests for Common Helper functions. - -## [3.1.0.0] - -### Changed - -- xOfflineDomainJoin: - - Updated to meet HQRM guidelines. -- xScheduledTask: - - Applied autoformatting to examples to improve readability. - - Added LogonType and RunLevel parameters for controlling - task execution. - - Correct `Assert-VerifiableMocks` to `Assert-VerifiableMock` - -## [3.0.0.0] - -### Changed - -- xComputer: Added parameter to set the local computer description along with documentation - and unit tests for this change. -- BREAKING CHANGE: xScheduledTask: - - Converted all Interval/Duration type parameters over to be string format - to prevent the Timezone the MOF file was created in from being stored. - This is to fix problems where MOF files are created in one timezone but - deployed nodes to a different timezone - See [Issue #85](https://github.com/PowerShell/xComputerManagement/issues/85) - - Added ConvertTo-TimeSpanFromScheduledTaskString function and refactored - to reduce code duplication. - - Added support for setting repetition duration to `Indefinitely`. -- xComputer: - - Moved strings to localization file. - - Updated to meet HQRM guidelines. -- xVirtualMemory: - - Refactored shared common code into new utility functions to - reduce code duplication and improve testability. - - Moved strings into localizable strings file. - - Converted calls to `throw` to use `New-InvalidOperationException` - in CommonResourceHelper. - - Improved unit test coverage. - - Updated to meet HQRM guidelines. - -## [2.1.0.0] - -### Changed - -- xComputer: Changed comparison that validates if we are in the correct AD - Domain to work correctly if FQDN wasn't used. -- Updated AppVeyor.yml to use AppVeyor.psm1 module in DSCResource.Tests. -- Removed Markdown.md errors. -- Added CodeCov.io support. -- xScheduledTask - - Fixed incorrect TaskPath handling - [Issue #45](https://github.com/PowerShell/xComputerManagement/issues/45) -- Change examples to meet HQRM standards and optin to Example validation - tests. -- Replaced examples in README.MD to links to Example files. -- Added the VS Code PowerShell extension formatting settings that cause PowerShell - files to be formatted as per the DSC Resource kit style guidelines - [Issue #91](https://github.com/PowerShell/xComputerManagement/issues/91). -- Opted into Common Tests 'Validate Module Files' and 'Validate Script Files'. -- Converted files with UTF8 with BOM over to UTF8 - fixes [Issue #90](https://github.com/PowerShell/xComputerManagement/issues/90). -- Updated Year to 2017 in License and Manifest - fixes [Issue #87](https://github.com/PowerShell/xComputerManagement/issues/87). -- Added .github support files - fixes [Issue #88](https://github.com/PowerShell/xComputerManagement/issues/88): - - CONTRIBUTING.md - - ISSUE_TEMPLATE.md - - PULL_REQUEST_TEMPLATE.md -- Resolved all PSScriptAnalyzer warnings and style guide warnings. -- xOfflineDomainJoin: - - Changed to use CommonResourceHelper to load localization strings. - - Renamed en-US to be correct case so that localization strings can be loaded. - - Suppress PSScriptAnalyzer rule PSAvoidGlobalVars for - `$global:DSCMachineStatus = 1`. -- xComputer: - - Suppress PSScriptAnalyzer rule PSAvoidGlobalVars for - `$global:DSCMachineStatus = 1`. -- xVirtualMemory: - - Suppress PSScriptAnalyzer rule PSAvoidGlobalVars for - `$global:DSCMachineStatus = 1`. - -## [2.0.0.0] - -### Changed - -- Updated resources - - BREAKING CHANGE: xScheduledTask: Added nearly all available parameters for tasks -- xVirtualMemory: - - Fixed failing tests. - -## [1.10.0.0] - -### Changed - -- Added resources: - - xVirtualMemory - -## [1.9.0.0] - -### Changed - -- Added resources - - xPowerPlan - -## [1.8.0.0] - -### Changed - -- Converted AppVeyor.yml to pull Pester from PSGallery instead of - Chocolatey. -- Changed AppVeyor.yml to use default image -- xScheduledTask: Fixed bug with different OS versions returning repeat interval - differently - -## [1.7.0.0] - -### Changed - -- Added support for enabling or disabling scheduled tasks -- The Name parameter resolves to $env:COMPUTERNAME when the value is localhost - -## [1.6.0.0] - -### Changed - -- Added the following resources: - - DSC_xOfflineDomainJoin resource to join computers to an AD Domain using an - Offline Domain Join request file. - - DSC_xScheduledTask resource to control scheduled tasks on the local server -- DSC_xOfflineDomainJoin: Corrected localizedData.DomainAlreadyJoinedhMessage name. -- xComputer: Changed credential generation code in tests to avoid triggering - PSSA rule PSAvoidUsingConvertToSecureStringWithPlainText. - Renamed unit test file to match the name of Resource file. - -## [1.5.0.0] - -### Changed - -- Update Unit tests to use the standard folder structure and test templates. -- Added .gitignore to prevent commit of DSCResource.Tests. - -## [1.4.0.0] - -### Changed - -- Added validation to the Name parameter -- Added the JoinOU parameter which allows you to specify the organizational unit - that the computer account will be created in -- Added the CurrentOU read-only property that shows the organizational unit that - the computer account is currently in - -## [1.3.0.0] - -### Changed - -- xComputer - - Fixed issue with Test-TargetResource when not specifying Domain or - Workgroup name - - Added tests - -## [1.2.2.0] - -### Changed - -- Added types to Get/Set/Test definitions to allow xResourceDesigner validation - to succeed - -## [1.2.0.0] - -### Changed - -- Added functionality to enable moving computer from one domain to another -- Modified Test-DscConfiguration logics when testing domain join - -## [1.0.0.0] - -### Changed - -- Initial release with the following resources: - - xComputer diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 index fea41de6..d8565aae 100644 --- a/RequiredModules.psd1 +++ b/RequiredModules.psd1 @@ -11,7 +11,7 @@ PSScriptAnalyzer = 'latest' Pester = 'latest' Plaster = 'latest' - ModuleBuilder = '1.0.0' + ModuleBuilder = 'latest' ChangelogManagement = 'latest' Sampler = 'latest' MarkdownLinkCheck = 'latest' diff --git a/azure-pipelines.yml b/azure-pipelines.yml index f272d3ed..1b74141f 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -3,8 +3,8 @@ trigger: include: - master paths: - exclude: - - CHANGELOG.md + include: + - source/* tags: include: - "v*" From 6b02ed9a205e58348aaef04f93620e8d285518a9 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 3 May 2020 17:43:56 +1200 Subject: [PATCH 02/23] Fix Issue #323 --- CHANGELOG.md | 2 ++ .../DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9698cf11..d8597042 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Change Azure DevOps Pipeline definition to include `source/*` - Fixes [Issue #324](https://github.com/dsccommunity/ComputerManagementDsc/issues/324). - Updated pipeline to use `latest` version of `ModuleBuilder` - Fixes [Issue #324](https://github.com/dsccommunity/ComputerManagementDsc/issues/324). - Merge `HISTORIC_CHANGELOG.md` into `CHANGELOG.md` - Fixes [Issue #325](https://github.com/dsccommunity/ComputerManagementDsc/issues/325). +- ScheduledTask: + - Fix ServiceAccount behavior on Windows Server 2016 - Fixes [Issue #323](https://github.com/dsccommunity/ComputerManagementDsc/issues/323). ### Fixed diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index 730bc043..adcb1d3f 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -1858,6 +1858,13 @@ function Get-CurrentResource if (($result.ContainsKey('LogonType')) -and ($result['LogonType'] -ieq 'ServiceAccount')) { + $userId = $task.Principal.UserId + + if ($userId -like 'NT AUTHORITY\*') + { + $userId = "NT AUTHORITY\$($userId)" + } + $result.Add('BuiltInAccount', $task.Principal.UserId) } } From 1ec54a4179de36a235adfd0e4cc8222262f8dbd9 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 3 May 2020 18:09:59 +1200 Subject: [PATCH 03/23] Correct builtInAccount behavior --- .../DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index adcb1d3f..df425f08 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -1858,14 +1858,14 @@ function Get-CurrentResource if (($result.ContainsKey('LogonType')) -and ($result['LogonType'] -ieq 'ServiceAccount')) { - $userId = $task.Principal.UserId + $builtInAccount = $task.Principal.UserId - if ($userId -like 'NT AUTHORITY\*') + if ($builtInAccount -like 'NT AUTHORITY\*') { - $userId = "NT AUTHORITY\$($userId)" + $builtInAccount = "NT AUTHORITY\$($builtInAccount)" } - $result.Add('BuiltInAccount', $task.Principal.UserId) + $result.Add('BuiltInAccount', $builtInAccount) } } From c05a32d23fd365e414791930e8079529933132c9 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 3 May 2020 19:18:28 +1200 Subject: [PATCH 04/23] Fix BuiltInAccount handling --- source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index df425f08..c7371358 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -1860,9 +1860,9 @@ function Get-CurrentResource { $builtInAccount = $task.Principal.UserId - if ($builtInAccount -like 'NT AUTHORITY\*') + if (-not $builtInAccount.Contains('\')) { - $builtInAccount = "NT AUTHORITY\$($builtInAccount)" + $builtInAccount = "NT AUTHORITY\$builtInAccount" } $result.Add('BuiltInAccount', $builtInAccount) From 0f4dc4c1248fb22fd5da3e247a77b62e927ec05b Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 3 May 2020 18:44:14 +1200 Subject: [PATCH 05/23] Add Debug Info --- source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index c7371358..3d94b780 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -1858,6 +1858,10 @@ function Get-CurrentResource if (($result.ContainsKey('LogonType')) -and ($result['LogonType'] -ieq 'ServiceAccount')) { + Write-Verbose -Message 'LogonType is ServiceAccount' -Verbose + Write-Verbose -Message ($result | Out-String) -Verbose + Write-Verbose -Message ($task.Principal | Out-String) -Verbose + $builtInAccount = $task.Principal.UserId if (-not $builtInAccount.Contains('\')) From 75b741383bf228c7beca6272b1ff806c9fcf16c5 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 3 May 2020 18:59:12 +1200 Subject: [PATCH 06/23] Another try --- source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 1 - 1 file changed, 1 deletion(-) diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index 3d94b780..1e58ac04 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -1859,7 +1859,6 @@ function Get-CurrentResource if (($result.ContainsKey('LogonType')) -and ($result['LogonType'] -ieq 'ServiceAccount')) { Write-Verbose -Message 'LogonType is ServiceAccount' -Verbose - Write-Verbose -Message ($result | Out-String) -Verbose Write-Verbose -Message ($task.Principal | Out-String) -Verbose $builtInAccount = $task.Principal.UserId From ead94537cc88bdc83f32331a9cda6bb0fd2e8f6b Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 3 May 2020 19:17:45 +1200 Subject: [PATCH 07/23] Remove debugging code --- source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index 1e58ac04..c7371358 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -1858,9 +1858,6 @@ function Get-CurrentResource if (($result.ContainsKey('LogonType')) -and ($result['LogonType'] -ieq 'ServiceAccount')) { - Write-Verbose -Message 'LogonType is ServiceAccount' -Verbose - Write-Verbose -Message ($task.Principal | Out-String) -Verbose - $builtInAccount = $task.Principal.UserId if (-not $builtInAccount.Contains('\')) From 3a4df5e599acf1952825da5c3651d854d99f825a Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 3 May 2020 19:34:46 +1200 Subject: [PATCH 08/23] Add some debug --- source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index c7371358..e732e6ae 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -1808,6 +1808,9 @@ function Get-CurrentResource $PrincipalId = 'UserId' } + Write-Verbose -Message 'Principal' -Verbose + Write-Verbose -Message ($task.Principal | Out-String) -Verbose + $result = @{ TaskName = $task.TaskName TaskPath = $task.TaskPath From 2c2f47a973909ef1de665a982177182a24175b79 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 3 May 2020 20:11:38 +1200 Subject: [PATCH 09/23] Fix integration tests --- tests/Integration/DSC_ScheduledTask.config.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Integration/DSC_ScheduledTask.config.ps1 b/tests/Integration/DSC_ScheduledTask.config.ps1 index bcd5ef04..54a93efa 100644 --- a/tests/Integration/DSC_ScheduledTask.config.ps1 +++ b/tests/Integration/DSC_ScheduledTask.config.ps1 @@ -226,7 +226,7 @@ Configuration ScheduledTaskExecuteAsGroupAdd -TypeName System.Management.Automation.PSCredential ` -ArgumentList ('BUILTIN\Users', (ConvertTo-SecureString -String 'Ignore' -AsPlainText -Force)) - ScheduledTask ScheduledTaskExecuteAsAdd + ScheduledTask ScheduledTaskExecuteAsGroupAdd { TaskName = 'Test task Logon with BuiltIn Group' TaskPath = '\ComputerManagementDsc\' @@ -420,7 +420,7 @@ Configuration ScheduledTaskExecuteAsGroupMod node 'localhost' { - ScheduledTask ScheduledTaskLogonMod + ScheduledTask ScheduledTaskExecuteAsGroupMod { TaskName = 'Test task Logon with BuiltIn Group' TaskPath = '\ComputerManagementDsc\' @@ -600,7 +600,7 @@ Configuration ScheduledTaskExecuteAsDel node 'localhost' { - ScheduledTask ScheduledTaskLogonDel + ScheduledTask ScheduledTaskExecuteAsDel { TaskName = 'Test task Logon' TaskPath = '\ComputerManagementDsc\' @@ -617,7 +617,7 @@ Configuration ScheduledTaskExecuteAsGroupDel node 'localhost' { - ScheduledTask ScheduledTaskLogonDel + ScheduledTask ScheduledTaskExecuteAsGroupDel { TaskName = 'Test task Logon with BuiltIn Group' TaskPath = '\ComputerManagementDsc\' From a349ec0f2aa61db71cdfcc509f3bb53b6a2c160e Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 3 May 2020 20:12:39 +1200 Subject: [PATCH 10/23] Fix ScheduledTask integration test config names --- tests/Integration/DSC_ScheduledTask.config.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Integration/DSC_ScheduledTask.config.ps1 b/tests/Integration/DSC_ScheduledTask.config.ps1 index bcd5ef04..54a93efa 100644 --- a/tests/Integration/DSC_ScheduledTask.config.ps1 +++ b/tests/Integration/DSC_ScheduledTask.config.ps1 @@ -226,7 +226,7 @@ Configuration ScheduledTaskExecuteAsGroupAdd -TypeName System.Management.Automation.PSCredential ` -ArgumentList ('BUILTIN\Users', (ConvertTo-SecureString -String 'Ignore' -AsPlainText -Force)) - ScheduledTask ScheduledTaskExecuteAsAdd + ScheduledTask ScheduledTaskExecuteAsGroupAdd { TaskName = 'Test task Logon with BuiltIn Group' TaskPath = '\ComputerManagementDsc\' @@ -420,7 +420,7 @@ Configuration ScheduledTaskExecuteAsGroupMod node 'localhost' { - ScheduledTask ScheduledTaskLogonMod + ScheduledTask ScheduledTaskExecuteAsGroupMod { TaskName = 'Test task Logon with BuiltIn Group' TaskPath = '\ComputerManagementDsc\' @@ -600,7 +600,7 @@ Configuration ScheduledTaskExecuteAsDel node 'localhost' { - ScheduledTask ScheduledTaskLogonDel + ScheduledTask ScheduledTaskExecuteAsDel { TaskName = 'Test task Logon' TaskPath = '\ComputerManagementDsc\' @@ -617,7 +617,7 @@ Configuration ScheduledTaskExecuteAsGroupDel node 'localhost' { - ScheduledTask ScheduledTaskLogonDel + ScheduledTask ScheduledTaskExecuteAsGroupDel { TaskName = 'Test task Logon with BuiltIn Group' TaskPath = '\ComputerManagementDsc\' From 111907606756ad70174aa5d42ed5d8ff6c3819ce Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 3 May 2020 20:28:58 +1200 Subject: [PATCH 11/23] Improve integration tests --- .../Integration/DSC_ScheduledTask.config.ps1 | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/tests/Integration/DSC_ScheduledTask.config.ps1 b/tests/Integration/DSC_ScheduledTask.config.ps1 index 54a93efa..1be2d206 100644 --- a/tests/Integration/DSC_ScheduledTask.config.ps1 +++ b/tests/Integration/DSC_ScheduledTask.config.ps1 @@ -403,13 +403,19 @@ Configuration ScheduledTaskExecuteAsMod node 'localhost' { + $executeAsCredential = New-Object ` + -TypeName System.Management.Automation.PSCredential ` + -ArgumentList ("$ENV:COMPUTERNAME\$ENV:USERNAME", (ConvertTo-SecureString -String 'Ignore' -AsPlainText -Force)) + ScheduledTask ScheduledTaskExecuteAsMod { - TaskName = 'Test task Logon' - TaskPath = '\ComputerManagementDsc\' - ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' - ScheduleType = 'AtLogOn' - RunLevel = 'Limited' + TaskName = 'Test task Logon' + TaskPath = '\ComputerManagementDsc\' + ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' + ScheduleType = 'AtLogOn' + ExecuteAsCredential = $executeAsCredential + LogonType = 'Interactive' + RunLevel = 'Highest' } } } @@ -420,13 +426,19 @@ Configuration ScheduledTaskExecuteAsGroupMod node 'localhost' { + $executeAsCredential = New-Object ` + -TypeName System.Management.Automation.PSCredential ` + -ArgumentList ('BUILTIN\Users', (ConvertTo-SecureString -String 'Ignore' -AsPlainText -Force)) + ScheduledTask ScheduledTaskExecuteAsGroupMod { - TaskName = 'Test task Logon with BuiltIn Group' - TaskPath = '\ComputerManagementDsc\' - ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' - ScheduleType = 'AtLogOn' - RunLevel = 'Limited' + TaskName = 'Test task Logon with BuiltIn Group' + TaskPath = '\ComputerManagementDsc\' + ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' + LogonType = 'Group' + ExecuteAsCredential = $executeAsCredential + ScheduleType = 'AtLogOn' + RunLevel = 'Limited' } } } From 32efe934302fb553e1e10c3a8f40dbd15a4dc2b6 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 3 May 2020 20:43:28 +1200 Subject: [PATCH 12/23] Improve integration tests of ScheduledTask --- .../Integration/DSC_ScheduledTask.config.ps1 | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/tests/Integration/DSC_ScheduledTask.config.ps1 b/tests/Integration/DSC_ScheduledTask.config.ps1 index 54a93efa..1be2d206 100644 --- a/tests/Integration/DSC_ScheduledTask.config.ps1 +++ b/tests/Integration/DSC_ScheduledTask.config.ps1 @@ -403,13 +403,19 @@ Configuration ScheduledTaskExecuteAsMod node 'localhost' { + $executeAsCredential = New-Object ` + -TypeName System.Management.Automation.PSCredential ` + -ArgumentList ("$ENV:COMPUTERNAME\$ENV:USERNAME", (ConvertTo-SecureString -String 'Ignore' -AsPlainText -Force)) + ScheduledTask ScheduledTaskExecuteAsMod { - TaskName = 'Test task Logon' - TaskPath = '\ComputerManagementDsc\' - ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' - ScheduleType = 'AtLogOn' - RunLevel = 'Limited' + TaskName = 'Test task Logon' + TaskPath = '\ComputerManagementDsc\' + ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' + ScheduleType = 'AtLogOn' + ExecuteAsCredential = $executeAsCredential + LogonType = 'Interactive' + RunLevel = 'Highest' } } } @@ -420,13 +426,19 @@ Configuration ScheduledTaskExecuteAsGroupMod node 'localhost' { + $executeAsCredential = New-Object ` + -TypeName System.Management.Automation.PSCredential ` + -ArgumentList ('BUILTIN\Users', (ConvertTo-SecureString -String 'Ignore' -AsPlainText -Force)) + ScheduledTask ScheduledTaskExecuteAsGroupMod { - TaskName = 'Test task Logon with BuiltIn Group' - TaskPath = '\ComputerManagementDsc\' - ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' - ScheduleType = 'AtLogOn' - RunLevel = 'Limited' + TaskName = 'Test task Logon with BuiltIn Group' + TaskPath = '\ComputerManagementDsc\' + ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' + LogonType = 'Group' + ExecuteAsCredential = $executeAsCredential + ScheduleType = 'AtLogOn' + RunLevel = 'Limited' } } } From c46ccc4dd27716e53c05e91ac8fdda57da154665 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Mon, 4 May 2020 08:14:45 +1200 Subject: [PATCH 13/23] Test changing Users group name --- tests/Integration/DSC_ScheduledTask.config.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Integration/DSC_ScheduledTask.config.ps1 b/tests/Integration/DSC_ScheduledTask.config.ps1 index 1be2d206..a01e01d9 100644 --- a/tests/Integration/DSC_ScheduledTask.config.ps1 +++ b/tests/Integration/DSC_ScheduledTask.config.ps1 @@ -224,7 +224,7 @@ Configuration ScheduledTaskExecuteAsGroupAdd { $executeAsCredential = New-Object ` -TypeName System.Management.Automation.PSCredential ` - -ArgumentList ('BUILTIN\Users', (ConvertTo-SecureString -String 'Ignore' -AsPlainText -Force)) + -ArgumentList ('Users', (ConvertTo-SecureString -String 'Ignore' -AsPlainText -Force)) ScheduledTask ScheduledTaskExecuteAsGroupAdd { @@ -428,7 +428,7 @@ Configuration ScheduledTaskExecuteAsGroupMod { $executeAsCredential = New-Object ` -TypeName System.Management.Automation.PSCredential ` - -ArgumentList ('BUILTIN\Users', (ConvertTo-SecureString -String 'Ignore' -AsPlainText -Force)) + -ArgumentList ('Users', (ConvertTo-SecureString -String 'Ignore' -AsPlainText -Force)) ScheduledTask ScheduledTaskExecuteAsGroupMod { From d9024fd050f7c3fdcbc9aeb21cdd8af525ffce11 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Mon, 4 May 2020 16:44:41 +1200 Subject: [PATCH 14/23] Implement Set-DomainNameInAccountName function --- .../DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 78 +++++++++++++++++-- tests/Unit/DSC_ScheduledTask.Tests.ps1 | 26 +++++++ 2 files changed, 97 insertions(+), 7 deletions(-) diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index e732e6ae..bfed25cd 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -1861,13 +1861,7 @@ function Get-CurrentResource if (($result.ContainsKey('LogonType')) -and ($result['LogonType'] -ieq 'ServiceAccount')) { - $builtInAccount = $task.Principal.UserId - - if (-not $builtInAccount.Contains('\')) - { - $builtInAccount = "NT AUTHORITY\$builtInAccount" - } - + $buildInAccount = Set-DomainNameInAccountName -AccountName $task.Principal.UserId -DomainName 'NT AUTHORITY' $result.Add('BuiltInAccount', $builtInAccount) } } @@ -1903,3 +1897,73 @@ function Test-DateStringContainsTimeZone return $DateString.Contains('+') } + +<# + .SYNOPSIS + Set domain name in a down-level user or group name. + + .DESCRIPTION + Set the domain name in a down-level user or group name. + + .PARAMETER AccountName + The user or group name to set the domain name in. + + .PARAMETER DomainName + If the AccountName does not contain a domain name them prefix + it with this value. If the AccountName already contains a domain + name then it will only be updated if the Force switch is set. + + .PARAMETER Force + If the identity already contains a domain prefix then force + it to the value in Domain. + + .EXAMPLE + Set-DomainNameInAccountName -AccountName 'Users' -DomainName 'NT AUTHORITY' + + Returns 'NT AUTHORITY\Users'. + + .EXAMPLE + Set-DomainNameInAccountName -AccountName 'MyDomain\Users' -DomainName 'NT AUTHORITY' + + Returns 'MyDomain\Users'. + + .EXAMPLE + Set-DomainNameInAccountName -AccountName 'MyDomain\Users' -DomainName 'NT AUTHORITY' -Force + + Returns 'NT AUTHORITY\Users'. +#> +function Set-DomainNameInAccountName +{ + [CmdletBinding()] + [OutputType([System.String])] + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $AccountName, + + [Parameter(Mandatory = $true)] + [System.String] + $DomainName, + + [Parameter()] + [Switch] + $Force + ) + + if ($AccountName.Contains('\')) + { + $existingDomainName, $name = ($AccountName -Split '\\') + + if (-not $force -and -not [System.String]::IsNullOrEmpty($existingDomainName)) + { + $DomainName = $existingDomainName + } + } + else + { + $name = $AccountName + } + + return "$DomainName\$name" +} diff --git a/tests/Unit/DSC_ScheduledTask.Tests.ps1 b/tests/Unit/DSC_ScheduledTask.Tests.ps1 index 49afe7e1..73b3e2f9 100644 --- a/tests/Unit/DSC_ScheduledTask.Tests.ps1 +++ b/tests/Unit/DSC_ScheduledTask.Tests.ps1 @@ -2189,6 +2189,32 @@ try } } } + + Describe 'DSC_ScheduledTask\Set-DomainNameInAccountName' { + Context 'When the account name does not have a domain name' { + It 'Should return NewDomain\Users' { + Set-DomainNameInAccountName -AccountName 'Users' -DomainName 'NewDomain' | Should -BeExactly 'NewDomain\Users' + } + } + + Context 'When the account name has an empty domain' { + It 'Should return NewDomain\Users' { + Set-DomainNameInAccountName -AccountName '\Users' -DomainName 'NewDomain' | Should -BeExactly 'NewDomain\Users' + } + } + + Context 'When the account name has a domain name and force is not set' { + It 'Should return ExistingDomain\Users' { + Set-DomainNameInAccountName -AccountName 'ExistingDomain\Users' -DomainName 'NewDomain' | Should -BeExactly 'ExistingDomain\Users' + } + } + + Context 'When the account name has a domain name and force is set' { + It 'Should return NewDomain\Users' { + Set-DomainNameInAccountName -AccountName 'ExistingDomain\Users' -DomainName 'NewDomain' -Force | Should -BeExactly 'NewDomain\Users' + } + } + } } } finally From 3e7ac11f74433b88434393f72c6ce4bc18ebbf6f Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Mon, 4 May 2020 16:57:47 +1200 Subject: [PATCH 15/23] Fix typo in ScheduledTask BuiltInAccount handling --- source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index bfed25cd..2c31ef51 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -1861,7 +1861,7 @@ function Get-CurrentResource if (($result.ContainsKey('LogonType')) -and ($result['LogonType'] -ieq 'ServiceAccount')) { - $buildInAccount = Set-DomainNameInAccountName -AccountName $task.Principal.UserId -DomainName 'NT AUTHORITY' + $builtInAccount = Set-DomainNameInAccountName -AccountName $task.Principal.UserId -DomainName 'NT AUTHORITY' $result.Add('BuiltInAccount', $builtInAccount) } } From 634fbcecba3f1742f12b65adda0e50fada0c7b47 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Mon, 4 May 2020 19:13:24 +1200 Subject: [PATCH 16/23] Add fixe for #294 --- CHANGELOG.md | 5 ++++ .../DSCResources/DSC_ScheduledTask/README.md | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52fc0e8d..6b6aaed5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Merge `HISTORIC_CHANGELOG.md` into `CHANGELOG.md` - Fixes [Issue #325](https://github.com/dsccommunity/ComputerManagementDsc/issues/325). - ScheduledTask: - Fix ServiceAccount behavior on Windows Server 2016 - Fixes [Issue #323](https://github.com/dsccommunity/ComputerManagementDsc/issues/323). + - Fixed problems in integration test configuration naming. + - Changed `ScheduledTaskExecuteAsGroupAdd` and `ScheduledTaskExecuteAsGroupMod` + to use a group name that does not include a domain name `BUILTIN\`. + - Added known issues to the documentation for describing `ExecuteAsCredential` + behavior - Fixes [Issue #294](https://github.com/dsccommunity/ComputerManagementDsc/issues/294). ### Fixed diff --git a/source/DSCResources/DSC_ScheduledTask/README.md b/source/DSCResources/DSC_ScheduledTask/README.md index 77f2b32e..8ea83832 100644 --- a/source/DSCResources/DSC_ScheduledTask/README.md +++ b/source/DSCResources/DSC_ScheduledTask/README.md @@ -3,3 +3,27 @@ The resource is used to define basic run once or recurring scheduled tasks on the local computer. It can also be used to delete or disable built-in scheduled tasks. + +## Known Issues + +### ExecuteAsCredential + +#### When Using a BUILTIN Group + +When creating a scheduled task that uses an `ExecuteAsCredential` that +is one of the 'BUILTIN' groups (e.g. 'BUILTIN\Users'), specifying the +username to include the 'BUILTIN' domain name will result in the resource +never going into state. The same behavior will also occur if setting a +'BUILTIN' group in the UI. + +To prevent this issue, set the username in the `ExecuteAsCredential` to the +name of the group only (e.g. 'Users'). + +#### When Using a Domain User/Group + +When creating a scheduled task that uses an `ExecuteAsCredential` that +is a domain user or group, (e.g. 'CONTOSO\ServiceUser'), the domain +name must be included, otherwise the resource will not go into state. + +To prevent this issue, set the username in the `ExecuteAsCredential` to the +name of the group only (e.g. 'CONTOSO\ServiceUser'). From def95e394cd5f93104a37986c8d634cc1376922a Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Mon, 4 May 2020 19:36:58 +1200 Subject: [PATCH 17/23] Remove debug code --- source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index 2c31ef51..1f7428ec 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -1808,9 +1808,6 @@ function Get-CurrentResource $PrincipalId = 'UserId' } - Write-Verbose -Message 'Principal' -Verbose - Write-Verbose -Message ($task.Principal | Out-String) -Verbose - $result = @{ TaskName = $task.TaskName TaskPath = $task.TaskPath From b618df7aab58d2edfea3d2f8e78864bbab1015d2 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Mon, 4 May 2020 19:42:09 +1200 Subject: [PATCH 18/23] Fix PendingReboot tests --- CHANGELOG.md | 4 ++++ tests/Integration/DSC_PendingReboot.Tests.ps1 | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b6aaed5..f0b1f25c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 to use a group name that does not include a domain name `BUILTIN\`. - Added known issues to the documentation for describing `ExecuteAsCredential` behavior - Fixes [Issue #294](https://github.com/dsccommunity/ComputerManagementDsc/issues/294). +- PendingReboot: + - Changed integration tests to `SkipPendingFileRename` check because + some Azure DevOps Agent images have the pending file rename flag set + to true by default. ### Fixed diff --git a/tests/Integration/DSC_PendingReboot.Tests.ps1 b/tests/Integration/DSC_PendingReboot.Tests.ps1 index cf9a9854..52d87baa 100644 --- a/tests/Integration/DSC_PendingReboot.Tests.ps1 +++ b/tests/Integration/DSC_PendingReboot.Tests.ps1 @@ -59,7 +59,7 @@ try RebootName = 'TestReboot' SkipComponentBasedServicing = $false SkipWindowsUpdate = $false - SkipPendingFileRename = $false + SkipPendingFileRename = $true SkipPendingComputerRename = $false SkipCcmClientSDK = $true } From a4c3df9f4feae878e14264132abbbcdcb533a02e Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Mon, 4 May 2020 20:17:01 +1200 Subject: [PATCH 19/23] Fix PendingReboot parameters --- tests/Integration/DSC_PendingReboot.Tests.ps1 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/Integration/DSC_PendingReboot.Tests.ps1 b/tests/Integration/DSC_PendingReboot.Tests.ps1 index 52d87baa..8a5f7618 100644 --- a/tests/Integration/DSC_PendingReboot.Tests.ps1 +++ b/tests/Integration/DSC_PendingReboot.Tests.ps1 @@ -96,17 +96,23 @@ try $_.ConfigurationName -eq "$($script:dscResourceName)_Config" } $current.Name | Should -Be $configData.AllNodes[0].RebootName - $current.SkipComponentBasedServicing | Should -Be $configData.AllNodes[0].SkipComponentBasedServicing $current.ComponentBasedServicing | Should -BeFalse - $current.SkipWindowsUpdate | Should -Be $configData.AllNodes[0].SkipWindowsUpdate $current.WindowsUpdate | Should -BeTrue - $current.SkipPendingFileRename | Should -Be $configData.AllNodes[0].SkipPendingFileRename $current.PendingFileRename | Should -BeFalse - $current.SkipPendingComputerRename | Should -Be $configData.AllNodes[0].SkipPendingComputerRename $current.PendingComputerRename | Should -BeFalse - $current.SkipCcmClientSDK | Should -Be $configData.AllNodes[0].SkipCcmClientSDK $current.CcmClientSDK | Should -BeFalse $current.RebootRequired | Should -BeTrue + <# + The actual values assigned to the Skip* parameters + are not returned by Get-TargetResource because they + are set only (control) parameters, so can not be + evaluated except to check the default values. + #> + $current.SkipComponentBasedServicing | Should -BeFalse + $current.SkipWindowsUpdate | Should -BeFalse + $current.SkipPendingFileRename | Should -BeFalse + $current.SkipPendingComputerRename | Should -BeFalse + $current.SkipCcmClientSDK | Should -BeTrue } } } From 88e03887bb99fa9517672b5d6e1bf64a53758c20 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Mon, 4 May 2020 20:56:54 +1200 Subject: [PATCH 20/23] Fix PendingReboot integration tests --- tests/Integration/DSC_PendingReboot.Tests.ps1 | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/Integration/DSC_PendingReboot.Tests.ps1 b/tests/Integration/DSC_PendingReboot.Tests.ps1 index 8a5f7618..3388413d 100644 --- a/tests/Integration/DSC_PendingReboot.Tests.ps1 +++ b/tests/Integration/DSC_PendingReboot.Tests.ps1 @@ -37,7 +37,19 @@ try reboot flag and then set it to reboot required. After the tests have run we will determine if the Get-TargetResource indicates that a reboot would have been required. + + Also, on Azure DevOps Agents, there are sometimes pending file + rename operations that also cause the test to fail. So we will + also preserve the state of this setting. #> + $rebootRegistryKeys = @{ + ComponentBasedServicing = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\' + WindowsUpdate = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\' + PendingFileRename = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\' + ActiveComputerName = 'HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName' + PendingComputerName = 'HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName' + } + $windowsUpdateKeys = (Get-ChildItem -Path $rebootRegistryKeys.WindowsUpdate).Name if ($windowsUpdateKeys) @@ -52,6 +64,13 @@ try -Name 'RebootRequired' } + $script:pendingFileRenameState = (Get-ItemProperty -Path $rebootRegistryKeys.PendingFileRename).PendingFileRenameOperations + + if (-not [System.String]::IsNullOrEmpty($script:pendingFileRenameState)) + { + $null = Set-ItemProperty -Path $rebootRegistryKeys.PendingFileRename -Name PendingFileRenameOperations -Value '' + } + $configData = @{ AllNodes = @( @{ @@ -59,7 +78,7 @@ try RebootName = 'TestReboot' SkipComponentBasedServicing = $false SkipWindowsUpdate = $false - SkipPendingFileRename = $true + SkipPendingFileRename = $false SkipPendingComputerRename = $false SkipCcmClientSDK = $true } @@ -126,5 +145,10 @@ finally -ErrorAction SilentlyContinue } + if (-not [System.String]::IsNullOrEmpty($script:pendingFileRenameState)) + { + $null = Set-ItemProperty -Path $rebootRegistryKeys.PendingFileRename -Name PendingFileRenameOperations -Value $script:pendingFileRenameState + } + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } From d09392cfaaa12b20a08cf0a947e5905b17d407f0 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Mon, 4 May 2020 21:12:41 +1200 Subject: [PATCH 21/23] Another fix to PendingReboot Integration tests --- tests/Integration/DSC_PendingReboot.Tests.ps1 | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/Integration/DSC_PendingReboot.Tests.ps1 b/tests/Integration/DSC_PendingReboot.Tests.ps1 index 3388413d..b20033b5 100644 --- a/tests/Integration/DSC_PendingReboot.Tests.ps1 +++ b/tests/Integration/DSC_PendingReboot.Tests.ps1 @@ -42,7 +42,7 @@ try rename operations that also cause the test to fail. So we will also preserve the state of this setting. #> - $rebootRegistryKeys = @{ + $script:rebootRegistryKeys = @{ ComponentBasedServicing = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\' WindowsUpdate = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\' PendingFileRename = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\' @@ -50,7 +50,7 @@ try PendingComputerName = 'HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName' } - $windowsUpdateKeys = (Get-ChildItem -Path $rebootRegistryKeys.WindowsUpdate).Name + $windowsUpdateKeys = (Get-ChildItem -Path $script:rebootRegistryKeys.WindowsUpdate).Name if ($windowsUpdateKeys) { @@ -60,15 +60,17 @@ try if (-not $script:currentAutoUpdateRebootState) { $null = New-Item ` - -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\' ` + -Path $script:rebootRegistryKeys.WindowsUpdate ` -Name 'RebootRequired' } - $script:pendingFileRenameState = (Get-ItemProperty -Path $rebootRegistryKeys.PendingFileRename).PendingFileRenameOperations + $script:currentPendingFileRenameState = (Get-ItemProperty -Path $script:rebootRegistryKeys.PendingFileRename).PendingFileRenameOperations - if (-not [System.String]::IsNullOrEmpty($script:pendingFileRenameState)) + if ($script:currentPendingFileRenameState) { - $null = Set-ItemProperty -Path $rebootRegistryKeys.PendingFileRename -Name PendingFileRenameOperations -Value '' + $null = Remove-ItemProperty ` + -Path $script:rebootRegistryKeys.PendingFileRename ` + -Name PendingFileRenameOperations } $configData = @{ @@ -145,9 +147,12 @@ finally -ErrorAction SilentlyContinue } - if (-not [System.String]::IsNullOrEmpty($script:pendingFileRenameState)) + if ($script:currentPendingFileRenameState) { - $null = Set-ItemProperty -Path $rebootRegistryKeys.PendingFileRename -Name PendingFileRenameOperations -Value $script:pendingFileRenameState + $null = Set-ItemProperty ` + -Path $script:rebootRegistryKeys.PendingFileRename ` + -Name PendingFileRenameOperations ` + -Value $script:currentPendingFileRenameState } Restore-TestEnvironment -TestEnvironment $script:testEnvironment From 8db44ab1870cd212a42802030ca6179271e32bd4 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Mon, 4 May 2020 21:20:57 +1200 Subject: [PATCH 22/23] Update CHANGELOG --- CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0b1f25c..d1a7310d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,9 +36,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added known issues to the documentation for describing `ExecuteAsCredential` behavior - Fixes [Issue #294](https://github.com/dsccommunity/ComputerManagementDsc/issues/294). - PendingReboot: - - Changed integration tests to `SkipPendingFileRename` check because - some Azure DevOps Agent images have the pending file rename flag set - to true by default. + - Changed integration tests to clear pending file rename reboot flag before + executing tests and restoring when complete. ### Fixed From 74eeeb8144034da625c33aca26dbe997e2e675bd Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Tue, 5 May 2020 13:24:41 +1200 Subject: [PATCH 23/23] Clarify logic --- .../DSC_ScheduledTask/DSC_ScheduledTask.psm1 | 3 ++- tests/Unit/DSC_ScheduledTask.Tests.ps1 | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index 1f7428ec..29e35b55 100644 --- a/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -1952,8 +1952,9 @@ function Set-DomainNameInAccountName { $existingDomainName, $name = ($AccountName -Split '\\') - if (-not $force -and -not [System.String]::IsNullOrEmpty($existingDomainName)) + if (-not [System.String]::IsNullOrEmpty($existingDomainName) -and -not $force.IsPresent) { + # Keep the existing domain name if it is set and force is not specified $DomainName = $existingDomainName } } diff --git a/tests/Unit/DSC_ScheduledTask.Tests.ps1 b/tests/Unit/DSC_ScheduledTask.Tests.ps1 index 73b3e2f9..a15d4901 100644 --- a/tests/Unit/DSC_ScheduledTask.Tests.ps1 +++ b/tests/Unit/DSC_ScheduledTask.Tests.ps1 @@ -2191,13 +2191,13 @@ try } Describe 'DSC_ScheduledTask\Set-DomainNameInAccountName' { - Context 'When the account name does not have a domain name' { + Context 'When the account name does not have a domain name and force is not set' { It 'Should return NewDomain\Users' { Set-DomainNameInAccountName -AccountName 'Users' -DomainName 'NewDomain' | Should -BeExactly 'NewDomain\Users' } } - Context 'When the account name has an empty domain' { + Context 'When the account name has an empty domain and force is not set' { It 'Should return NewDomain\Users' { Set-DomainNameInAccountName -AccountName '\Users' -DomainName 'NewDomain' | Should -BeExactly 'NewDomain\Users' } @@ -2214,6 +2214,12 @@ try Set-DomainNameInAccountName -AccountName 'ExistingDomain\Users' -DomainName 'NewDomain' -Force | Should -BeExactly 'NewDomain\Users' } } + + Context 'When the account name does not have a domain name and force is set' { + It 'Should return NewDomain\Users' { + Set-DomainNameInAccountName -AccountName 'Users' -DomainName 'NewDomain' -Force | Should -BeExactly 'NewDomain\Users' + } + } } } }