diff --git a/.MetaTestOptIn.json b/.MetaTestOptIn.json deleted file mode 100644 index da83b370..00000000 --- a/.MetaTestOptIn.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - "Common Tests - Validate Markdown Files", - "Common Tests - Validate Example Files", - "Common Tests - Validate Module Files", - "Common Tests - Validate Script Files", - "Common Tests - Required Script Analyzer Rules", - "Common Tests - Flagged Script Analyzer Rules", - "Common Tests - New Error-Level Script Analyzer Rules", - "Common Tests - Custom Script Analyzer Rules", - "Common Tests - Validate Example Files To Be Published", - "Common Tests - Validate Markdown Links", - "Common Tests - Relative Path Length", - "Common Tests - Validate Localization" -] diff --git a/.codecov.yml b/.codecov.yml deleted file mode 100644 index 411198f0..00000000 --- a/.codecov.yml +++ /dev/null @@ -1,26 +0,0 @@ -codecov: - notify: - require_ci_to_pass: no - # dev should be the baseline for reporting - branch: dev - -comment: - layout: "reach, diff" - behavior: default - -coverage: - range: 50..80 - round: down - precision: 0 - - status: - project: - default: - # Set the overall project code coverage requirement to 70% - target: 70 - patch: - default: - # Set the pull request requirement to not regress overall coverage by more than 5% - # and let codecov.io set the goal for the code changed in the patch. - target: auto - threshold: 5 diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 925594ed..8f9fed13 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -36,7 +36,7 @@ --> - [ ] Added an entry under the Unreleased section of the change log in the CHANGELOG.md. Entry should say what was changed, and how that affects users (if applicable). -- [ ] Resource documentation added/updated in README.md in the resource folder. +- [ ] Resource documentation added/updated in README.md in resource folder. - [ ] Resource parameter descriptions added/updated in schema.mof and comment-based help. - [ ] Comment-based help added/updated. diff --git a/.gitignore b/.gitignore index 5066fd17..ecfe6a7f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,9 @@ -DSCResource.Tests +*.suo +*.user +*.coverage +.vs +.psproj +.sln +markdownissues.txt +TestResults.xml +output/ diff --git a/.vscode/settings.json b/.vscode/settings.json index 43f01cf9..503b7024 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,6 @@ -// Place your settings in this file to overwrite default and user settings. { "powershell.codeFormatting.openBraceOnSameLine": false, - "powershell.codeFormatting.newLineAfterOpenBrace": false, + "powershell.codeFormatting.newLineAfterOpenBrace": true, "powershell.codeFormatting.newLineAfterCloseBrace": true, "powershell.codeFormatting.whitespaceBeforeOpenBrace": true, "powershell.codeFormatting.whitespaceBeforeOpenParen": true, @@ -9,7 +8,30 @@ "powershell.codeFormatting.whitespaceAfterSeparator": true, "powershell.codeFormatting.ignoreOneLineBlock": false, "powershell.codeFormatting.preset": "Custom", + "powershell.codeFormatting.alignPropertyValuePairs": true, "files.trimTrailingWhitespace": true, "files.insertFinalNewline": true, - "powershell.scriptAnalysis.settingsPath": ".vscode\\analyzersettings.psd1" + "powershell.scriptAnalysis.settingsPath": ".vscode\\analyzersettings.psd1", + "powershell.scriptAnalysis.enable": true, + "files.associations": { + "*.ps1xml": "xml" + }, + "cSpell.words": [ + "COMPANYNAME", + "ICONURI", + "LICENSEURI", + "PROJECTURI", + "RELEASENOTES", + "buildhelpers", + "endregion", + "gitversion", + "icontains", + "keepachangelog", + "notin", + "pscmdlet", + "steppable" + ], + "[markdown]": { + "files.encoding": "utf8" + } } diff --git a/CHANGELOG.md b/CHANGELOG.md index f7ceafd2..70d75d22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,400 +1,42 @@ -# Versions +# Change log for ComputerManagementDsc -## Unreleased +The format is based on and uses the types of changes according to [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Added + +- None + +### Changed - SmbShare: - Add parameter ScopeName to support creating shares in a different - scope. Fixes [Issue #284](https://github.com/PowerShell/ComputerManagementDsc/issues/284) + scope - Fixes [Issue #284](https://github.com/dsccommunity/ComputerManagementDsc/issues/284). - Added `.gitattributes` to ensure CRLF is used when pulling repository - Fixes - [Issue #290](https://github.com/PowerShell/ComputerManagementDsc/issues/290). + [Issue #290](https://github.com/dsccommunity/ComputerManagementDsc/issues/290). - SystemLocale: - Migrated SystemLocale from [SystemLocaleDsc](https://github.com/PowerShell/SystemLocaleDsc). - RemoteDesktopAdmin: - Correct Context messages in integration tests by adding 'When'. +- WindowsCapability: + - Change `Test-TargetResource` to remove test for valid LogPath. -## 7.1.0.0 - -- ComputerManagementDsc: - - Update psd1 description - Fixes [Issue #269](https://github.com/PowerShell/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/PowerShell/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/PowerShell/ComputerManagementDsc/issues/215) - - Removal of duplicate code in Add-SmbShareAccessPermission helper function - fixes [Issue #226](https://github.com/PowerShell/ComputerManagementDsc/issues/226). - -## 7.0.0.0 - -- 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/PowerShell/ComputerManagementDsc/issues/230). - - Changed `Get-ScheduledTask` calls to `ScheduledTasks\Get-ScheduledTask` to - avoid name clash with `Carbon` module. Fixes [Issue #248](https://github.com/PowerShell/ComputerManagementDsc/issues/248). - - Cast `MultipleInstances` value returned by `Get-TargetResource` to `string` - - fixes [Issue #255](https://github.com/PowerShell/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/PowerShell/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/PowerShell/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/PowerShell/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 - -- 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/PowerShell/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/PowerShell/ComputerManagementDsc/issues/217). -- PowerShellExecutionPolicy: - - Removed `SupportsShouldProcess` as it cannot be used with DSC - Fixes - [Issue #219](https://github.com/PowerShell/ComputerManagementDsc/issues/219). -- Combined all ComputerManagementDsc.ResourceHelper module functions into - ComputerManagementDsc.Common module - Fixes [Issue #218](https://github.com/PowerShell/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 - -- ScheduledTask: - - IdleWaitTimeout returned from Get-TargetResource always null - Fixes [Issue #186](https://github.com/PowerShell/ComputerManagementDsc/issues/186). - - Added BuiltInAccount Property to allow running task as one of the build in - service accounts - Fixes [Issue #130](https://github.com/PowerShell/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/PowerShell/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 - -- Correct PSSA custom rule violations - fixes [Issue #209](https://github.com/PowerShell/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/PowerShell/ComputerManagementDsc/issues/152). -- PowerPlan: - - Added support to specify the desired power plan either as name or guid. - Fixes [Issue #59](https://github.com/PowerShell/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/PowerShell/ComputerManagementDsc/issues/155) - and [Issue #65](https://github.com/PowerShell/ComputerManagementDsc/issues/65) - -## 6.2.0.0 - -- 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/PowerShell/ComputerManagementDsc/issues/18). -- Updated examples to format required for publishing to PowerShell Gallery - fixes - [Issue #206](https://github.com/PowerShell/ComputerManagementDsc/issues/206). -- Opted into Common Tests 'Validate Example Files To Be Published' and - 'Validate Markdown Links'. - -## 6.1.0.0 - -- Updated LICENSE file to match the Microsoft Open Source Team standard. - Fixes [Issue #197](https://github.com/PowerShell/ComputerManagementDsc/issues/197). -- Explicitly removed extra hidden files from release package - -## 6.0.0.0 - -- ScheduledTask: - - Added support for Group Managed Service Accounts, implemented using the ExecuteAsGMSA - parameter. Fixes [Issue #111](https://github.com/PowerShell/ComputerManagementDsc/issues/111) - - Added support to set the Synchronize Across Time Zone option. Fixes [Issue #109](https://github.com/PowerShell/ComputerManagementDsc/issues/109) -- Added .VSCode settings for applying DSC PSSA rules - fixes [Issue #189](https://github.com/PowerShell/ComputerManagementDsc/issues/189). -- BREAKING CHANGE: PowerPlan: - - Added IsActive Read-Only Property - Fixes [Issue #171](https://github.com/PowerShell/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 - -- 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 MSFT_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/PowerShell/ComputerManagementDsc/issues/167) - -## 5.1.0.0 - -- TimeZone: - - Migrated xTimeZone resource from [xTimeZone](https://github.com/PowerShell/xTimeZone) - and renamed to TimeZone - fixes [Issue #157](https://github.com/PowerShell/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/PowerShell/ComputerManagementDsc/issues/161) - -## 5.0.0.0 - -- BREAKING CHANGE: - - Renamed ComputerManagement to ComputerManagementDsc - fixes [Issue #119](https://github.com/PowerShell/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 - -- 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 - -- 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 - -- 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 - -- 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 - -- 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 - -- 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 - -- Updated resources - - BREAKING CHANGE: xScheduledTask: Added nearly all available parameters for tasks -- xVirtualMemory: - - Fixed failing tests. - -## 1.10.0.0 - -- Added resources: - - xVirtualMemory - -## 1.9.0.0 - -- Added resources - - xPowerPlan - -## 1.8.0.0 - -- 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 - -- Added support for enabling or disabling scheduled tasks -- The Name parameter resolves to $env:COMPUTERNAME when the value is localhost - -## 1.6.0.0 - -- Added the following resources: - - MSFT_xOfflineDomainJoin resource to join computers to an AD Domain using an - Offline Domain Join request file. - - MSFT_xScheduledTask resource to control scheduled tasks on the local server -- MSFT_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 - -- Update Unit tests to use the standard folder structure and test templates. -- Added .gitignore to prevent commit of DSCResource.Tests. - -## 1.4.0.0 - -- 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 +### Deprecated -- xComputer - - Fixed issue with Test-TargetResource when not specifying Domain or - Workgroup name - - Added tests +- None -## 1.2.2 +### Removed -- Added types to Get/Set/Test definitions to allow xResourceDesigner validation - to succeed +- None -## 1.2 +### Fixed -- Added functionality to enable moving computer from one domain to another -- Modified Test-DscConfiguration logics when testing domain join +- WindowsCapability: + - Fix `A parameter cannot be found that matches parameter name 'Ensure'.` + error in `Test-TargetResource` - Fixes [Issue #297](https://github.com/dsccommunity/ComputerManagementDsc/issues/297). -## 1.0.0.0 +### Security -- Initial release with the following resources: - - xComputer +- None diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 1d5c9eab..d7589ddb 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,6 +1,3 @@ -# Code of conduct +# Code of Conduct -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). -For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) -or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional -questions or comments. +This project has adopted the [DSC Community Code of Conduct](https://dsccommunity.org/code_of_conduct). diff --git a/ComputerManagementDsc.psd1 b/ComputerManagementDsc.psd1 deleted file mode 100644 index 842c8c27..00000000 --- a/ComputerManagementDsc.psd1 +++ /dev/null @@ -1,82 +0,0 @@ -@{ -# Version number of this module. -moduleVersion = '7.1.0.0' - -# ID used to uniquely identify this module -GUID = 'B5004952-489E-43EA-999C-F16A25355B89' - -# Author of this module -Author = 'Microsoft Corporation' - -# Company or vendor of this module -CompanyName = 'Microsoft Corporation' - -# Copyright statement for this module -Copyright = '(c) Microsoft Corporation. All rights reserved.' - -# Description of the functionality provided by this module -Description = 'The ComputerManagementDsc module contains DSC resources for configuration of a Windows computer. These DSC resources allow you to perform computer management tasks, such as renaming the computer, joining a domain and scheduling tasks as well as configuring items such as virtual memory, event logs, time zones and power settings. - -All of the resources in the DSC Resource Kit are provided AS IS, and are not supported through any Microsoft standard support program or service.' - -# Minimum version of the Windows PowerShell engine required by this module -PowerShellVersion = '4.0' - -# Minimum version of the common language runtime (CLR) required by this module -CLRVersion = '4.0' - -# Functions to export from this module -FunctionsToExport = '*' - -# Cmdlets to export from this module -CmdletsToExport = '*' - -# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. -PrivateData = @{ - - PSData = @{ - - # Tags applied to this module. These help with module discovery in online galleries. - Tags = @('DesiredStateConfiguration', 'DSC', 'DSCResourceKit', 'DSCResource') - - # A URL to the license for this module. - LicenseUri = 'https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE' - - # A URL to the main website for this project. - ProjectUri = 'https://github.com/PowerShell/ComputerManagementDsc' - - # A URL to an icon representing this module. - # IconUri = '' - - # ReleaseNotes of this module - ReleaseNotes = '- ComputerManagementDsc: - - Update psd1 description - Fixes [Issue 269](https://github.com/PowerShell/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/PowerShell/ComputerManagementDsc/issues/258). -- SmbShare: - - Removal of duplicate code in Add-SmbShareAccessPermission helper function - fixes [Issue 226](https://github.com/PowerShell/ComputerManagementDsc/issues/226). - -' - - } # End of PSData hashtable - -} # End of PrivateData hashtable -} - - - - - - - - - - - diff --git a/DSCResources/MSFT_WindowsCapability/MSFT_WindowsCapability.schema.mof b/DSCResources/MSFT_WindowsCapability/MSFT_WindowsCapability.schema.mof deleted file mode 100644 index d03ccf72..00000000 --- a/DSCResources/MSFT_WindowsCapability/MSFT_WindowsCapability.schema.mof +++ /dev/null @@ -1,9 +0,0 @@ - -[ClassVersion("1.0.0.1"), FriendlyName("WindowsCapability")] -class MSFT_WindowsCapability : OMI_BaseResource -{ - [Key, Description("Specifies the given name of a Windows Capability")] String Name; - [Write, Description("Specifies whether the Windows Capability should be installed or uninstalled. To install the Windows Capability, set this property to Present. To uninstall the Windows Capability, set the property to Absent."), ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure; - [Write, Description("Specifies the given LogLevel of a Windows Capability."), ValueMap{"Errors", "Warnings", "WarningsInfo"}, Values{"Errors", "Warnings", "WarningsInfo"}] String LogLevel; - [Write, Description("Specifies the full path and file name to log to.")] String LogPath; -}; diff --git a/DSCResources/MSFT_WindowsCapability/README.md b/DSCResources/MSFT_WindowsCapability/README.md deleted file mode 100644 index 874d0a41..00000000 --- a/DSCResources/MSFT_WindowsCapability/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Description - -This resource allows the configuration of a Windows Capability. -It can be used for enabling or disabling Windows Capabilities -and configure the desired Loglevel and Logpath. diff --git a/GitVersion.yml b/GitVersion.yml new file mode 100644 index 00000000..ae02882c --- /dev/null +++ b/GitVersion.yml @@ -0,0 +1,26 @@ +mode: ContinuousDelivery +next-version: 7.4.0 +major-version-bump-message: '\s?(breaking|major|breaking\schange)' +minor-version-bump-message: '\s?(add|feature|minor)' +patch-version-bump-message: '\s?(fix|patch)' +no-bump-message: '\+semver:\s?(none|skip)' +assembly-informational-format: '{NuGetVersionV2}+Sha.{Sha}.Date.{CommitDate}' +branches: + master: + tag: preview + pull-request: + tag: PR + feature: + tag: useBranchName + increment: Minor + regex: f(eature(s)?)?[\/-] + source-branches: ['master'] + hotfix: + tag: fix + increment: Patch + regex: (hot)?fix(es)?[\/-] + source-branches: ['master'] + +ignore: + sha: [] +merge-message-formats: {} diff --git a/HISTORIC_CHANGELOG.md b/HISTORIC_CHANGELOG.md new file mode 100644 index 00000000..08edee21 --- /dev/null +++ b/HISTORIC_CHANGELOG.md @@ -0,0 +1,451 @@ +# 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/LICENSE b/LICENSE index 21071075..be601b58 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,21 @@ - MIT License +MIT License - Copyright (c) Microsoft Corporation. All rights reserved. +Copyright the DSC Community contributors. All rights reserved. - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE diff --git a/README.md b/README.md index 80ad2f4c..ac19b646 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,32 @@ # ComputerManagementDsc +[![Build Status](https://dev.azure.com/dsccommunity/ComputerManagementDsc/_apis/build/status/dsccommunity.ComputerManagementDsc?branchName=master)](https://dev.azure.com/dsccommunity/ComputerManagementDsc/_build/latest?definitionId=16&branchName=master) +![Code Coverage](https://img.shields.io/azure-devops/coverage/dsccommunity/ComputerManagementDsc/16/master) +[![Azure DevOps tests](https://img.shields.io/azure-devops/tests/dsccommunity/ComputerManagementDsc/16/master)](https://dsccommunity.visualstudio.com/ComputerManagementDsc/_test/analytics?definitionId=16&contextType=build) +[![PowerShell Gallery (with prereleases)](https://img.shields.io/powershellgallery/vpre/ComputerManagementDsc?label=ComputerManagementDsc%20Preview)](https://www.powershellgallery.com/packages/ComputerManagementDsc/) +[![PowerShell Gallery](https://img.shields.io/powershellgallery/v/ComputerManagementDsc?label=ComputerManagementDsc)](https://www.powershellgallery.com/packages/ComputerManagementDsc/) + +## Code of Conduct + +This project has adopted [this code of conduct](CODE_OF_CONDUCT.md). + +## Releases + +For each merge to the branch `master` a preview release will be +deployed to [PowerShell Gallery](https://www.powershellgallery.com/). +Periodically a release version tag will be pushed which will deploy a +full release to [PowerShell Gallery](https://www.powershellgallery.com/). + +## Contributing + +Please check out common DSC Community [contributing guidelines](https://dsccommunity.org/guidelines/contributing). + +## Change log + +A full list of changes in each version can be found in the [change log](CHANGELOG.md). + +## Resources + The **ComputerManagementDsc** module contains the following resources: - **Computer**: allows you to configure a computer by changing its name and @@ -40,31 +67,4 @@ This project has adopted [this code of conduct](CODE_OF_CONDUCT.md). ## Documentation and Examples For a full list of resources in ComputerManagementDsc and examples on their use, -check out the [ComputerManagementDsc wiki](https://github.com/PowerShell/ComputerManagementDsc/wiki). - -## Branches - -### master - -[![Build status](https://ci.appveyor.com/api/projects/status/cg28qxeco39wgo9l/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/ComputerManagementDsc/branch/master) -[![codecov](https://codecov.io/gh/PowerShell/ComputerManagementDsc/branch/master/graph/badge.svg)](https://codecov.io/gh/PowerShell/ComputerManagementDsc/branch/master) - -This is the branch containing the latest release - no contributions should be made -directly to this branch. - -### dev - -[![Build status](https://ci.appveyor.com/api/projects/status/cg28qxeco39wgo9l/branch/dev?svg=true)](https://ci.appveyor.com/project/PowerShell/ComputerManagementDsc/branch/dev) -[![codecov](https://codecov.io/gh/PowerShell/ComputerManagementDsc/branch/dev/graph/badge.svg)](https://codecov.io/gh/PowerShell/ComputerManagementDsc/branch/dev) - -This is the development branch to which contributions should be proposed by contributors -as pull requests. This development branch will periodically be merged to the master -branch, and be released to [PowerShell Gallery](https://www.powershellgallery.com/). - -## Contributing - -Please check out common DSC Resources [contributing guidelines](https://github.com/PowerShell/DscResource.Kit/blob/master/CONTRIBUTING.md). - -## Change log - -A full list of changes in each version can be found in the [change log](CHANGELOG.md). +check out the [ComputerManagementDsc wiki](https://github.com/dsccommunity/ComputerManagementDsc/wiki). diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 new file mode 100644 index 00000000..e37ab1af --- /dev/null +++ b/RequiredModules.psd1 @@ -0,0 +1,21 @@ +@{ + # Set up a mini virtual environment... + PSDependOptions = @{ + AddToPath = $true + Target = 'output\RequiredModules' + Parameters = @{ + } + } + + invokeBuild = 'latest' + PSScriptAnalyzer = 'latest' + pester = 'latest' + Plaster = 'latest' + ModuleBuilder = '1.0.0' + ChangelogManagement = 'latest' + Sampler = 'latest' + 'DscResource.Test' = 'latest' + 'DscResource.AnalyzerRules' = 'latest' + xDscResourceDesigner = 'latest' + LoopbackAdapter = 'latest' +} diff --git a/Resolve-Dependency.ps1 b/Resolve-Dependency.ps1 new file mode 100644 index 00000000..ec909b88 --- /dev/null +++ b/Resolve-Dependency.ps1 @@ -0,0 +1,288 @@ +[CmdletBinding()] +param +( + [Parameter()] + [String] + $DependencyFile = 'RequiredModules.psd1', + + [Parameter()] + [String] + # Path for PSDepend to be bootstrapped and save other dependencies. + # Can also be CurrentUser or AllUsers if you wish to install the modules in such scope + # Default to $PWD.Path/output/modules + $PSDependTarget = (Join-Path $PSScriptRoot './output/RequiredModules'), + + [Parameter()] + [uri] + # URI to use for Proxy when attempting to Bootstrap PackageProvider & PowerShellGet + $Proxy, + + [Parameter()] + # Credential to contact the Proxy when provided + [PSCredential]$ProxyCredential, + + [Parameter()] + [ValidateSet('CurrentUser', 'AllUsers')] + [String] + # Scope to bootstrap the PackageProvider and PSGet if not available + $Scope = 'CurrentUser', + + [Parameter()] + [String] + # Gallery to use when bootstrapping PackageProvider, PSGet and when calling PSDepend (can be overridden in Dependency files) + $Gallery = 'PSGallery', + + [Parameter()] + [PSCredential] + # Credentials to use with the Gallery specified above + $GalleryCredential, + + + [Parameter()] + [switch] + # Allow you to use a locally installed version of PowerShellGet older than 1.6.0 (not recommended, default to $false) + $AllowOldPowerShellGetModule, + + [Parameter()] + [String] + # Allow you to specify a minimum version fo PSDepend, if you're after specific features. + $MinimumPSDependVersion, + + [Parameter()] + [Switch] + $AllowPrerelease, + + [Parameter()] + [Switch] + $WithYAML +) + +# Load Defaults for parameters values from Resolve-Dependency.psd1 if not provided as parameter +try +{ + Write-Verbose -Message "Importing Bootstrap default parameters from '$PSScriptRoot/Resolve-Dependency.psd1'." + $ResolveDependencyDefaults = Import-PowerShellDataFile -Path (Join-Path $PSScriptRoot '.\Resolve-Dependency.psd1' -Resolve -ErrorAction Stop) + $ParameterToDefault = $MyInvocation.MyCommand.ParameterSets.Where{ $_.Name -eq $PSCmdlet.ParameterSetName }.Parameters.Keys + if ($ParameterToDefault.Count -eq 0) + { + $ParameterToDefault = $MyInvocation.MyCommand.Parameters.Keys + } + # Set the parameters available in the Parameter Set, or it's not possible to choose yet, so all parameters are an option + foreach ($ParamName in $ParameterToDefault) + { + if (-Not $PSBoundParameters.Keys.Contains($ParamName) -and $ResolveDependencyDefaults.ContainsKey($ParamName)) + { + Write-Verbose -Message "Setting $ParamName with $($ResolveDependencyDefaults[$ParamName])" + try + { + $variableValue = $ResolveDependencyDefaults[$ParamName] + if ($variableValue -is [string]) + { + $variableValue = $ExecutionContext.InvokeCommand.ExpandString($variableValue) + } + $PSBoundParameters.Add($ParamName, $variableValue) + Set-Variable -Name $ParamName -value $variableValue -Force -ErrorAction SilentlyContinue + } + catch + { + Write-Verbose -Message "Error adding default for $ParamName : $($_.Exception.Message)" + } + } + } +} +catch +{ + Write-Warning -Message "Error attempting to import Bootstrap's default parameters from $(Join-Path $PSScriptRoot '.\Resolve-Dependency.psd1'): $($_.Exception.Message)." +} + +Write-Progress -Activity "Bootstrap:" -PercentComplete 0 -CurrentOperation "NuGet Bootstrap" + +if (!(Get-PackageProvider -Name NuGet -ForceBootstrap -ErrorAction SilentlyContinue)) +{ + $providerBootstrapParams = @{ + Name = 'nuget' + force = $true + ForceBootstrap = $true + ErrorAction = 'Stop' + } + + switch ($PSBoundParameters.Keys) + { + 'Proxy' + { + $providerBootstrapParams.Add('Proxy', $Proxy) + } + 'ProxyCredential' + { + $providerBootstrapParams.Add('ProxyCredential', $ProxyCredential) + } + 'Scope' + { + $providerBootstrapParams.Add('Scope', $Scope) + } + } + + if ($AllowPrerelease) + { + $providerBootstrapParams.Add('AllowPrerelease', $true) + } + + Write-Information "Bootstrap: Installing NuGet Package Provider from the web (Make sure Microsoft addresses/ranges are allowed)" + $null = Install-PackageProvider @providerBootstrapParams + $latestNuGetVersion = (Get-PackageProvider -Name NuGet -ListAvailable | Select-Object -First 1).Version.ToString() + Write-Information "Bootstrap: Importing NuGet Package Provider version $latestNuGetVersion to current session." + $Null = Import-PackageProvider -Name NuGet -RequiredVersion $latestNuGetVersion -Force +} + +Write-Progress -Activity "Bootstrap:" -PercentComplete 10 -CurrentOperation "Ensuring Gallery $Gallery is trusted" + +# Fail if the given PSGallery is not Registered +$Policy = (Get-PSRepository $Gallery -ErrorAction Stop).InstallationPolicy +Set-PSRepository -Name $Gallery -InstallationPolicy Trusted -ErrorAction Ignore +try +{ + Write-Progress -Activity "Bootstrap:" -PercentComplete 25 -CurrentOperation "Checking PowerShellGet" + # Ensure the module is loaded and retrieve the version you have + $PowerShellGetVersion = (Import-Module PowerShellGet -PassThru -ErrorAction SilentlyContinue).Version + + Write-Verbose "Bootstrap: The PowerShellGet version is $PowerShellGetVersion" + # Versions below 1.6.0 are considered old, unreliable & not recommended + if (!$PowerShellGetVersion -or ($PowerShellGetVersion -lt [System.version]'1.6.0' -and !$AllowOldPowerShellGetModule)) + { + Write-Progress -Activity "Bootstrap:" -PercentComplete 40 -CurrentOperation "Installing newer version of PowerShellGet" + $InstallPSGetParam = @{ + Name = 'PowerShellGet' + Force = $true + SkipPublisherCheck = $true + AllowClobber = $true + Scope = $Scope + Repository = $Gallery + } + + switch ($PSBoundParameters.Keys) + { + 'Proxy' + { + $InstallPSGetParam.Add('Proxy', $Proxy) + } + 'ProxyCredential' + { + $InstallPSGetParam.Add('ProxyCredential', $ProxyCredential) + } + 'GalleryCredential' + { + $InstallPSGetParam.Add('Credential', $GalleryCredential) + } + } + + Install-Module @InstallPSGetParam + Remove-Module PowerShellGet -force -ErrorAction SilentlyContinue + Import-Module PowerShellGet -Force + $NewLoadedVersion = (Get-Module PowerShellGet).Version.ToString() + Write-Information "Bootstrap: PowerShellGet version loaded is $NewLoadedVersion" + Write-Progress -Activity "Bootstrap:" -PercentComplete 60 -CurrentOperation "Installing newer version of PowerShellGet" + } + + # Try to import the PSDepend module from the available modules + try + { + $ImportPSDependParam = @{ + Name = 'PSDepend' + ErrorAction = 'Stop' + Force = $true + } + + if ($MinimumPSDependVersion) + { + $ImportPSDependParam.add('MinimumVersion', $MinimumPSDependVersion) + } + $null = Import-Module @ImportPSDependParam + } + catch + { + # PSDepend module not found, installing or saving it + if ($PSDependTarget -in 'CurrentUser', 'AllUsers') + { + Write-Debug "PSDepend module not found. Attempting to install from Gallery $Gallery" + Write-Warning "Installing PSDepend in $PSDependTarget Scope" + $InstallPSDependParam = @{ + Name = 'PSDepend' + Repository = $Gallery + Force = $true + Scope = $PSDependTarget + SkipPublisherCheck = $true + AllowClobber = $true + } + + if ($MinimumPSDependVersion) + { + $InstallPSDependParam.add('MinimumVersion', $MinimumPSDependVersion) + } + + Write-Progress -Activity "Bootstrap:" -PercentComplete 75 -CurrentOperation "Installing PSDepend from $Gallery" + Install-Module @InstallPSDependParam + } + else + { + Write-Debug "PSDepend module not found. Attempting to Save from Gallery $Gallery to $PSDependTarget" + $SaveModuleParam = @{ + Name = 'PSDepend' + Repository = $Gallery + Path = $PSDependTarget + } + + if ($MinimumPSDependVersion) + { + $SaveModuleParam.add('MinimumVersion', $MinimumPSDependVersion) + } + + Write-Progress -Activity "Bootstrap:" -PercentComplete 75 -CurrentOperation "Saving & Importing PSDepend from $Gallery to $Scope" + Save-Module @SaveModuleParam + } + } + finally + { + Write-Progress -Activity "Bootstrap:" -PercentComplete 100 -CurrentOperation "Loading PSDepend" + # We should have successfully bootstrapped PSDepend. Fail if not available + Import-Module PSDepend -ErrorAction Stop + } + + if ($WithYAML) + { + if (-Not (Get-Module -ListAvailable -Name 'PowerShell-Yaml')) + { + Write-Verbose "PowerShell-Yaml module not found. Attempting to Save from Gallery $Gallery to $PSDependTarget" + $SaveModuleParam = @{ + Name = 'PowerShell-Yaml' + Repository = $Gallery + Path = $PSDependTarget + } + + Save-Module @SaveModuleParam + Import-Module "PowerShell-Yaml" -ErrorAction Stop + } + else + { + Write-Verbose "PowerShell-Yaml is already available" + } + } + + Write-Progress -Activity "PSDepend:" -PercentComplete 0 -CurrentOperation "Restoring Build Dependencies" + if (Test-Path $DependencyFile) + { + $PSDependParams = @{ + Force = $true + Path = $DependencyFile + } + + # TODO: Handle when the Dependency file is in YAML, and -WithYAML is specified + Invoke-PSDepend @PSDependParams + } + Write-Progress -Activity "PSDepend:" -PercentComplete 100 -CurrentOperation "Dependencies restored" -Completed +} +finally +{ + # Reverting the Installation Policy for the given gallery + Set-PSRepository -Name $Gallery -InstallationPolicy $Policy + Write-Verbose "Project Bootstrapped, returning to Invoke-Build" +} diff --git a/Resolve-Dependency.psd1 b/Resolve-Dependency.psd1 new file mode 100644 index 00000000..2ae8c0da --- /dev/null +++ b/Resolve-Dependency.psd1 @@ -0,0 +1,5 @@ +@{ + Gallery = 'PSGallery' + AllowPrerelease = $false + WithYAML = $true +} diff --git a/Tests/Integration/MSFT_PendingReboot.Tests.ps1 b/Tests/Integration/MSFT_PendingReboot.Tests.ps1 deleted file mode 100644 index fc77d271..00000000 --- a/Tests/Integration/MSFT_PendingReboot.Tests.ps1 +++ /dev/null @@ -1,122 +0,0 @@ -#region HEADER -$script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_PendingReboot' - -# Integration Test Template Version: 1.3.3 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -TestType Integration -#endregion - -try -{ - $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" - . $configFile - - Describe "$($script:dscResourceName)_Integration" { - <# - These integration tests will not actually reboot the node - because that would terminate the tests and cause them to fail. - - There does not appear to be a method of determining if the - reboot is in fact triggered, so this is not currently tested. - - Instead, we will preserve the current state of the Auto Update - 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. - #> - $windowsUpdateKeys = (Get-ChildItem -Path $rebootRegistryKeys.WindowsUpdate).Name - - if ($windowsUpdateKeys) - { - $script:currentAutoUpdateRebootState = $windowsUpdateKeys.Split('\') -contains 'RebootRequired' - } - - if (-not $script:currentAutoUpdateRebootState) - { - $null = New-Item ` - -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\' ` - -Name 'RebootRequired' - } - - $configData = @{ - AllNodes = @( - @{ - NodeName = 'localhost' - RebootName = 'TestReboot' - SkipComponentBasedServicing = $false - SkipWindowsUpdate = $false - SkipPendingFileRename = $false - SkipPendingComputerRename = $false - SkipCcmClientSDK = $true - } - ) - } - - It 'Should compile and apply the MOF without throwing' { - { - & "$($script:dscResourceName)_Config" ` - -OutputPath $TestDrive ` - -ConfigurationData $configData - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { - Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { - $_.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 - } - } -} -finally -{ - #region FOOTER - if (-not $script:currentAutoUpdateRebootState) - { - $null = Remove-Item ` - -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired' ` - -ErrorAction SilentlyContinue - } - - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion -} diff --git a/Tests/Integration/MSFT_PowerShellExecutionPolicy.Integration.Tests.ps1 b/Tests/Integration/MSFT_PowerShellExecutionPolicy.Integration.Tests.ps1 deleted file mode 100644 index 46671a70..00000000 --- a/Tests/Integration/MSFT_PowerShellExecutionPolicy.Integration.Tests.ps1 +++ /dev/null @@ -1,68 +0,0 @@ -#region HEADER -$script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_PowerShellExecutionPolicy' - -# Integration Test Template Version: 1.3.3 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -TestType Integration -#endregion - -try -{ - #region Integration Tests - $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" - . $configFile - - Describe "$($script:dscResourceName)_Integration" { - #region DEFAULT TESTS - It 'Should compile and apply the MOF without throwing' { - { - & "$($script:dscResourceName)_Config" -OutputPath $TestDrive - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { - Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw - } - #endregion - - It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { - $_.ConfigurationName -eq "$($script:dscResourceName)_Config" - } - $current.ExecutionPolicy | Should -Be 'RemoteSigned' - $current.ExecutionPolicyScope | Should -Be 'LocalMachine' - } - } - #endregion - -} -finally -{ - #region FOOTER - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion -} diff --git a/Tests/Integration/MSFT_RemoteDesktopAdmin.Integration.Tests.ps1 b/Tests/Integration/MSFT_RemoteDesktopAdmin.Integration.Tests.ps1 deleted file mode 100644 index 53aadb2e..00000000 --- a/Tests/Integration/MSFT_RemoteDesktopAdmin.Integration.Tests.ps1 +++ /dev/null @@ -1,171 +0,0 @@ -#region HEADER -$script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_RemoteDesktopAdmin' - -# Integration Test Template Version: 1.3.3 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -TestType Integration -#endregion - -# Using try/finally to always cleanup. -try -{ - #region Integration Tests - $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" - . $configFile - - $script:tSRegistryKey = 'HKLM:\System\CurrentControlSet\Control\Terminal Server' - $script:winStationsRegistryKey = 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' - - Describe "$($script:dscResourceName)_Integration" { - Context 'When setting Remote Desktop for Administration to Denied' { - $CurrentConfig = 'setToDenied' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file without error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -Be $true - } - - It 'Should return the correct values from Get-DscConfiguration' { - $Current = Get-DscConfiguration | Where-Object -FilterScript {$_.ConfigurationName -eq $CurrentConfig} - $Current.IsSingleInstance | Should -Be 'Yes' - $Current.Ensure | Should -Be 'Absent' - } - - It 'Should have set the correct registry values' { - (Get-ItemProperty -Path $script:tSRegistryKey -Name 'fDenyTSConnections').fDenyTSConnections | Should -Be 1 - } - } - - Context 'When setting Remote Desktop for Administration to Allowed' { - $CurrentConfig = 'setToAllowed' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file without error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -Be $true - } - - It 'Should return the correct values from Get-DscConfiguration' { - $Current = Get-DscConfiguration | Where-Object -FilterScript {$_.ConfigurationName -eq $CurrentConfig} - $Current.IsSingleInstance | Should -Be 'Yes' - $Current.Ensure | Should -Be 'Present' - } - - It 'Should have set the correct registry values' { - (Get-ItemProperty -Path $script:tSRegistryKey -Name 'fDenyTSConnections').fDenyTSConnections | Should -Be 0 - } - } - - Context 'When settting Remote Desktop for Administration to Allowed with Secure Authentication' { - $CurrentConfig = 'setToAllowedSecure' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file without error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -Be $true - } - - It 'Should return the correct values from Get-DscConfiguration' { - $Current = Get-DscConfiguration | Where-Object -FilterScript {$_.ConfigurationName -eq $CurrentConfig} - $Current.IsSingleInstance | Should -Be 'Yes' - $Current.Ensure | Should -Be 'Present' - $Current.UserAuthentication | Should -Be 'Secure' - } - - It 'Should have set the correct registry values' { - (Get-ItemProperty -Path $script:tSRegistryKey -Name 'fDenyTSConnections').fDenyTSConnections | Should -Be 0 - (Get-ItemProperty -Path $script:winStationsRegistryKey -Name 'UserAuthentication').UserAuthentication | Should -Be 1 - } - } - - Context 'When settting Remote Desktop for Administration to Allowed with NonSecure Authentication' { - $CurrentConfig = 'setToAllowedNonSecure' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file without error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -Be $true - } - - It 'Should return the correct values from Get-DscConfiguration' { - $Current = Get-DscConfiguration | Where-Object -FilterScript {$_.ConfigurationName -eq $CurrentConfig} - $Current.IsSingleInstance | Should -Be 'Yes' - $Current.Ensure | Should -Be 'Present' - $Current.UserAuthentication | Should -Be 'NonSecure' - } - - It 'Should have set the correct registry values' { - (Get-ItemProperty -Path $script:tSRegistryKey -Name 'fDenyTSConnections').fDenyTSConnections | Should -Be 0 - (Get-ItemProperty -Path $script:winStationsRegistryKey -Name 'UserAuthentication').UserAuthentication | Should -Be 0 - } - } - } -} -finally -{ - #region FOOTER - - Restore-TestEnvironment -TestEnvironment $TestEnvironment - - #endregion -} diff --git a/Tests/Integration/MSFT_ScheduledTask.Integration.Tests.ps1 b/Tests/Integration/MSFT_ScheduledTask.Integration.Tests.ps1 deleted file mode 100644 index 2279c5f5..00000000 --- a/Tests/Integration/MSFT_ScheduledTask.Integration.Tests.ps1 +++ /dev/null @@ -1,395 +0,0 @@ -#Requires -Version 5.0 -#region HEADER -$script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_ScheduledTask' - -# Integration Test Template Version: 1.3.3 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -TestType Integration -#endregion - -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global - -# Load the ComputerManagementDsc.Common module to use Set-TimezoneId function -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'Modules' -ChildPath 'ComputerManagementDsc.Common')) -Force - -# Begin Testing -try -{ - $ConfigFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" - . $ConfigFile - - #region Pester Tests - Describe $script:dscResourceName { - - $contexts = @{ - Once = 'ScheduledTaskOnce' - Daily = 'ScheduledTaskDaily' - DailyIndefinitely = 'ScheduledTaskDailyIndefinitely' - Weekly = 'ScheduledTaskWeekly' - AtLogon = 'ScheduledTaskLogon' - AtStartup = 'ScheduledTaskStartup' - ExecuteAs = 'ScheduledTaskExecuteAs' - ExecuteAsGroup = 'ScheduledTaskExecuteAsGroup' - OnEvent = 'ScheduledTaskOnEvent' - } - - $configData = @{ - AllNodes = @( - @{ - NodeName = 'localhost' - PSDscAllowPlainTextPassword = $true - } - ) - } - - foreach ($contextInfo in $contexts.GetEnumerator()) - { - Context "[$($contextInfo.Key)] No scheduled task exists but it should" { - $currentConfig = '{0}Add' -f $contextInfo.Value - $configDir = (Join-Path -Path $TestDrive -ChildPath $currentConfig) - $configMof = (Join-Path -Path $configDir -ChildPath 'localhost.mof') - - It 'Should compile the MOF without throwing' { - { - . $currentConfig ` - -OutputPath $configDir ` - -ConfigurationData $configData - } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration ` - -Path $configDir ` - -Wait ` - -Force ` - -Verbose ` - -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $configMof -Verbose).InDesiredState | Should -BeTrue - } - } - - Context "[$($contextInfo.Key)] A scheduled task exists with the wrong settings" { - $currentConfig = '{0}Mod' -f $contextInfo.Value - $configDir = (Join-Path -Path $TestDrive -ChildPath $currentConfig) - $configMof = (Join-Path -Path $configDir -ChildPath 'localhost.mof') - - It 'Should compile the MOF without throwing' { - { - . $currentConfig ` - -OutputPath $configDir ` - -ConfigurationData $configData - } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration ` - -Path $configDir ` - -Wait ` - -Force ` - -Verbose ` - -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $configMof -Verbose).InDesiredState | Should -BeTrue - } - } - - Context "[$($contextInfo.Key)] A scheduled tasks exists but it should not" { - $currentConfig = '{0}Del' -f $contextInfo.Value - $configDir = (Join-Path -Path $TestDrive -ChildPath $currentConfig) - $configMof = (Join-Path -Path $configDir -ChildPath 'localhost.mof') - - It 'Should compile the MOF without throwing' { - { - . $currentConfig ` - -OutputPath $configDir ` - -ConfigurationData $configData - } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration ` - -Path $configDir ` - -Wait ` - -Force ` - -Verbose ` - -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $configMof -Verbose).InDesiredState | Should -BeTrue - } - } - } - - Context "MOF is created in a different timezone to node MOF being applied to" { - BeforeAll { - $currentTimeZoneId = Get-TimeZoneId - } - - $currentConfig = 'ScheduledTaskOnceCrossTimezone' - $configDir = (Join-Path -Path $TestDrive -ChildPath $currentConfig) - $configMof = (Join-Path -Path $configDir -ChildPath 'localhost.mof') - - It 'Should compile the MOF without throwing in W. Australia Standard Time Timezone' { - { - - Set-TimeZoneId -TimeZoneId 'W. Australia Standard Time' - . $currentConfig ` - -OutputPath $configDir - } | Should -Not -Throw - } - - It 'Should apply the MOF correctly in New Zealand Standard Time Timezone' { - { - Set-TimeZoneId -TimeZoneId 'New Zealand Standard Time' - Start-DscConfiguration ` - -Path $configDir ` - -Wait ` - -Force ` - -Verbose ` - -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $configMof -Verbose).InDesiredState | Should -BeTrue - } - - It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript {$_.ConfigurationName -eq $currentConfig} - $current.TaskName | Should -Be 'Test task once cross timezone' - $current.TaskPath | Should -Be '\ComputerManagementDsc\' - $current.ActionExecutable | Should -Be 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' - $current.ScheduleType | Should -Be 'Once' - $current.RepeatInterval | Should -Be '00:15:00' - $current.RepetitionDuration | Should -Be '23:00:00' - $current.ActionWorkingPath | Should -Be (Get-Location).Path - $current.Enable | Should -BeTrue - $current.RandomDelay | Should -Be '01:00:00' - $current.DisallowHardTerminate | Should -BeTrue - $current.RunOnlyIfIdle | Should -BeFalse - $current.Priority | Should -Be 9 - $current.RunLevel | Should -Be 'Limited' - $current.ExecutionTimeLimit | Should -Be '00:00:00' - } - - AfterAll { - Set-TimeZoneId -TimeZoneId $currentTimeZoneId - } - } - - Context "When a scheduled task is created and synchronize across time zone is disabled" { - $currentConfig = 'ScheduledTaskOnceSynchronizeAcrossTimeZoneDisabled' - $configDir = (Join-Path -Path $TestDrive -ChildPath $currentConfig) - $configMof = (Join-Path -Path $configDir -ChildPath 'localhost.mof') - - It 'Should compile the MOF without throwing' { - { - . $currentConfig ` - -OutputPath $configDir - } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration ` - -Path $configDir ` - -Wait ` - -Force ` - -Verbose ` - -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $configMof -Verbose).InDesiredState | Should -BeTrue - } - - $expectedStartTime = '2018-10-01T01:00:00' - - It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript {$_.ConfigurationName -eq $currentConfig} - $current.TaskName | Should -Be 'Test task sync across time zone disabled' - $current.TaskPath | Should -Be '\ComputerManagementDsc\' - $current.ActionExecutable | Should -Be 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' - $current.ScheduleType | Should -Be 'Once' - $current.StartTime | Should -Be (Get-Date -Date $expectedStartTime) - $current.SynchronizeAcrossTimeZone | Should -BeFalse - $current.ActionWorkingPath | Should -Be (Get-Location).Path - $current.Enable | Should -BeTrue - } - - It "Should have the trigger startBoundary set to $expectedStartTime" { - $task = (Get-ScheduledTask -TaskName 'Test task sync across time zone disabled') - $task.Triggers[0].StartBoundary | Should -Be $expectedStartTime - } - } - - Context "When a scheduled task is created and synchronize across time zone is enabled" { - $currentConfig = 'ScheduledTaskOnceSynchronizeAcrossTimeZoneEnabled' - $configDir = (Join-Path -Path $TestDrive -ChildPath $currentConfig) - $configMof = (Join-Path -Path $configDir -ChildPath 'localhost.mof') - - It 'Should compile the MOF without throwing' { - { - . $currentConfig ` - -OutputPath $configDir - } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration ` - -Path $configDir ` - -Wait ` - -Force ` - -Verbose ` - -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $configMof -Verbose).InDesiredState | Should -BeTrue - } - - $expectedStartTime = '2018-10-01T01:00:00' + (Get-Date -Format 'zzz') - - It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript {$_.ConfigurationName -eq $currentConfig} - $current.TaskName | Should -Be 'Test task sync across time zone enabled' - $current.TaskPath | Should -Be '\ComputerManagementDsc\' - $current.ActionExecutable | Should -Be 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' - $current.ScheduleType | Should -Be 'Once' - $current.StartTime | Should -Be (Get-Date -Date $expectedStartTime) - $current.SynchronizeAcrossTimeZone | Should -BeTrue - $current.ActionWorkingPath | Should -Be (Get-Location).Path - $current.Enable | Should -BeTrue - } - - It "Should have the trigger startBoundary set to $expectedStartTime" { - $task = (Get-ScheduledTask -TaskName 'Test task sync across time zone enabled') - $task.Triggers[0].StartBoundary | Should -Be $expectedStartTime - } - } - - # Simulate a "built-in" scheduled task - $action = New-ScheduledTaskAction -Execute 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' - $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) - $task = New-ScheduledTask -Action $action -Trigger $trigger - Register-ScheduledTask -InputObject $task -TaskName 'Test task builtin' -TaskPath '\ComputerManagementDsc\' -User 'NT AUTHORITY\SYSTEM' - - Context 'Built-in task needs to be disabled' { - $currentConfig = 'ScheduledTaskDisableBuiltIn' - $configDir = (Join-Path -Path $TestDrive -ChildPath $currentConfig) - $configMof = (Join-Path -Path $configDir -ChildPath 'localhost.mof') - - It 'Should compile the MOF without throwing' { - { - . $currentConfig ` - -OutputPath $configDir ` - -ConfigurationData $configData - } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration ` - -Path $configDir ` - -Wait ` - -Force ` - -Verbose ` - -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $configMof -Verbose).InDesiredState | Should -BeTrue - } - - It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { - $_.ConfigurationName -eq $currentConfig - } - $current.TaskName | Should -Be 'Test task builtin' - $current.TaskPath | Should -Be '\ComputerManagementDsc\' - $current.Enable | Should -BeFalse - } - } - - Context 'Built-in task needs to be removed' { - $currentConfig = 'ScheduledTaskRemoveBuiltIn' - $configDir = (Join-Path -Path $TestDrive -ChildPath $currentConfig) - $configMof = (Join-Path -Path $configDir -ChildPath 'localhost.mof') - - - It 'Should compile the MOF without throwing' { - { - . $currentConfig ` - -OutputPath $configDir ` - -ConfigurationData $configData - } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration ` - -Path $configDir ` - -Wait ` - -Force ` - -Verbose ` - -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $configMof -Verbose).InDesiredState | Should -BeTrue - } - - It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { - $_.ConfigurationName -eq $currentConfig - } - $current.TaskName | Should -Be 'Test task builtin' - $current.TaskPath | Should -Be '\ComputerManagementDsc\' - $current.Ensure | Should -Be 'Absent' - } - } - } -} -finally -{ - #region FOOTER - - # Remove any traces of the created tasks - Get-ScheduledTask -TaskPath '\ComputerManagementDsc\' -ErrorAction SilentlyContinue | Unregister-ScheduledTask -ErrorAction SilentlyContinue -Confirm:$false - - $scheduler = New-Object -ComObject Schedule.Service - $scheduler.Connect() - $rootFolder = $scheduler.GetFolder('\') - $rootFolder.DeleteFolder('ComputerManagementDsc', 0) - - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion -} diff --git a/Tests/Integration/MSFT_SmbServerConfiguration.Tests.ps1 b/Tests/Integration/MSFT_SmbServerConfiguration.Tests.ps1 deleted file mode 100644 index 712789a9..00000000 --- a/Tests/Integration/MSFT_SmbServerConfiguration.Tests.ps1 +++ /dev/null @@ -1,203 +0,0 @@ -#region HEADER -$script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_SmbServerConfiguration' - -# Integration Test Template Version: 1.3.3 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -TestType Integration -#endregion - -$script:CurrentSmbServerConfigBackup = Get-SmbServerConfiguration - -try -{ - $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" - . $configFile - - Describe "$($script:dscResourceName)_Integration" { - - $configData = @{ - AllNodes = @( - @{ - NodeName = 'localhost' - IsSingleInstance = 'Yes' - AnnounceComment = 'Test String' - AnnounceServer = $true - AsynchronousCredits = 32 - AuditSmb1Access = $true - AutoDisconnectTimeout = 30 - AutoShareServer = $false - AutoShareWorkstation = $false - CachedOpenLimit = 20 - DurableHandleV2TimeoutInSeconds = 90 - EnableAuthenticateUserSharing = $true - EnableDownlevelTimewarp = $true - EnableForcedLogoff = $false - EnableLeasing = $false - EnableMultiChannel = $false - EnableOplocks = $false - EnableSecuritySignature = $true - EnableSMB1Protocol = $false - EnableSMB2Protocol = $false - EnableStrictNameChecking = $false - EncryptData = $true - IrpStackSize = 20 - KeepAliveTime = 3 - MaxChannelPerSession = 16 - MaxMpxCount = 100 - MaxSessionPerConnection = 16000 - MaxThreadsPerQueue = 15 - MaxWorkItems = 2 - NullSessionPipes = 'TestPipe' - NullSessionShares = 'TestShare' - OplockBreakWait = 30 - PendingClientTimeoutInSeconds = 60 - RejectUnencryptedAccess = $false - RequireSecuritySignature = $true - ServerHidden = $false - Smb2CreditsMax = 2000 - Smb2CreditsMin = 256 - SmbServerNameHardeningLevel = 1 - TreatHostAsStableStorage = $true - ValidateAliasNotCircular = $false - ValidateShareScope = $false - ValidateShareScopeNotAliased = $false - ValidateTargetName = $false - } - ) - } - - It 'Should compile and apply the MOF without throwing' { - { - & "$($script:dscResourceName)_Config" ` - -OutputPath $TestDrive ` - -ConfigurationData $configData - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { - Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { - $_.ConfigurationName -eq "$($script:dscResourceName)_Config" - } - $current.AnnounceComment | Should -Be $configData.AllNodes[0].AnnounceComment - $current.AnnounceServer | Should -Be $configData.AllNodes[0].AnnounceServer - $current.AsynchronousCredits | Should -Be $configData.AllNodes[0].AsynchronousCredits - $current.AuditSmb1Access | Should -Be $configData.AllNodes[0].AuditSmb1Access - $current.AutoDisconnectTimeout | Should -Be $configData.AllNodes[0].AutoDisconnectTimeout - $current.AutoShareServer | Should -Be $configData.AllNodes[0].AutoShareServer - $current.AutoShareWorkstation | Should -Be $configData.AllNodes[0].AutoShareWorkstation - $current.CachedOpenLimit | Should -Be $configData.AllNodes[0].CachedOpenLimit - $current.DurableHandleV2TimeoutInSeconds | Should -Be $configData.AllNodes[0].DurableHandleV2TimeoutInSeconds - $current.EnableAuthenticateUserSharing | Should -Be $configData.AllNodes[0].EnableAuthenticateUserSharing - $current.EnableDownlevelTimewarp | Should -Be $configData.AllNodes[0].EnableDownlevelTimewarp - $current.EnableForcedLogoff | Should -Be $configData.AllNodes[0].EnableForcedLogoff - $current.EnableLeasing | Should -Be $configData.AllNodes[0].EnableLeasing - $current.EnableMultiChannel | Should -Be $configData.AllNodes[0].EnableMultiChannel - $current.EnableOplocks | Should -Be $configData.AllNodes[0].EnableOplocks - $current.EnableSecuritySignature | Should -Be $configData.AllNodes[0].EnableSecuritySignature - $current.EnableSMB1Protocol | Should -Be $configData.AllNodes[0].EnableSMB1Protocol - $current.EnableSMB2Protocol | Should -Be $configData.AllNodes[0].EnableSMB2Protocol - $current.EnableStrictNameChecking | Should -Be $configData.AllNodes[0].EnableStrictNameChecking - $current.EncryptData | Should -Be $configData.AllNodes[0].EncryptData - $current.IrpStackSize | Should -Be $configData.AllNodes[0].IrpStackSize - $current.KeepAliveTime | Should -Be $configData.AllNodes[0].KeepAliveTime - $current.MaxChannelPerSession | Should -Be $configData.AllNodes[0].MaxChannelPerSession - $current.MaxMpxCount | Should -Be $configData.AllNodes[0].MaxMpxCount - $current.MaxSessionPerConnection | Should -Be $configData.AllNodes[0].MaxSessionPerConnection - $current.MaxThreadsPerQueue | Should -Be $configData.AllNodes[0].MaxThreadsPerQueue - $current.MaxWorkItems | Should -Be $configData.AllNodes[0].MaxWorkItems - $current.NullSessionPipes | Should -Be $configData.AllNodes[0].NullSessionPipes - $current.NullSessionShares | Should -Be $configData.AllNodes[0].NullSessionShares - $current.OplockBreakWait | Should -Be $configData.AllNodes[0].OplockBreakWait - $current.PendingClientTimeoutInSeconds | Should -Be $configData.AllNodes[0].PendingClientTimeoutInSeconds - $current.RejectUnencryptedAccess | Should -Be $configData.AllNodes[0].RejectUnencryptedAccess - $current.RequireSecuritySignature | Should -Be $configData.AllNodes[0].RequireSecuritySignature - $current.ServerHidden | Should -Be $configData.AllNodes[0].ServerHidden - $current.Smb2CreditsMax | Should -Be $configData.AllNodes[0].Smb2CreditsMax - $current.Smb2CreditsMin | Should -Be $configData.AllNodes[0].Smb2CreditsMin - $current.SmbServerNameHardeningLevel | Should -Be $configData.AllNodes[0].SmbServerNameHardeningLevel - $current.TreatHostAsStableStorage | Should -Be $configData.AllNodes[0].TreatHostAsStableStorage - $current.ValidateAliasNotCircular | Should -Be $configData.AllNodes[0].ValidateAliasNotCircular - $current.ValidateShareScope | Should -Be $configData.AllNodes[0].ValidateShareScope - $current.ValidateShareScopeNotAliased | Should -Be $configData.AllNodes[0].ValidateShareScopeNotAliased - $current.ValidateTargetName | Should -Be $configData.AllNodes[0].ValidateTargetName - } - } -} -finally -{ - #region FOOTER - Set-SmbServerConfiguration -AnnounceComment $script:CurrentSmbServerConfigBackup.AnnounceComment ` - -AnnounceServer $script:CurrentSmbServerConfigBackup.AnnounceServer ` - -AsynchronousCredits $script:CurrentSmbServerConfigBackup.AsynchronousCredits ` - -AuditSmb1Access $script:CurrentSmbServerConfigBackup.AuditSmb1Access ` - -AutoDisconnectTimeout $script:CurrentSmbServerConfigBackup.AutoDisconnectTimeout ` - -AutoShareServer $script:CurrentSmbServerConfigBackup.AutoShareServer ` - -AutoShareWorkstation $script:CurrentSmbServerConfigBackup.AutoShareWorkstation ` - -CachedOpenLimit $script:CurrentSmbServerConfigBackup.CachedOpenLimit ` - -DurableHandleV2TimeoutInSeconds $script:CurrentSmbServerConfigBackup.DurableHandleV2TimeoutInSeconds ` - -EnableAuthenticateUserSharing $script:CurrentSmbServerConfigBackup.EnableAuthenticateUserSharing ` - -EnableDownlevelTimewarp $script:CurrentSmbServerConfigBackup.EnableDownlevelTimewarp ` - -EnableForcedLogoff $script:CurrentSmbServerConfigBackup.EnableForcedLogoff ` - -EnableLeasing $script:CurrentSmbServerConfigBackup.EnableLeasing ` - -EnableMultiChannel $script:CurrentSmbServerConfigBackup.EnableMultiChannel ` - -EnableOplocks $script:CurrentSmbServerConfigBackup.EnableOplocks ` - -EnableSecuritySignature $script:CurrentSmbServerConfigBackup.EnableSecuritySignature ` - -EnableSMB1Protocol $script:CurrentSmbServerConfigBackup.EnableSMB1Protocol ` - -EnableSMB2Protocol $script:CurrentSmbServerConfigBackup.EnableSMB2Protocol ` - -EnableStrictNameChecking $script:CurrentSmbServerConfigBackup.EnableStrictNameChecking ` - -EncryptData $script:CurrentSmbServerConfigBackup.EncryptData ` - -IrpStackSize $script:CurrentSmbServerConfigBackup.IrpStackSize ` - -KeepAliveTime $script:CurrentSmbServerConfigBackup.KeepAliveTime ` - -MaxChannelPerSession $script:CurrentSmbServerConfigBackup.MaxChannelPerSession ` - -MaxMpxCount $script:CurrentSmbServerConfigBackup.MaxMpxCount ` - -MaxSessionPerConnection $script:CurrentSmbServerConfigBackup.MaxSessionPerConnection ` - -MaxThreadsPerQueue $script:CurrentSmbServerConfigBackup.MaxThreadsPerQueue ` - -MaxWorkItems $script:CurrentSmbServerConfigBackup.MaxWorkItems ` - -NullSessionPipes $script:CurrentSmbServerConfigBackup.NullSessionPipes ` - -NullSessionShares $script:CurrentSmbServerConfigBackup.NullSessionShares ` - -OplockBreakWait $script:CurrentSmbServerConfigBackup.OplockBreakWait ` - -PendingClientTimeoutInSeconds $script:CurrentSmbServerConfigBackup.PendingClientTimeoutInSeconds ` - -RejectUnencryptedAccess $script:CurrentSmbServerConfigBackup.RejectUnencryptedAccess ` - -RequireSecuritySignature $script:CurrentSmbServerConfigBackup.RequireSecuritySignature ` - -ServerHidden $script:CurrentSmbServerConfigBackup.ServerHidden ` - -Smb2CreditsMax $script:CurrentSmbServerConfigBackup.Smb2CreditsMax ` - -Smb2CreditsMin $script:CurrentSmbServerConfigBackup.Smb2CreditsMin ` - -SmbServerNameHardeningLevel $script:CurrentSmbServerConfigBackup.SmbServerNameHardeningLevel ` - -TreatHostAsStableStorage $script:CurrentSmbServerConfigBackup.TreatHostAsStableStorage ` - -ValidateAliasNotCircular $script:CurrentSmbServerConfigBackup.ValidateAliasNotCircular ` - -ValidateShareScope $script:CurrentSmbServerConfigBackup.ValidateShareScope ` - -ValidateShareScopeNotAliased $script:CurrentSmbServerConfigBackup.ValidateShareScopeNotAliased ` - -ValidateTargetName $script:CurrentSmbServerConfigBackup.ValidateTargetName ` - -Confirm:$false - - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion -} diff --git a/Tests/Integration/MSFT_SmbShare.Integration.Tests.ps1 b/Tests/Integration/MSFT_SmbShare.Integration.Tests.ps1 deleted file mode 100644 index c2ef5458..00000000 --- a/Tests/Integration/MSFT_SmbShare.Integration.Tests.ps1 +++ /dev/null @@ -1,484 +0,0 @@ -<# - .SYNOPSIS - Integration tests for DSC resource SmbShare. -#> - -#region HEADER -$script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceFriendlyName = 'SmbShare' -$script:dscResourceName = "MSFT_$($script:dscResourceFriendlyName)" - -# Integration Test Template Version: 1.3.3 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -TestType Integration -#endregion - -#region HEADER - -$script:dscResourceFriendlyName = 'SmbShare' -$script:dcsResourceName = "MSFT_$($script:dscResourceFriendlyName)" - -#region Integration Tests -$configurationFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dcsResourceName).config.ps1" -. $configurationFile - -Describe "$($script:dcsResourceName)_Integration" { - $configurationName = "$($script:dcsResourceName)_Prerequisites_Config" - - Context ('When using configuration {0}' -f $configurationName) { - It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw - } - } - - $configurationName = "$($script:dcsResourceName)_CreateShare1_Config" - - Context ('When using configuration {0}' -f $configurationName) { - It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should have set the resource and all the parameters should match' { - $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { - $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq "[$($script:dscResourceFriendlyName)]Integration_Test" - } - - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.ShareName1 - $resourceCurrentState.Path | Should -Be $ConfigurationData.AllNodes.SharePath1 - $resourceCurrentState.Description | Should -BeNullOrEmpty - $resourceCurrentState.EncryptData | Should -BeFalse - $resourceCurrentState.ConcurrentUserLimit | Should -Be 0 - $resourceCurrentState.Description | Should -BeNullOrEmpty - $resourceCurrentState.CachingMode | Should -Be 'Manual' - $resourceCurrentState.ContinuouslyAvailable | Should -BeFalse - $resourceCurrentState.ShareState | Should -Be 'Online' - $resourceCurrentState.ShareType | Should -Be 'FileSystemDirectory' - $resourceCurrentState.ShadowCopy | Should -BeFalse - $resourceCurrentState.Special | Should -BeFalse - $resourceCurrentState.FullAccess | Should -BeNullOrEmpty - $resourceCurrentState.ChangeAccess | Should -BeNullOrEmpty - $resourceCurrentState.NoAccess | Should -BeNullOrEmpty - - <# - By design of the cmdlet `New-SmbShare`, the Everyone group is - always added when not providing any access permission members - in the configuration. - #> - $resourceCurrentState.ReadAccess | Should -HaveCount 1 - $resourceCurrentState.ReadAccess | Should -Contain 'Everyone' - } - - It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -BeTrue - } - } - - $configurationName = "$($script:dcsResourceName)_CreateShare2_Config" - - Context ('When using configuration {0}' -f $configurationName) { - It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should have set the resource and all the parameters should match' { - $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { - $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq "[$($script:dscResourceFriendlyName)]Integration_Test" - } - - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.ShareName2 - $resourceCurrentState.Path | Should -Be $ConfigurationData.AllNodes.SharePath2 - $resourceCurrentState.Description | Should -BeNullOrEmpty - $resourceCurrentState.EncryptData | Should -BeFalse - $resourceCurrentState.ConcurrentUserLimit | Should -Be 0 - $resourceCurrentState.Description | Should -BeNullOrEmpty - $resourceCurrentState.CachingMode | Should -Be 'Manual' - $resourceCurrentState.ContinuouslyAvailable | Should -BeFalse - $resourceCurrentState.ShareState | Should -Be 'Online' - $resourceCurrentState.ShareType | Should -Be 'FileSystemDirectory' - $resourceCurrentState.ShadowCopy | Should -BeFalse - $resourceCurrentState.Special | Should -BeFalse - $resourceCurrentState.FullAccess | Should -BeNullOrEmpty - $resourceCurrentState.ReadAccess | Should -BeNullOrEmpty - $resourceCurrentState.NoAccess | Should -BeNullOrEmpty - - <# - By design of the cmdlet `New-SmbShare`, the Everyone group is - always added when using `ReadAccess = @()` in the configuration. - #> - $resourceCurrentState.ChangeAccess | Should -HaveCount 1 - $resourceCurrentState.ChangeAccess | Should -Contain $ConfigurationData.AllNodes.UserName1 - } - - It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -BeTrue - } - } - - $configurationName = "$($script:dcsResourceName)_UpdateProperties_Config" - - Context ('When using configuration {0}' -f $configurationName) { - It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should have set the resource and all the parameters should match' { - $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { - $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq "[$($script:dscResourceFriendlyName)]Integration_Test" - } - - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.ShareName1 - $resourceCurrentState.Path | Should -Be $ConfigurationData.AllNodes.SharePath1 - $resourceCurrentState.Description | Should -Be 'A new description' - #$resourceCurrentState.EncryptData | Should -BeTrue - $resourceCurrentState.ConcurrentUserLimit | Should -Be 20 - #$resourceCurrentState.FolderEnumerationMode | Should -Be 'AccessBased' - #$resourceCurrentState.CachingMode | Should -Be 'None' - #$resourceCurrentState.ContinuouslyAvailable | Should -BeTrue - $resourceCurrentState.ShareState | Should -Be 'Online' - $resourceCurrentState.ShareType | Should -Be 'FileSystemDirectory' - $resourceCurrentState.ShadowCopy | Should -BeFalse - $resourceCurrentState.Special | Should -BeFalse - - $resourceCurrentState.FullAccess | Should -HaveCount 1 - $resourceCurrentState.FullAccess | Should -Contain $ConfigurationData.AllNodes.UserName1 - - $resourceCurrentState.ChangeAccess | Should -HaveCount 1 - $resourceCurrentState.ChangeAccess | Should -Contain $ConfigurationData.AllNodes.UserName2 - - $resourceCurrentState.ReadAccess | Should -HaveCount 1 - $resourceCurrentState.ReadAccess | Should -Contain $ConfigurationData.AllNodes.UserName3 - - $resourceCurrentState.NoAccess | Should -HaveCount 1 - $resourceCurrentState.NoAccess | Should -Contain $ConfigurationData.AllNodes.UserName4 - } - - It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -BeTrue - } - } - - $configurationName = "$($script:dcsResourceName)_RemovePermission_Config" - - Context ('When using configuration {0}' -f $configurationName) { - It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should have set the resource and all the parameters should match' { - $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { - $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq "[$($script:dscResourceFriendlyName)]Integration_Test" - } - - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.ShareName1 - $resourceCurrentState.FullAccess | Should -BeNullOrEmpty - $resourceCurrentState.ChangeAccess | Should -BeNullOrEmpty - $resourceCurrentState.NoAccess | Should -BeNullOrEmpty - - $resourceCurrentState.ReadAccess | Should -HaveCount 1 - $resourceCurrentState.ReadAccess | Should -Contain 'Everyone' - } - - It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -BeTrue - } - } - - $configurationName = "$($script:dcsResourceName)_RecreateShare1_Config" - - Context ('When using configuration {0}' -f $configurationName) { - It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should have set the resource and all the parameters should match' { - $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { - $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq "[$($script:dscResourceFriendlyName)]Integration_Test" - } - - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.ShareName1 - $resourceCurrentState.Path | Should -Be $ConfigurationData.AllNodes.SharePath2 - } - - It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -BeTrue - } - } - - - $configurationName = "$($script:dcsResourceName)_RemoveShare1_Config" - - Context ('When using configuration {0}' -f $configurationName) { - It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should have set the resource and all the parameters should match' { - $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { - $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq "[$($script:dscResourceFriendlyName)]Integration_Test" - } - - $resourceCurrentState.Ensure | Should -Be 'Absent' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.ShareName1 - } - - It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -BeTrue - } - } - - $configurationName = "$($script:dcsResourceName)_RemoveShare2_Config" - - Context ('When using configuration {0}' -f $configurationName) { - It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should have set the resource and all the parameters should match' { - $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { - $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq "[$($script:dscResourceFriendlyName)]Integration_Test" - } - - $resourceCurrentState.Ensure | Should -Be 'Absent' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.ShareName2 - } - - It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -BeTrue - } - } - - $configurationName = "$($script:dcsResourceName)_Cleanup_Config" - - Context ('When using configuration {0}' -f $configurationName) { - It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw - } - } -} -#endregion diff --git a/Tests/Integration/MSFT_SystemLocale.Integration.Tests.ps1 b/Tests/Integration/MSFT_SystemLocale.Integration.Tests.ps1 deleted file mode 100644 index 852516cd..00000000 --- a/Tests/Integration/MSFT_SystemLocale.Integration.Tests.ps1 +++ /dev/null @@ -1,85 +0,0 @@ -$script:DSCModuleName = 'ComputerManagementDsc' -$script:DSCResourceName = 'MSFT_SystemLocale' - -#region HEADER -# Integration Test Template Version: 1.1.1 -[String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $Script:DSCModuleName ` - -DSCResourceName $Script:DSCResourceName ` - -TestType Integration -#endregion - -# Store the test machine system locale -$currentSystemLocale = (Get-WinSystemLocale).Name - -# Change the current system locale so that a complete test occurs. -Set-WinSystemLocale -SystemLocale 'kl-GL' - -# Using try/finally to always cleanup even if something awful happens. -try -{ - $ConfigFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1" - . $ConfigFile -Verbose -ErrorAction Stop - - Describe "$($script:DSCResourceName)_Integration" { - Context 'When settting System Locale to fr-FR' { - $configData = @{ - AllNodes = @( - @{ - NodeName = 'localhost' - SystemLocale = 'fr-FR' - IsSingleInstance = 'Yes' - } - ) - } - - It 'Should compile and apply the MOF without throwing' { - { - & "$($script:DSCResourceName)_Config" ` - -OutputPath $TestDrive ` - -ConfigurationData $configData - - Start-DscConfiguration ` - -Path $TestDrive ` - -ComputerName localhost ` - -Wait ` - -Verbose ` - -Force ` - -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object { - $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" - } - <# - A reboot would need to occur before this node can be bought into alignment. - Therefore a test for the new SystemLocale can not be automated. - #> - $current.IsSingleInstance | Should -Be $configData.AllNodes[0].IsSingleInstance - } - } - } -} -finally -{ - # Restore the test machine system locale - Set-WinSystemLocale -SystemLocale $currentSystemLocale - - #region FOOTER - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion -} diff --git a/Tests/Integration/MSFT_TimeZone.Integration.Tests.ps1 b/Tests/Integration/MSFT_TimeZone.Integration.Tests.ps1 deleted file mode 100644 index 837da24b..00000000 --- a/Tests/Integration/MSFT_TimeZone.Integration.Tests.ps1 +++ /dev/null @@ -1,82 +0,0 @@ -#region HEADER -$script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_TimeZone' - -# Integration Test Template Version: 1.3.3 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -TestType Integration -#endregion - -# Store the test machine timezone -$currentTimeZone = & tzutil.exe /g - -# Change the current timezone so that a complete test occurs. -tzutil.exe /s 'Eastern Standard Time' - -# Using try/finally to always cleanup even if something awful happens. -try -{ - #region Integration Tests - $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" - . $configFile -Verbose -ErrorAction Stop - - Describe "$($script:dscResourceName)_Integration" { - $configData = @{ - AllNodes = @( - @{ - NodeName = 'localhost' - TimeZone = 'Pacific Standard Time' - IsSingleInstance = 'Yes' - } - ) - } - - It 'Should compile and apply the MOF without throwing' { - { - & "$($script:dscResourceName)_Config" ` - -OutputPath $TestDrive ` - -ConfigurationData $configData - - Start-DscConfiguration ` - -Path $TestDrive ` - -ComputerName localhost ` - -Wait ` - -Verbose ` - -Force ` - -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should have set the configuration and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { - $_.ConfigurationName -eq "$($script:dscResourceName)_Config" - } - $current.TimeZone | Should -Be $configData.AllNodes[0].TimeZone - $current.IsSingleInstance | Should -Be $configData.AllNodes[0].IsSingleInstance - } - } - #endregion -} -finally -{ - # Restore the test machine timezone - & tzutil.exe /s $CurrentTimeZone - - #region FOOTER - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion -} diff --git a/Tests/Integration/MSFT_VirtualMemory.Integration.Tests.ps1 b/Tests/Integration/MSFT_VirtualMemory.Integration.Tests.ps1 deleted file mode 100644 index 49f7d2f5..00000000 --- a/Tests/Integration/MSFT_VirtualMemory.Integration.Tests.ps1 +++ /dev/null @@ -1,125 +0,0 @@ -#region HEADER -$script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_VirtualMemory' - -# Integration Test Template Version: 1.3.3 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -TestType Integration -#endregion - -# Using try/finally to always cleanup. -try -{ - #region Integration Tests - $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" - . $configFile - - Describe "$($script:dscResourceName)_Integration" { - - Context 'Set page file to automatically managed' { - $CurrentConfig = 'setToAuto' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file without error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue - } - } - - Context 'Set page file to custom size' { - $CurrentConfig = 'setToCustom' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file without error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue - } - } - - Context 'Set page file to system managed' { - $CurrentConfig = 'setToSystemManaged' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file without error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue - } - } - - Context 'Set page file to none' { - $CurrentConfig = 'setToNone' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file without error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue - } - } - } -} -finally -{ - #region FOOTER - - Restore-TestEnvironment -TestEnvironment $TestEnvironment - - #endregion -} diff --git a/Tests/Integration/MSFT_WindowsCapability.Integration.Tests.ps1 b/Tests/Integration/MSFT_WindowsCapability.Integration.Tests.ps1 deleted file mode 100644 index 70cb29f5..00000000 --- a/Tests/Integration/MSFT_WindowsCapability.Integration.Tests.ps1 +++ /dev/null @@ -1,165 +0,0 @@ -#region HEADER -$script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_WindowsCapability' - -# Integration Test Template Version: 1.3.3 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -TestType Integration -#endregion - -function Invoke-TestSetup -{ - if (-not (Get-Module dism -ListAvailable)) - { - Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\dism.psm1') -Force - } -} - -function Invoke-TestCleanup -{ - Restore-TestEnvironment -TestEnvironment $TestEnvironment -} - -try -{ - Invoke-TestSetup - - # Ensure that the tests can be performed on this computer - $productType = (Get-CimInstance Win32_OperatingSystem).ProductType - Describe 'Environment' { - Context 'Operating System' { - It 'Should be a Desktop OS' { - if ($productType -ne 1) - { - Set-ItResult -Inconclusive -Because 'Operating System is not a Desktop OS' - } - } - } - } - - if ($productType -ne 1) - { - break - } - - $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).Config.ps1" - . $configFile - - Describe "$($script:dscResourceName)_Integration" { - Context 'When adding a Windows Capability' { - $configData = @{ - AllNodes = @( - @{ - NodeName = 'localhost' - Name = 'XPS.Viewer~~~~0.0.1.0' - LogLevel = 'Errors' - LogPath = Join-Path -Path $ENV:Temp -ChildPath 'Logfile.log' - Ensure = 'Present' - } - ) - } - - It 'Should compile and apply the MOF without throwing' { - { - & "$($script:dscResourceName)_Config" ` - -OutputPath $TestDrive ` - -ConfigurationData $configData - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { - Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { - $_.ConfigurationName -eq "$($script:dscResourceName)_Config" - } - $current.Name | Should -Be $configData.AllNodes[0].Name - $current.LogLevel | Should -Be $configData.AllNodes[0].LogLevel - $current.LogPath | Should -Be $configData.AllNodes[0].LogPath - $current.Ensure | Should -Be $configData.AllNodes[0].Ensure - $current.IsSingleInstance | Should -Be 'Yes' - } - } - - Context 'When removing a Windows Capability' { - $configData = @{ - AllNodes = @( - @{ - NodeName = 'localhost' - Name = 'XPS.Viewer~~~~0.0.1.0' - LogLevel = 'Errors' - LogPath = Join-Path -Path $ENV:Temp -ChildPath 'Logfile.log' - Ensure = 'Absent' - } - ) - } - - It 'Should compile and apply the MOF without throwing' { - { - & "$($script:dscResourceName)_Config" ` - -OutputPath $TestDrive ` - -ConfigurationData $configData - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { - Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw - } - - It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { - $_.ConfigurationName -eq "$($script:dscResourceName)_Config" - } - $current.Name | Should -Be $configData.AllNodes[0].Name - $current.LogLevel | Should -Be $configData.AllNodes[0].LogLevel - $current.LogPath | Should -Be $configData.AllNodes[0].LogPath - $current.Ensure | Should -Be $configData.AllNodes[0].Ensure - $current.IsSingleInstance | Should -Be 'Yes' - } - } - } -} -finally -{ - #region FOOTER - Invoke-TestCleanup - #endregion -} diff --git a/Tests/Integration/MSFT_WindowsEventLog.Integration.Tests.ps1 b/Tests/Integration/MSFT_WindowsEventLog.Integration.Tests.ps1 deleted file mode 100644 index 54a62372..00000000 --- a/Tests/Integration/MSFT_WindowsEventLog.Integration.Tests.ps1 +++ /dev/null @@ -1,292 +0,0 @@ -#region HEADER -$script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_WindowsEventLog' - -# Integration Test Template Version: 1.3.3 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -TestType Integration -#endregion - -# Using try/finally to always cleanup. -try -{ - #region Integration Tests - $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" - . $configFile - Describe "$($script:dscResourceName)_Integration" { - - Context 'Set Windows Event Log to Logmode Retain' { - $CurrentConfig = 'MSFT_WindowsEventLog_RetainSize' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file without error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue - } - } - - Context 'Set Windows Event Log to Logmode AutoBackup with LogRetentionDays of 30 days' { - $CurrentConfig = 'MSFT_WindowsEventLog_AutobackupLogRetention' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file without error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue - } - } - - Context 'Set Windows Event Log to Logmode Circular, MaximumSizeInBytes 20971520, LogFilePath C:\temp\Application.evtx' { - $CurrentConfig = 'MSFT_WindowsEventLog_CircularLogPath' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file without error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue - } - } - - Context 'Set Windows Event Log to Default' { - $CurrentConfig = 'MSFT_WindowsEventLog_Default' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file without error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue - } - } - - Context 'Enable a Logfile other than Application Eventlog' { - $CurrentConfig = 'MSFT_WindowsEventLog_EnableLog' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file without error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue - } - } - - Context 'Disable a Logfile other than Application Windows Event Log' { - $CurrentConfig = 'MSFT_WindowsEventLog_DisableLog' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file without error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue - } - } - - Context 'Set Eventlog to Logmode Circular with a SecurityDescriptor' { - $CurrentConfig = 'MSFT_WindowsEventLog_CircularSecurityDescriptor' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file without error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue - } - } - - Context 'Enable a Logfile other than Application Windows Event Log with Retention' { - $CurrentConfig = 'MSFT_WindowsEventLog_EnableBackupLog' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should not apply the MOF' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should return a incompliant state' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeFalse - } - } - - Context 'Disable a Logfile other than Application Eventlog with retention' { - $CurrentConfig = 'MSFT_WindowsEventLog_DisableBackupLog' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file without error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue - } - } - - Context 'Set Windows Event Log back to the default configuration' { - $CurrentConfig = 'MSFT_WindowsEventLog_Default' - $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) - $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') - - It 'Should compile a MOF file without error' { - { - . $CurrentConfig -OutputPath $ConfigDir - } | Should -Not -Throw - } - - It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should apply the MOF correctly' { - { - Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force - } | Should -Not -Throw - } - - It 'Should return a compliant state after being applied' { - (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue - } - } - } -} -finally -{ - Restore-TestEnvironment -TestEnvironment $TestEnvironment -} diff --git a/Tests/Unit/ComputerManagementDsc.Common.Tests.ps1 b/Tests/Unit/ComputerManagementDsc.Common.Tests.ps1 deleted file mode 100644 index 144b3f50..00000000 --- a/Tests/Unit/ComputerManagementDsc.Common.Tests.ps1 +++ /dev/null @@ -1,1782 +0,0 @@ -#region HEADER -$script:ModuleName = 'ComputerManagementDsc.Common' - -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global - -# Unit Test Template Version: 1.2.4 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force -Import-Module (Join-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'Modules' -ChildPath $script:ModuleName)) -ChildPath "$script:ModuleName.psm1") -Force -#endregion HEADER - -# Begin Testing -try -{ - InModuleScope $script:ModuleName { - Describe 'ComputerManagementDsc.Common\Remove-CommonParameter' { - $removeCommonParameter = @{ - Parameter1 = 'value1' - Parameter2 = 'value2' - Verbose = $true - Debug = $true - ErrorAction = 'Stop' - WarningAction = 'Stop' - InformationAction = 'Stop' - ErrorVariable = 'errorVariable' - WarningVariable = 'warningVariable' - OutVariable = 'outVariable' - OutBuffer = 'outBuffer' - PipelineVariable = 'pipelineVariable' - InformationVariable = 'informationVariable' - WhatIf = $true - Confirm = $true - UseTransaction = $true - } - - Context 'Hashtable contains all common parameters' { - It 'Should not throw exception' { - { $script:result = Remove-CommonParameter -Hashtable $removeCommonParameter -Verbose } | Should -Not -Throw - } - - It 'Should have retained parameters in the hashtable' { - $script:result.Contains('Parameter1') | Should -BeTrue - $script:result.Contains('Parameter2') | Should -BeTrue - } - - It 'Should have removed the common parameters from the hashtable' { - $script:result.Contains('Verbose') | Should -BeFalse - $script:result.Contains('Debug') | Should -BeFalse - $script:result.Contains('ErrorAction') | Should -BeFalse - $script:result.Contains('WarningAction') | Should -BeFalse - $script:result.Contains('InformationAction') | Should -BeFalse - $script:result.Contains('ErrorVariable') | Should -BeFalse - $script:result.Contains('WarningVariable') | Should -BeFalse - $script:result.Contains('OutVariable') | Should -BeFalse - $script:result.Contains('OutBuffer') | Should -BeFalse - $script:result.Contains('PipelineVariable') | Should -BeFalse - $script:result.Contains('InformationVariable') | Should -BeFalse - $script:result.Contains('WhatIf') | Should -BeFalse - $script:result.Contains('Confirm') | Should -BeFalse - $script:result.Contains('UseTransaction') | Should -BeFalse - } - } - } - - Describe 'ComputerManagementDsc.Common\Test-DscParameterState' { - $verbose = $true - - Context 'When testing single values' { - $currentValues = @{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3' - } - } - - Context 'When all values match' { - $desiredValues = [PSObject] @{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3' - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $true' { - $script:result | Should -Be $true - } - } - - Context 'When a string is mismatched' { - $desiredValues = [PSObject] @{ - String = 'different string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3' - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When a boolean is mismatched' { - $desiredValues = [PSObject] @{ - String = 'a string' - Bool = $false - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3' - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When an int is mismatched' { - $desiredValues = [PSObject] @{ - String = 'a string' - Bool = $true - Int = 1 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3' - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When a type is mismatched' { - $desiredValues = [PSObject] @{ - String = 'a string' - Bool = $true - Int = '99' - Array = 'a', 'b', 'c' - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When a type is mismatched but TurnOffTypeChecking is used' { - $desiredValues = [PSObject] @{ - String = 'a string' - Bool = $true - Int = '99' - Array = 'a', 'b', 'c' - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -TurnOffTypeChecking ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $true' { - $script:result | Should -Be $true - } - } - - Context 'When a value is mismatched but valuesToCheck is used to exclude them' { - $desiredValues = [PSObject] @{ - String = 'a string' - Bool = $false - Int = 1 - Array = @( 'a', 'b' ) - } - - $valuesToCheck = @( - 'String' - ) - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -ValuesToCheck $valuesToCheck ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $true' { - $script:result | Should -Be $true - } - } - } - - Context 'When testing array values' { - BeforeAll { - $currentValues = @{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c', 1 - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3' - } - } - } - - Context 'When array is missing a value' { - $desiredValues = [PSObject]@{ - String = 'a string' - Bool = $true - Int = 1 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3' - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When array has an additional value' { - $desiredValues = [PSObject] @{ - String = 'a string' - Bool = $true - Int = 1 - Array = 'a', 'b', 'c', 1, 2 - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When array has a different value' { - $desiredValues = [PSObject] @{ - String = 'a string' - Bool = $true - Int = 1 - Array = 'a', 'x', 'c', 1 - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When array has different order' { - $desiredValues = [PSObject] @{ - String = 'a string' - Bool = $true - Int = 1 - Array = 'c', 'b', 'a', 1 - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When array has different order but SortArrayValues is used' { - $desiredValues = [PSObject] @{ - String = 'a string' - Bool = $true - Int = 1 - Array = 'c', 'b', 'a', 1 - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -SortArrayValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - - Context 'When array has a value with a different type' { - $desiredValues = [PSObject] @{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c', '1' - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When array has a value with a different type but TurnOffTypeChecking is used' { - $desiredValues = [PSObject] @{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c', '1' - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -TurnOffTypeChecking ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $true' { - $script:result | Should -Be $true - } - } - - Context 'When both arrays are empty' { - $currentValues = @{ - String = 'a string' - Bool = $true - Int = 99 - Array = @() - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = @() - } - } - - $desiredValues = [PSObject]@{ - String = 'a string' - Bool = $true - Int = 99 - Array = @() - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = @() - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $true' { - $script:result | Should -Be $true - } - } - } - - Context 'When testing hashtables' { - $currentValues = @{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3', 99 - } - } - - Context 'When hashtable is missing a value' { - $desiredValues = [PSObject]@{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3' - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When hashtable has an additional value' { - $desiredValues = [PSObject]@{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3', 99, 100 - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When hashtable has a different value' { - $desiredValues = [PSObject]@{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'xx', 'v2', 'v3', 99 - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When an array in hashtable has different order' { - $desiredValues = [PSObject]@{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v3', 'v2', 'v1', 99 - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When an array in hashtable has different order but SortArrayValues is used' { - $desiredValues = [PSObject]@{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v3', 'v2', 'v1', 99 - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -SortArrayValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $true' { - $script:result | Should -Be $true - } - } - - - Context 'When hashtable has a value with a different type' { - $desiredValues = [PSObject]@{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3', '99' - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When hashtable has a value with a different type but TurnOffTypeChecking is used' { - $desiredValues = [PSObject]@{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3', 99 - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -TurnOffTypeChecking ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $true' { - $script:result | Should -Be $true - } - } - } - - Context 'When testing CimInstances / hashtables' { - $currentValues = @{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3', 99 - } - CimInstances = [CimInstance[]](ConvertTo-CimInstance -Hashtable @{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a, b, c' - }) - } - - Context 'When everything matches' { - $desiredValues = [PSObject]@{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3', 99 - } - CimInstances = [CimInstance[]](ConvertTo-CimInstance -Hashtable @{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a, b, c' - }) - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $true' { - $script:result | Should -Be $true - } - } - - Context 'When CimInstances missing a value in the desired state (not recognized)' { - $desiredValues = [PSObject]@{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3', 99 - } - CimInstances = @{ - String = 'a string' - Bool = $true - Array = 'a, b, c' - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $true' { - $script:result | Should -Be $true - } - } - - Context 'When CimInstances missing a value in the desired state (recognized using ReverseCheck)' { - $desiredValues = [PSObject]@{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3', 99 - } - CimInstances = @{ - String = 'a string' - Bool = $true - Array = 'a, b, c' - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -ReverseCheck ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When CimInstances have an additional value' { - $desiredValues = [PSObject]@{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3', 99 - } - CimInstances = @{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a, b, c' - Test = 'Some string' - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When CimInstances have a different value' { - $desiredValues = [PSObject]@{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3', 99 - } - CimInstances = @{ - String = 'some other string' - Bool = $true - Int = 99 - Array = 'a, b, c' - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When CimInstances have a value with a different type' { - $desiredValues = [PSObject]@{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3', 99 - } - CimInstances = @{ - String = 'a string' - Bool = $true - Int = '99' - Array = 'a, b, c' - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - - Context 'When CimInstances have a value with a different type but TurnOffTypeChecking is used' { - $desiredValues = [PSObject]@{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c' - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3', 99 - } - CimInstances = @{ - String = 'a string' - Bool = $true - Int = '99' - Array = 'a, b, c' - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -TurnOffTypeChecking ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $true' { - $script:result | Should -Be $true - } - } - } - - Context 'When reverse checking' { - $currentValues = @{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a', 'b', 'c', 1 - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3' - } - } - - Context 'When even if missing property in the desired state' { - $desiredValues = [PSObject] @{ - Array = 'a', 'b', 'c', 1 - Hashtable = @{ - k1 = 'Test' - k2 = 123 - k3 = 'v1', 'v2', 'v3' - } - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $true' { - $script:result | Should -Be $true - } - } - - Context 'When missing property in the desired state' { - $currentValues = @{ - String = 'a string' - Bool = $true - } - - $desiredValues = [PSObject] @{ - String = 'a string' - } - - It 'Should not throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -ReverseCheck ` - -Verbose:$verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - } - - Context 'When testing parameter types' { - Context 'When desired value is of the wrong type' { - $currentValues = @{ - String = 'a string' - } - - $desiredValues = 1, 2, 3 - - It 'Should throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Throw - } - } - - Context 'When current value is of the wrong type' { - $currentValues = 1, 2, 3 - - $desiredValues = @{ - String = 'a string' - } - - It 'Should throw exception' { - { $script:result = Test-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -Verbose:$verbose } | Should -Throw - } - } - } - } - - Describe 'ComputerManagementDsc.Common\Test-DscObjectHasProperty' { - # Use the Get-Verb cmdlet to just get a simple object fast - $testDscObject = (Get-Verb)[0] - - Context 'When the object contains the expected property' { - It 'Should not throw exception' { - { $script:result = Test-DscObjectHasProperty -Object $testDscObject -PropertyName 'Verb' -Verbose } | Should -Not -Throw - } - - It 'Should return $true' { - $script:result | Should -Be $true - } - } - - Context 'When the object does not contain the expected property' { - It 'Should not throw exception' { - { $script:result = Test-DscObjectHasProperty -Object $testDscObject -PropertyName 'Missing' -Verbose } | Should -Not -Throw - } - - It 'Should return $false' { - $script:result | Should -Be $false - } - } - } - - Describe 'ComputerManagementDsc.Common\ConvertTo-CimInstance' { - $hashtable = @{ - k1 = 'v1' - k2 = 100 - k3 = 1, 2, 3 - } - - Context 'When the array contains the expected record count' { - It 'Should not throw exception' { - { $script:result = [CimInstance[]]($hashtable | ConvertTo-CimInstance) } | Should -Not -Throw - } - - It "Should record count should be $($hashTable.Count)" { - $script:result.Count | Should -Be $hashtable.Count - } - - It 'Should return result of type CimInstance[]' { - $script:result.GetType().Name | Should -Be 'CimInstance[]' - } - - It 'Should return value "k1" in the CimInstance array should be "v1"' { - ($script:result | Where-Object Key -eq k1).Value | Should -Be 'v1' - } - - It 'Should return value "k2" in the CimInstance array should be "100"' { - ($script:result | Where-Object Key -eq k2).Value | Should -Be 100 - } - - It 'Should return value "k3" in the CimInstance array should be "1,2,3"' { - ($script:result | Where-Object Key -eq k3).Value | Should -Be '1,2,3' - } - } - } - - Describe 'ComputerManagementDsc.Common\ConvertTo-HashTable' { - [CimInstance[]]$cimInstances = ConvertTo-CimInstance -Hashtable @{ - k1 = 'v1' - k2 = 100 - k3 = 1, 2, 3 - } - - Context 'When the array contains the expected record count' { - It 'Should not throw exception' { - { $script:result = $cimInstances | ConvertTo-HashTable } | Should -Not -Throw - } - - It "Should return record count of $($cimInstances.Count)" { - $script:result.Count | Should -Be $cimInstances.Count - } - - It 'Should return result of type [System.Collections.Hashtable]' { - $script:result | Should -BeOfType [System.Collections.Hashtable] - } - - It 'Should return value "k1" in the hashtable should be "v1"' { - $script:result.k1 | Should -Be 'v1' - } - - It 'Should return value "k2" in the hashtable should be "100"' { - $script:result.k2 | Should -Be 100 - } - - It 'Should return value "k3" in the hashtable should be "1,2,3"' { - $script:result.k3 | Should -Be '1,2,3' - } - } - } - - Describe 'ComputerManagementDsc.Common\Get-TimeZoneId' { - Context '"Get-TimeZone" not available and current timezone is set to "Pacific Standard Time"' { - Mock ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Get-TimeZone' - } - - Mock -CommandName Get-CimInstance -MockWith { - @{ - StandardName = 'Pacific Standard Time' - } - } - - It 'Returns "Pacific Standard Time"' { - Get-TimeZoneId | Should -Be 'Pacific Standard Time' - } - - It 'Should call expected mocks' { - Assert-MockCalled ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Get-TimeZone' - } -Exactly -Times 1 - - Assert-MockCalled -CommandName Get-CimInstance -Exactly -Times 1 - } - } - - Context '"Get-TimeZone" not available and current timezone is set to "Russia TZ 11 Standard Time"' { - Mock ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Get-TimeZone' - } - - Mock -CommandName Get-CimInstance -MockWith { - @{ - StandardName = 'Russia TZ 11 Standard Time' - } - } - - It 'Returns "Russia Time Zone 11"' { - Get-TimeZoneId | Should -Be 'Russia Time Zone 11' - } - - It 'Should call expected mocks' { - Assert-MockCalled ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Get-TimeZone' - } -Exactly -Times 1 - - Assert-MockCalled -CommandName Get-CimInstance -Exactly -Times 1 - } - } - - Context '"Get-TimeZone" available and current timezone is set to "Pacific Standard Time"' { - function Get-TimeZone - { - } - - Mock ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Get-TimeZone' - } -MockWith { - 'Get-TimeZone' - } - - Mock ` - -CommandName Get-TimeZone ` - -MockWith { - @{ - StandardName = 'Pacific Standard Time' - } - } - - It 'Returns "Pacific Standard Time"' { - Get-TimeZoneId | Should -Be 'Pacific Standard Time' - } - - It 'Should call expected mocks' { - Assert-MockCalled ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Get-TimeZone' - } -Exactly -Times 1 - - Assert-MockCalled -CommandName Get-TimeZone -Exactly -Times 1 - } - } - } - - Describe 'ComputerManagementDsc.Common\Test-TimezoneId' { - Mock -CommandName Get-TimeZoneId -MockWith { - 'Russia Time Zone 11' - } - - Context 'current timezone matches desired timezone' { - It 'Should return $true' { - Test-TimezoneId -TimeZoneId 'Russia Time Zone 11' | Should -BeTrue - } - } - - Context 'current timezone does not match desired timezone' { - It 'Should return $false' { - Test-TimezoneId -TimeZoneId 'GMT Standard Time' | Should -BeFalse - } - } - } - - Describe 'ComputerManagementDsc.Common\Set-TimeZoneId' { - Context '"Set-TimeZone" and "Add-Type" is not available, Tzutil Returns 0' { - Mock ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Add-Type' - } - - Mock ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Set-TimeZone' - } - - Mock -CommandName 'TzUtil.exe' -MockWith { - $global:LASTEXITCODE = 0 - return 'OK' - } - - Mock -CommandName Add-Type - - It 'Should not throw an exception' { - { Set-TimeZoneId -TimezoneId 'Eastern Standard Time' } | Should -Not -Throw - } - - It 'Should call expected mocks' { - Assert-MockCalled ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Add-Type' - } -Exactly -Times 1 - - Assert-MockCalled ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Set-TimeZone' - } -Exactly -Times 1 - - Assert-MockCalled -CommandName TzUtil.exe -Exactly -Times 1 - Assert-MockCalled -CommandName Add-Type -Exactly -Times 0 - } - } - - Context '"Set-TimeZone" is not available but "Add-Type" is available' { - Mock ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Add-Type' - } -MockWith { - 'Add-Type' - } - - Mock ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Set-TimeZone' - } - - Mock -CommandName 'TzUtil.exe' -MockWith { - $global:LASTEXITCODE = 0 - return 'OK' - } - - Mock -CommandName Add-Type - Mock -CommandName Set-TimeZoneUsingDotNet - - It 'Should not throw an exception' { - { Set-TimeZoneId -TimezoneId 'Eastern Standard Time' } | Should -Not -Throw - } - - It 'Should call expected mocks' { - Assert-MockCalled ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Add-Type' - } -Exactly -Times 1 - - Assert-MockCalled ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Set-TimeZone' - } -Exactly -Times 1 - - Assert-MockCalled -CommandName TzUtil.exe -Exactly -Times 0 - Assert-MockCalled -CommandName Add-Type -Exactly -Times 0 - Assert-MockCalled -CommandName Set-TimeZoneUsingDotNet -Exactly -Times 1 - } - } - - Context '"Set-TimeZone" is available' { - function Set-TimeZone - { - param - ( - [System.String] - $id - ) - } - - Mock ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Add-Type' - } - - Mock ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Set-TimeZone' - } -MockWith { - 'Set-TimeZone' - } - - Mock -CommandName Set-TimeZone - - It 'Should not throw an exception' { - { Set-TimeZoneId -TimezoneId 'Eastern Standard Time' } | Should -Not -Throw - } - - It 'Should call expected mocks' { - Assert-MockCalled ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Add-Type' - } -Exactly -Times 0 - - Assert-MockCalled ` - -CommandName Get-Command ` - -ParameterFilter { - $Name -eq 'Set-TimeZone' - } -Exactly -Times 1 - - Assert-MockCalled -CommandName Set-TimeZone -Exactly -Times 1 - } - } - } - - Describe 'ComputerManagementDsc.Common\Get-PowerPlan' { - $mockBalancedPowerPlan = @{ - FriendlyName = 'Balanced' - Guid = [System.Guid]'381b4222-f694-41f0-9685-ff5bb260df2e' - } - - $mockHighPerformancePowerPlan = @{ - 'FriendlyName' = 'High performance' - 'Guid' = [System.Guid]'8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' - } - - $mockPowerSaverPowerPlan = @{ - 'FriendlyName' = 'Power saver' - 'Guid' = [System.Guid]'a1841308-3541-4fab-bc81-f71556f20b4a' - } - - Context 'Only one power plan is available and "PowerPlan" parameter is not specified' { - Mock ` - -CommandName Get-PowerPlanUsingPInvoke ` - -MockWith { - return $mockBalancedPowerPlan - } - - It 'Should not throw an exception' { - { Get-PowerPlan } | Should -Not -Throw - } - - It 'Should call expected mocks' { - Assert-MockCalled ` - -CommandName Get-PowerPlanUsingPInvoke ` - -Exactly -Times 1 - } - - It 'Should return exactly one hashtable' { - $result = Get-PowerPlan - $result | Should -BeOfType [System.Collections.Hashtable] - $result | Should -HaveCount 1 - } - - } - - Context 'Only one power plan is available and "PowerPlan" parameter is specified as Guid of the available plan' { - Mock ` - -CommandName Get-PowerPlanUsingPInvoke ` - -MockWith { - return $mockBalancedPowerPlan - } - - It 'Should not throw an exception' { - { Get-PowerPlan -PowerPlan '381b4222-f694-41f0-9685-ff5bb260df2e' } | Should -Not -Throw - } - - It 'Should call expected mocks' { - Assert-MockCalled ` - -CommandName Get-PowerPlanUsingPInvoke ` - -Exactly -Times 1 - } - - It 'Should return a hashtable with the name and guid fo the power plan' { - $result = Get-PowerPlan -PowerPlan '381b4222-f694-41f0-9685-ff5bb260df2e' - $result | Should -BeOfType [System.Collections.Hashtable] - $result | Should -HaveCount 1 - $result.FriendlyName | Should -Be 'Balanced' - $result.guid | Should -Be '381b4222-f694-41f0-9685-ff5bb260df2e' - } - } - - Context 'Only one power plan is available and "PowerPlan" parameter is specified as Guid of a not available plan' { - Mock ` - -CommandName Get-PowerPlanUsingPInvoke ` - -MockWith { - return $mockBalancedPowerPlan - } - - It 'Should not throw an exception' { - { Get-PowerPlan -PowerPlan '8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' } | Should -Not -Throw - } - - It 'Should call expected mocks' { - Assert-MockCalled ` - -CommandName Get-PowerPlanUsingPInvoke ` - -Exactly -Times 1 - } - - It 'Should return nothing' { - $result = Get-PowerPlan -PowerPlan '8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' - $result | Should -BeNullOrEmpty - } - } - - Context 'Only one power plan is available and "PowerPlan" parameter is specified as name of the available plan' { - Mock ` - -CommandName Get-PowerPlanUsingPInvoke ` - -MockWith { - return $mockBalancedPowerPlan - } - - It 'Should not throw an exception' { - { Get-PowerPlan -PowerPlan 'Balanced' } | Should -Not -Throw - } - - It 'Should call expected mocks' { - Assert-MockCalled ` - -CommandName Get-PowerPlanUsingPInvoke ` - -Exactly -Times 1 - } - - It 'Should return a hashtable with the name and guid fo the power plan' { - $result = Get-PowerPlan -PowerPlan 'Balanced' - $result | Should -BeOfType [System.Collections.Hashtable] - $result | Should -HaveCount 1 - $result.FriendlyName | Should -Be 'Balanced' - $result.guid | Should -Be '381b4222-f694-41f0-9685-ff5bb260df2e' - } - } - - Context 'Only one power plan is available and "PowerPlan" parameter is specified as name of a not available plan' { - Mock ` - -CommandName Get-PowerPlanUsingPInvoke ` - -MockWith { - return $mockBalancedPowerPlan - } - - It 'Should not throw an exception' { - { Get-PowerPlan -PowerPlan 'High performance' } | Should -Not -Throw - } - - It 'Should call expected mocks' { - Assert-MockCalled ` - -CommandName Get-PowerPlanUsingPInvoke ` - -Exactly -Times 1 - } - - It 'Should return nothing' { - $result = Get-PowerPlan -PowerPlan 'High performance' - $result | Should -BeNullOrEmpty - } - } - - Context 'Multiple power plans are available and "PowerPlan" parameter is not specified' { - Mock ` - -CommandName Get-PowerPlanUsingPInvoke ` - -MockWith { - return @( - $mockBalancedPowerPlan - $mockHighPerformancePowerPlan - $mockPowerSaverPowerPlan - ) - } - - It 'Should not throw an exception' { - { Get-PowerPlan } | Should -Not -Throw - } - - It 'Should call expected mocks' { - Assert-MockCalled ` - -CommandName Get-PowerPlanUsingPInvoke ` - -Exactly -Times 1 - } - - It 'Should return an array with all available plans' { - $result = Get-PowerPlan - $result | Should -HaveCount 3 - } - } - - Context 'Multiple power plans are available and "PowerPlan" parameter is specified as Guid of an available plan' { - Mock ` - -CommandName Get-PowerPlanUsingPInvoke ` - -MockWith { - return @( - $mockBalancedPowerPlan - $mockHighPerformancePowerPlan - $mockPowerSaverPowerPlan - ) - } - - It 'Should not throw an exception' { - { Get-PowerPlan -PowerPlan '381b4222-f694-41f0-9685-ff5bb260df2e'} | Should -Not -Throw - } - - It 'Should call expected mocks' { - Assert-MockCalled ` - -CommandName Get-PowerPlanUsingPInvoke ` - -Exactly -Times 1 - } - - It 'Should return a hashtable with the name and guid fo the power plan' { - $result = Get-PowerPlan -PowerPlan '381b4222-f694-41f0-9685-ff5bb260df2e' - $result | Should -BeOfType [System.Collections.Hashtable] - $result | Should -HaveCount 1 - $result.FriendlyName | Should -Be 'Balanced' - $result.guid | Should -Be '381b4222-f694-41f0-9685-ff5bb260df2e' - } - } - - Context 'Multiple power plans are available and "PowerPlan" parameter is specified as Guid of a not available plan' { - Mock ` - -CommandName Get-PowerPlanUsingPInvoke ` - -MockWith { - return @( - $mockBalancedPowerPlan - $mockHighPerformancePowerPlan - $mockPowerSaverPowerPlan - ) - } - - It 'Should not throw an exception' { - { Get-PowerPlan -PowerPlan '9c5e7fda-e8bf-4a96-9a85-a7e23a8c635c'} | Should -Not -Throw - } - - It 'Should call expected mocks' { - Assert-MockCalled ` - -CommandName Get-PowerPlanUsingPInvoke ` - -Exactly -Times 1 - } - - It 'Should return nothing' { - $result = Get-PowerPlan -PowerPlan '9c5e7fda-e8bf-4a96-9a85-a7e23a8c635c' - $result | Should -BeNullOrEmpty - } - } - - Context 'Multiple power plans are available and "PowerPlan" parameter is specified as name of an available plan' { - Mock ` - -CommandName Get-PowerPlanUsingPInvoke ` - -MockWith { - return @( - $mockBalancedPowerPlan - $mockHighPerformancePowerPlan - $mockPowerSaverPowerPlan - ) - } - - It 'Should not throw an exception' { - { Get-PowerPlan -PowerPlan 'High performance'} | Should -Not -Throw - } - - It 'Should call expected mocks' { - Assert-MockCalled ` - -CommandName Get-PowerPlanUsingPInvoke ` - -Exactly -Times 1 - } - - It 'Should return a hashtable with the name and guid fo the power plan' { - $result = Get-PowerPlan -PowerPlan 'High performance' - $result | Should -BeOfType [System.Collections.Hashtable] - $result | Should -HaveCount 1 - $result.FriendlyName | Should -Be 'High performance' - $result.guid | Should -Be '8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' - } - } - - Context 'Multiple power plans are available and "PowerPlan" parameter is specified as name of a not available plan' { - Mock ` - -CommandName Get-PowerPlanUsingPInvoke ` - -MockWith { - return @( - $mockBalancedPowerPlan - $mockHighPerformancePowerPlan - $mockPowerSaverPowerPlan - ) - } - - It 'Should not throw an exception' { - { Get-PowerPlan -PowerPlan 'Some unavailable plan'} | Should -Not -Throw - } - - It 'Should call expected mocks' { - Assert-MockCalled ` - -CommandName Get-PowerPlanUsingPInvoke ` - -Exactly -Times 1 - } - - It 'Should return nothing' { - $result = Get-PowerPlan -PowerPlan 'Some unavailable plan' - $result | Should -BeNullOrEmpty - } - } - } - - Describe 'DscResource.LocalizationHelper\Get-LocalizedData' { - $mockTestPath = { - return $mockTestPathReturnValue - } - - $mockImportLocalizedData = { - $BaseDirectory | Should -Be $mockExpectedLanguagePath - } - - BeforeEach { - Mock -CommandName Test-Path -MockWith $mockTestPath -Verifiable - Mock -CommandName Import-LocalizedData -MockWith $mockImportLocalizedData -Verifiable - } - - Context 'When loading localized data for Swedish' { - $mockExpectedLanguagePath = 'sv-SE' - $mockTestPathReturnValue = $true - - It 'Should call Import-LocalizedData with sv-SE language' { - Mock -CommandName Join-Path -MockWith { - return 'sv-SE' - } -Verifiable - - { Get-LocalizedData -ResourceName 'DummyResource' } | Should -Not -Throw - - Assert-MockCalled -CommandName Join-Path -Exactly -Times 3 -Scope It - Assert-MockCalled -CommandName Test-Path -Exactly -Times 1 -Scope It - Assert-MockCalled -CommandName Import-LocalizedData -Exactly -Times 1 -Scope It - } - - $mockExpectedLanguagePath = 'en-US' - $mockTestPathReturnValue = $false - - It 'Should call Import-LocalizedData and fallback to en-US if sv-SE language does not exist' { - Mock -CommandName Join-Path -MockWith { - return $ChildPath - } -Verifiable - - { Get-LocalizedData -ResourceName 'DummyResource' } | Should -Not -Throw - - Assert-MockCalled -CommandName Join-Path -Exactly -Times 4 -Scope It - Assert-MockCalled -CommandName Test-Path -Exactly -Times 1 -Scope It - Assert-MockCalled -CommandName Import-LocalizedData -Exactly -Times 1 -Scope It - } - - Context 'When $ScriptRoot is set to a path' { - $mockExpectedLanguagePath = 'sv-SE' - $mockTestPathReturnValue = $true - - It 'Should call Import-LocalizedData with sv-SE language' { - Mock -CommandName Join-Path -MockWith { - return 'sv-SE' - } -Verifiable - - { Get-LocalizedData -ResourceName 'DummyResource' -ScriptRoot '.' } | Should -Not -Throw - - Assert-MockCalled -CommandName Join-Path -Exactly -Times 1 -Scope It - Assert-MockCalled -CommandName Test-Path -Exactly -Times 1 -Scope It - Assert-MockCalled -CommandName Import-LocalizedData -Exactly -Times 1 -Scope It - } - - $mockExpectedLanguagePath = 'en-US' - $mockTestPathReturnValue = $false - - It 'Should call Import-LocalizedData and fallback to en-US if sv-SE language does not exist' { - Mock -CommandName Join-Path -MockWith { - return $ChildPath - } -Verifiable - - { Get-LocalizedData -ResourceName 'DummyResource' -ScriptRoot '.' } | Should -Not -Throw - - Assert-MockCalled -CommandName Join-Path -Exactly -Times 2 -Scope It - Assert-MockCalled -CommandName Test-Path -Exactly -Times 1 -Scope It - Assert-MockCalled -CommandName Import-LocalizedData -Exactly -Times 1 -Scope It - } - } - } - - Context 'When loading localized data for English' { - Mock -CommandName Join-Path -MockWith { - return 'en-US' - } -Verifiable - - $mockExpectedLanguagePath = 'en-US' - $mockTestPathReturnValue = $true - - It 'Should call Import-LocalizedData with en-US language' { - { Get-LocalizedData -ResourceName 'DummyResource' } | Should -Not -Throw - } - } - - Assert-VerifiableMock - } - - Describe 'DscResource.LocalizationHelper\New-InvalidOperationException' { - Context 'When calling with Message parameter only' { - It 'Should throw the correct error' { - $mockErrorMessage = 'Mocked error' - - { New-InvalidOperationException -Message $mockErrorMessage } | Should -Throw $mockErrorMessage - } - } - - Context 'When calling with both the Message and ErrorRecord parameter' { - It 'Should throw the correct error' { - $mockErrorMessage = 'Mocked error' - $mockExceptionErrorMessage = 'Mocked exception error message' - - $mockException = New-Object -TypeName System.Exception -ArgumentList $mockExceptionErrorMessage - $mockErrorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord -ArgumentList $mockException, $null, 'InvalidResult', $null - - { New-InvalidOperationException -Message $mockErrorMessage -ErrorRecord $mockErrorRecord } | Should -Throw ('System.InvalidOperationException: {0} ---> System.Exception: {1}' -f $mockErrorMessage, $mockExceptionErrorMessage) - } - } - - Assert-VerifiableMock - } - - Describe 'DscResource.LocalizationHelper\New-InvalidArgumentException' { - Context 'When calling with both the Message and ArgumentName parameter' { - It 'Should throw the correct error' { - $mockErrorMessage = 'Mocked error' - $mockArgumentName = 'MockArgument' - - { New-InvalidArgumentException -Message $mockErrorMessage -ArgumentName $mockArgumentName } | Should -Throw ('Parameter name: {0}' -f $mockArgumentName) - } - } - - Assert-VerifiableMock - } - - Describe 'DscResource.LocalizationHelper\Test-IsNanoServer' { - Context 'When the cmdlet Get-ComputerInfo does not exist' { - BeforeAll { - Mock -CommandName Test-Command { - return $false - } - } - - Test-IsNanoServer | Should -BeFalse - } - - Context 'When the current computer is a Nano server' { - BeforeAll { - Mock -CommandName Test-Command { - return $true - } - - Mock -CommandName Get-ComputerInfo { - return @{ - OsProductType = 'Server' - OsServerLevel = 'NanoServer' - } - } - } - - Test-IsNanoServer | Should -BeTrue - } - - Context 'When the current computer is not a Nano server' { - BeforeAll { - Mock -CommandName Test-Command { - return $true - } - - Mock -CommandName Get-ComputerInfo { - return @{ - OsProductType = 'Server' - OsServerLevel = 'FullServer' - } - } - } - - Test-IsNanoServer | Should -BeFalse - } - } - } -} -finally -{ - #region FOOTER - #endregion -} diff --git a/Tests/Unit/MSFT_PowerPlan.Tests.ps1 b/Tests/Unit/MSFT_PowerPlan.Tests.ps1 deleted file mode 100644 index fba0fa0e..00000000 --- a/Tests/Unit/MSFT_PowerPlan.Tests.ps1 +++ /dev/null @@ -1,300 +0,0 @@ -#region HEADER -$script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_PowerPlan' - -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global - -# Unit Test Template Version: 1.2.4 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force - -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -ResourceType 'Mof' ` - -TestType Unit -#endregion HEADER - -function Invoke-TestCleanup -{ - Restore-TestEnvironment -TestEnvironment $TestEnvironment -} - -# Begin Testing -try -{ - # Assign the localized data from the module into a local variable - $LocalizedData = InModuleScope $script:dscResourceName { - $LocalizedData - } - - $testCases =@( - # Power plan as name specified - @{ - Type = 'Name' - Name = 'High performance' - }, - - # Power plan as Guid specified - @{ - Type = 'Guid' - Name = '8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' - } - ) - - Describe "$($script:dscResourceName)\Get-TargetResource" { - Context 'When the system is in the desired present state' { - BeforeEach { - Mock ` - -CommandName Get-PowerPlan ` - -MockWith { - return @{ - FriendlyName = 'High performance' - Guid = [System.Guid]'8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' - } - } ` - -ModuleName $script:dscResourceName ` - -Verifiable - - Mock ` - -CommandName Get-ActivePowerPlan ` - -MockWith { - return [System.Guid]'8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' - } ` - -ModuleName $script:dscResourceName ` - -Verifiable - } - - It 'Should return the same values as passed as parameters (power plan specified as )' -TestCases $testCases { - param - ( - [System.String] - $Name - ) - - $result = Get-TargetResource -Name $Name -IsSingleInstance 'Yes' -Verbose - $result.IsSingleInstance | Should -Be 'Yes' - $result.Name | Should -Be $Name - $result.IsActive | Should -BeTrue - } - } - - Context 'When the system is not in the desired present state' { - BeforeEach { - Mock ` - -CommandName Get-PowerPlan ` - -MockWith { - return @{ - FriendlyName = 'High performance' - Guid = [System.Guid]'8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' - } - } ` - -ModuleName $script:dscResourceName ` - -Verifiable - - Mock ` - -CommandName Get-ActivePowerPlan ` - -MockWith { - return [System.Guid]'381b4222-f694-41f0-9685-ff5bb260df2e' - } ` - -ModuleName $script:dscResourceName ` - -Verifiable - } - - It 'Should return an inactive plan (power plan specified as )' -TestCases $testCases { - - param - ( - [System.String] - $Name - ) - - $result = Get-TargetResource -Name $Name -IsSingleInstance 'Yes' -Verbose - $result.IsSingleInstance | Should -Be 'Yes' - $result.Name | Should -Be $Name - $result.IsActive | Should -BeFalse - } - } - - Context 'When the preferred plan does not exist' { - BeforeEach { - Mock ` - -CommandName Get-PowerPlan ` - -ModuleName $script:dscResourceName ` - -Verifiable - } - - It 'Should throw the expected error (power plan specified as )' -TestCases $testCases { - - param - ( - [System.String] - $Name - ) - - $errorRecord = Get-InvalidOperationRecord ` - -Message ($LocalizedData.PowerPlanNotFound -f $Name) - - { Get-TargetResource -Name $Name -IsSingleInstance 'Yes' -Verbose } | Should -Throw $errorRecord - } - - Assert-VerifiableMock - } - } - - Describe "$($script:dscResourceName)\Set-TargetReource" { - BeforeEach { - Mock ` - -CommandName Get-PowerPlan ` - -MockWith { - return @{ - FriendlyName = 'High performance' - Guid = [System.Guid]'8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' - } - } ` - -ModuleName $script:dscResourceName ` - -Verifiable - - Mock ` - -CommandName Set-ActivePowerPlan ` - -ModuleName $script:dscResourceName ` - -Verifiable - } - - Context 'When the system is not in the desired present state' { - It 'Should call Get-PowerPlan once (power plan specified as )' -TestCases $testCases { - param - ( - [System.String] - $Name - ) - - Set-TargetResource -Name $Name -IsSingleInstance 'Yes' -Verbose - - Assert-MockCalled -CommandName Get-PowerPlan -Exactly -Times 1 -Scope It -ModuleName $script:dscResourceName - } - - It 'Should call Set-ActivePowerPlan once (power plan specified as )' -TestCases $testCases { - param - ( - [System.String] - $Name - ) - - Set-TargetResource -Name $Name -IsSingleInstance 'Yes' -Verbose - - Assert-MockCalled ` - -CommandName Set-ActivePowerPlan ` - -Exactly ` - -Times 1 ` - -Scope It ` - -ModuleName $script:dscResourceName ` - -ParameterFilter {$PowerPlanGuid -eq '8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c'} - } - } - - Context 'When the preferred plan does not exist' { - BeforeEach { - Mock ` - -CommandName Get-PowerPlan ` - -ModuleName $script:dscResourceName ` - -Verifiable - } - - It 'Should throw the expected error (power plan specified as )' -TestCases $testCases { - param - ( - [System.String] - $Name - ) - - $errorRecord = Get-InvalidOperationRecord ` - -Message ($LocalizedData.PowerPlanNotFound -f $Name) - - { Set-TargetResource -Name $Name -IsSingleInstance 'Yes' -Verbose } | Should -Throw $errorRecord - } - } - - Assert-VerifiableMock - } - Describe "$($script:dscResourceName)\Test-TargetResource" { - Context 'When the system is in the desired present state' { - BeforeEach { - Mock ` - -CommandName Get-PowerPlan ` - -MockWith { - return @{ - FriendlyName = 'High performance' - Guid = [System.Guid]'8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' - } - } ` - -ModuleName $script:dscResourceName ` - -Verifiable - - Mock ` - -CommandName Get-ActivePowerPlan ` - -MockWith { - return [System.Guid]'8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' - } ` - -ModuleName $script:dscResourceName ` - -Verifiable - } - - - It 'Should return the the state as present ($true) (power plan specified as )' -TestCases $testCases { - param - ( - [System.String] - $Name - ) - - Test-TargetResource -Name $Name -IsSingleInstance 'Yes' -Verbose | Should -BeTrue - } - } - - Context 'When the system is not in the desired state' { - BeforeEach { - Mock ` - -CommandName Get-PowerPlan ` - -MockWith { - return @{ - FriendlyName = 'High performance' - Guid = [System.Guid]'8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' - } - } ` - -ModuleName $script:dscResourceName ` - -Verifiable - - Mock ` - -CommandName Get-ActivePowerPlan ` - -MockWith { - return [System.Guid]'381b4222-f694-41f0-9685-ff5bb260df2e' - } ` - -ModuleName $script:dscResourceName ` - -Verifiable - } - - It 'Should return the the state as absent ($false) (power plan specified as )' -TestCases $testCases { - param - ( - [System.String] - $Name - ) - - Test-TargetResource -Name $Name -IsSingleInstance 'Yes' -Verbose | Should -BeFalse - } - } - - Assert-VerifiableMock - } -} -finally -{ - Invoke-TestCleanup -} diff --git a/Tests/Unit/MSFT_WindowsCapability.Tests.ps1 b/Tests/Unit/MSFT_WindowsCapability.Tests.ps1 deleted file mode 100644 index 5f5a1183..00000000 --- a/Tests/Unit/MSFT_WindowsCapability.Tests.ps1 +++ /dev/null @@ -1,302 +0,0 @@ -#region HEADER -$script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_WindowsCapability' - -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global - -# Unit Test Template Version: 1.2.4 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force - -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -ResourceType 'Mof' ` - -TestType Unit -#endregion HEADER - -# Begin Testing -try -{ - InModuleScope $script:dscResourceName { - $script:testResourceName = 'Test' - - $script:testAndSetTargetResourceParametersPresent = @{ - Name = $script:testResourceName - Ensure = 'Present' - } - - $script:testAndSetTargetResourceParametersAbsent = @{ - Name = $script:testResourceName - Ensure = 'Absent' - } - - $getWindowsCapabilityIsInstalled = { - @{ - Name = 'Test' - State = 'Installed' - Ensure = 'Present' - } - } - - $getWindowsCapabilityIsNotInstalled = { - @{ - Name = 'Test' - State = 'NotPresent' - Ensure = 'Absent' - } - } - - function Get-WindowsCapability - { - [CmdletBinding()] - param - ( - [Parameter()] - [System.String] - $Name, - - [Parameter()] - [Switch] - $Online = $true - ) - } - - function Add-WindowsCapability - { - [CmdletBinding()] - param - ( - [Parameter()] - [System.String] - $Name, - - [Parameter()] - [Switch] - $Online = $true - ) - } - - function Remove-WindowsCapability - { - [CmdletBinding()] - param - ( - [Parameter()] - [System.String] - $Name, - - [Parameter()] - [Switch] - $Online = $true - ) - } - - Describe "MSFT_WindowsCapability\Get-TargetResource" { - Context 'When a Windows Capability is enabled and it should' { - Mock -CommandName Get-WindowsCapability ` - -MockWith $getWindowsCapabilityIsInstalled ` - -ModuleName 'MSFT_WindowsCapability' ` - -Verifiable - - It 'Should not throw an exception' { - { - $script:getTargetResourceResult = Get-TargetResource -Name $script:testResourceName -Verbose - } | Should -Not -Throw - } - - It 'Should return expected result' { - $script:getTargetResourceResult.Name | Should -Be $script:testResourceName - $script:getTargetResourceResult.State | Should -Be 'Installed' - } - - It 'Should call all verifiable mocks' { - Assert-VerifiableMock - } - } - - Context 'When a Windows Capability is not enabled' { - Mock -CommandName Get-WindowsCapability ` - -MockWith $getWindowsCapabilityIsNotInstalled ` - -ModuleName 'MSFT_WindowsCapability' ` - -Verifiable - - It 'Should not throw an exception' { - { - $script:getTargetResourceResult = Get-TargetResource -Name $script:testResourceName -Verbose - } | Should -Not -Throw - } - - It 'Should return expected result' { - $script:getTargetResourceResult.Name | Should -Be $script:testResourceName - $script:getTargetResourceResult.State | Should -Be 'NotPresent' - } - - It 'Should call all verifiable mocks' { - Assert-VerifiableMock - } - } - } - - Describe "MSFT_WindowsCapability\Test-TargetResource" { - Context 'When a Windows Capability is enabled' { - Mock -CommandName Get-WindowsCapability ` - -MockWith $getWindowsCapabilityIsInstalled ` - -ModuleName 'MSFT_WindowsCapability' ` - -Verifiable - - It 'Should not throw an exception' { - { - $script:testTargetResourceResult = Test-TargetResource $script:testAndSetTargetResourceParametersPresent - } | Should -Not -Throw - } - - It 'Should return true' { - $script:testTargetResourceResult | Should -BeTrue - } - - It 'Should call all verifiable mocks' { - Assert-VerifiableMock - } - } - - Context 'When a Windows Capability is not enabled' { - Mock -CommandName Get-WindowsCapability ` - -MockWith $getWindowsCapabilityIsNotInstalled ` - -ModuleName 'MSFT_WindowsCapability' ` - -Verifiable - - It 'Should not throw an exception' { - { - $script:testTargetResourceResult = Test-TargetResource $script:testAndSetTargetResourceParametersAbsent - } | Should -Not -Throw - } - - It 'Should return true' { - $script:testTargetResourceResult | Should -BeTrue - } - - It 'Should call all verifiable mocks' { - Assert-VerifiableMock - } - } - } - - Describe "MSFT_WindowsCapability\Set-TargetResource" { - - Context 'When a Windows Capability is not enabled' { - Mock -CommandName Get-WindowsCapability ` - -MockWith $getWindowsCapabilityIsNotInstalled ` - -ModuleName 'MSFT_WindowsCapability' ` - -Verifiable - - Mock -CommandName Add-WindowsCapability -MockWith {} - - It 'Should not throw an exception' { - { - Set-TargetResource @script:testAndSetTargetResourceParametersAbsent - } | Should -Not -Throw - } - - It 'Should call Add-WindowsCapability when Ensure set to Present' { - { - Set-TargetResource -Name $testResourceName - } | Should -Not -Throw - Assert-MockCalled -CommandName Add-WindowsCapability -Times 1 -Exactly -Scope It - } - - It 'Should call Get-WindowsCapability when Ensure set to Present' { - { Set-TargetResource -Name $testResourceName } | Should -Not -Throw - Assert-MockCalled -CommandName Get-WindowsCapability -Times 1 -Exactly -Scope It - } - } - - Context 'When a Windows Capability is already enabled' { - Mock -CommandName Get-WindowsCapability ` - -MockWith $getWindowsCapabilityIsInstalled ` - -ModuleName 'MSFT_WindowsCapability' ` - -Verifiable - - Mock -CommandName Add-WindowsCapability -MockWith {} - - It 'Should not throw an exception' { - { - Set-TargetResource @script:testAndSetTargetResourceParametersPresent - } | Should -Not -Throw - } - - It 'Should not call Add-WindowsCapability when Windows Capability is already enabled' { - { Set-TargetResource -Name $testResourceName } | Should -Not -Throw - Assert-MockCalled -CommandName Add-WindowsCapability -Times 0 -Exactly -Scope It - } - - It 'Should call Get-WindowsCapability when when Windows Capability is already enabled' { - { Set-TargetResource -Name $testResourceName } | Should -Not -Throw - Assert-MockCalled -CommandName Get-WindowsCapability -Times 1 -Exactly -Scope It - } - } - - Context 'When a Windows Capability is already disabled' { - Mock -CommandName Get-WindowsCapability ` - -MockWith $getWindowsCapabilityIsNotInstalled ` - -ModuleName 'MSFT_WindowsCapability' ` - -Verifiable - - Mock -CommandName Remove-WindowsCapability -MockWith {} - - It 'Should not throw an exception' { - { - Set-TargetResource @script:testAndSetTargetResourceParametersPresent - } | Should -Not -Throw - } - - It 'Should not call Remove-WindowsCapability when Windows Capability is already disabled' { - { - Set-TargetResource -Name $testResourceName - } | Should -Not -Throw - Assert-MockCalled -CommandName Remove-WindowsCapability -Times 0 -Exactly -Scope It - } - - It 'Should call Get-WindowsCapability when when Windows Capability is already enabled' { - { Set-TargetResource -Name $testResourceName } | Should -Not -Throw - Assert-MockCalled -CommandName Get-WindowsCapability -Times 1 -Exactly -Scope It - } - } - - Context 'When a Windows Capability is enabled and should not be' { - Mock -CommandName Get-WindowsCapability ` - -MockWith $getWindowsCapabilityIsInstalled ` - -ModuleName 'MSFT_WindowsCapability' ` - -Verifiable - - Mock -CommandName Remove-WindowsCapability -MockWith {} - - It 'Should not throw an exception' { - { - Set-TargetResource @script:testAndSetTargetResourceParametersAbsent - } | Should -Not -Throw - } - - It 'Should call Remove-WindowsCapability when Ensure set to Absent' { - { Set-TargetResource -Name $testResourceName -Ensure 'Absent' } | Should -Not -Throw - Assert-MockCalled -CommandName Remove-WindowsCapability -Times 1 -Exactly -Scope It - } - - It 'Should call Get-WindowsCapability when Windows Capability is set to Absent' { - { Set-TargetResource -Name $testResourceName -Ensure 'Absent' } | Should -Not -Throw - Assert-MockCalled -CommandName Get-WindowsCapability -Times 1 -Exactly -Scope It - } - } - } - } -} -finally -{ - Restore-TestEnvironment -TestEnvironment $TestEnvironment -} diff --git a/Tests/Unit/MSFT_WindowsEventLog.Tests.ps1 b/Tests/Unit/MSFT_WindowsEventLog.Tests.ps1 deleted file mode 100644 index 4149d044..00000000 --- a/Tests/Unit/MSFT_WindowsEventLog.Tests.ps1 +++ /dev/null @@ -1,391 +0,0 @@ -#region HEADER -$script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_WindowsEventLog' - -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global - -# Unit Test Template Version: 1.2.4 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force - -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -ResourceType 'Mof' ` - -TestType Unit -#endregion HEADER - -# Begin Testing -try -{ - InModuleScope $script:dscResourceName { - $script:dscResourceName = 'MSFT_WindowsEventLog' - - Describe "$($script:dscResourceName)\Get-TargetResource" -Tag 'Get' { - - Mock -CommandName Get-WindowsEventLog -MockWith { - $properties = @{ - MaximumSizeInBytes = 4096kb - IsEnabled = $true - LogMode = 'Circular' - LogFilePath = '%SystemRoot%\System32\Winevt\Logs\Application.evtx' - SecurityDescriptor = 'TestDescriptor' - LogRetentionDays = '0' - LogName = 'Application' - } - - return (New-Object -TypeName PSObject -Property $properties) - } - - $results = Get-TargetResource -LogName 'Application' -IsEnabled $true - - It 'Should return an hashtable' { - $results.GetType().Name | Should -Be 'Hashtable' - } - - It 'Should return a Logname Application' { - $results.LogName = 'Application' - } - - It 'Should return a MaximumSizeInBytes of 4096kb' { - $results.MaximumSizeInBytes | Should -Be 4096kb - } - - It 'Should return IsEnabled is true' { - $results.IsEnabled | Should -BeTrue - } - - It 'Should return a LogMode is Circular' { - $results.LogMode | Should -Be 'Circular' - } - - It 'Should return a LogRetentionDays of 0' { - $results.LogRetentionDays | Should -Be 0 - } - - It 'Should return a LogFilePath of %SystemRoot%\System32\Winevt\Logs\Application.evtx' { - $results.LogFilePath | Should -Be "%SystemRoot%\System32\Winevt\Logs\Application.evtx" - } - - It 'Should return SecurityDescriptor with a value TestDescriptor' { - $results.SecurityDescriptor | Should -Be 'TestDescriptor' - } - } - - Describe "$($script:dscResourceName)\Test-TargetResource" -Tag 'Test' { - - Mock -CommandName Get-WindowsEventLog -MockWith { - $properties = @{ - MaximumSizeInBytes = 1028kb - IsEnabled = $true - LogMode = 'Circular' - LogFilePath = '%SystemRoot%\System32\Winevt\Logs\Application.evtx' - SecurityDescriptor = 'TestDescriptor' - LogRetentionDays = '7' - LogName = 'Application' - } - - return (New-Object -TypeName PSObject -Property $properties) - } - - Mock -CommandName Get-EventLog -MockWith { - $params = @{ - MinimumRetentionDays = '7' - Log = 'Application' - } - - return (New-Object -TypeName PSObject -Property $params) - } - - It 'Should not throw when passed an valid Logname' { - { Test-TargetResource -LogName 'Application' -IsEnabled $true -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should throw when passed an invalid LogMode' { - { Test-TargetResource -LogName 'Application' -LogMode 'BadLogmode' -IsEnabled $true -ErrorAction Stop } | Should -Throw - } - - It 'Should not throw when passed an valid LogMode' { - { Test-TargetResource -LogName 'Application' -LogMode 'Circular' -IsEnabled $true -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should return $true if Logmode is in desired state' { - Test-TargetResource -LogName 'Application' -LogMode 'Circular' -IsEnabled $true | Should -BeTrue - } - - It 'Should return $false if Logmode is not in desired state' { - Test-TargetResource -LogName 'Application' -LogMode 'AutoBackup' -IsEnabled $false | Should -BeFalse - } - - It 'Should throw when passed an invalid MaximumSizeInBytes below 1028kb' { - { Test-TargetResource -LogName 'Application' -LogMode 'Circular' -IsEnabled $true -MaximumSizeInBytes 1027kb -ErrorAction Stop } | Should -Throw - } - - It 'Shoudl throw when passed an invalid MaximumSizeInBytes above 18014398509481983kb' { - { Test-TargetResource -LogName 'Application' -LogMode 'Circular' -IsEnabled $true -MaximumSizeInBytes 18014398509481983kb -ErrorAction Stop } | Should -Throw - } - - It 'Should return $true if MaximumSizeInBytes is in desired state' { - Test-TargetResource -MaximumSizeInBytes 1028kb -LogName 'Application' -IsEnabled $true | Should -BeTrue - } - - It 'Should return $false if MaximumSizeInBytes is not in desired state' { - Test-TargetResource -MaximumSizeInBytes 2048kb -LogName 'Application' -IsEnabled $true | Should -BeFalse - } - - It 'Should not throw when passed an valid MaximumSizeInBytes' { - { Test-TargetResource -LogName 'Application' -MaximumSizeInBytes 1028kb -IsEnabled $true -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should throw when passed an invalid LogRetentionDays below 1 day' { - { Test-TargetResource -LogName 'Application' -LogMode 'AutoBackup' -IsEnabled $true -LogRetentionDays 0 -ErrorAction Stop } | Should -Throw - } - - It 'Should throw when passed an invalid LogRetentionDays above 365 days' { - { Test-TargetResource -LogName 'Application' -LogMode 'AutoBackup' -IsEnabled $true -LogRetentionDays 366 -ErrorAction Stop } | Should -Throw - } - - It 'Should not throw when passed an valid LogRetentionDays' { - { Test-TargetResource -LogName 'Application' -LogMode 'AutoBackup' -LogRetentionDays 30 -IsEnabled $true -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should return $false if LogRetentionDays is not in desired state' { - Test-TargetResource -LogName 'Application' -IsEnabled $true -LogRetentionDays 13 -LogMode 'AutoBackup' | Should -BeFalse - } - - It 'Should return $true if LogRetentionDays is in desired state' { - Mock -CommandName Get-WindowsEventLog -MockWith { - $properties = @{ - MaximumSizeInBytes = 1028kb - IsEnabled = $true - LogMode = 'AutoBackup' - LogFilePath = '%SystemRoot%\System32\Winevt\Logs\Application.evtx' - SecurityDescriptor = 'TestDescriptor' - LogRetentionDays = '7' - LogName = 'Application' - } - - return (New-Object -TypeName PSObject -Property $properties) - } - - Test-TargetResource -LogName 'Application' -IsEnabled $true -LogRetentionDays 7 -LogMode 'AutoBackup' | Should -BeTrue - } - - It 'Should not throw when passed an invalid LogRetentionDays' { - { Test-TargetResource -LogName 'WrongLog' -LogMode 'AutoBackup' -LogRetentionDays 30 -IsEnabled $true -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should not throw when passed an invalid LogMode with LogRetention' { - { Test-TargetResource -LogName 'Application' -LogMode 'Circular' -LogRetentionDays 30 -IsEnabled $true -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should not throw when passed an valid LogFilePath' { - { Test-TargetResource -LogName 'Application' -IsEnabled $true -LogFilePath '%SystemRoot%\System32\Winevt\Logs\Application.evtx' -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should return $true if LogFilePath is in desired state' { - Test-TargetResource -LogName 'Application' -LogFilePath '%SystemRoot%\System32\Winevt\Logs\Application.evtx' -IsEnabled $true | Should -BeTrue - } - - It 'Should return $false if LogFilePath is not in desired state' { - Test-TargetResource -LogName 'Application' -LogFilePath '%SystemRoot%\System32\Winevt\OtherLogs\Application.evtx' -IsEnabled $true | Should -BeFalse - } - - It 'Should not throw when passed an valid SecurityDescriptor' { - { Test-TargetResource -LogName 'Application' -SecurityDescriptor 'TestDescriptor' -IsEnabled $true -ErrorAction Stop } | Should -Not -Throw - } - - It 'Should return $true if SecurityDescriptor is in desired state' { - Test-TargetResource -LogName 'Application' -SecurityDescriptor 'TestDescriptor' -IsEnabled $true | Should -BeTrue - } - - It 'Should return $false if SecurityDescriptor is not in desired state' { - Test-TargetResource -LogName 'Application' -SecurityDescriptor 'TestTestDescriptor' -IsEnabled $true | Should -BeFalse - } - - It 'Should return $true if IsEnabled is in desired state' { - Test-TargetResource -LogName 'Application' -IsEnabled $true | Should -BeTrue - } - - It 'Should return $false if IsEnabled is not in desired state' { - Test-TargetResource -LogName 'Application' -IsEnabled $false | Should -BeFalse - } - - It 'Should return $false if IsEnabled is not in desired state' { - Mock -CommandName Get-WindowsEventLog -MockWith { - $properties = @{ - MaximumSizeInBytes = 1028kb - IsEnabled = $false - LogName = 'Application' - } - - return (New-Object -TypeName PSObject -Property $properties) - } - - Test-TargetResource -LogName 'Application' -IsEnabled $true | Should -BeFalse - } - - It 'Should return $true if IsEnabled is not in desired state' { - Mock -CommandName Get-WindowsEventLog -MockWith { - $properties = @{ - MaximumSizeInBytes = 1028kb - IsEnabled = $true - LogName = 'Application' - } - - return (New-Object -TypeName PSObject -Property $properties) - } - - Test-TargetResource -LogName 'Application' -IsEnabled $true | Should -BeTrue - } - } - - Describe "$($script:dscResourceName)\Set-TargetResource" -Tag 'Set' { - Mock -CommandName Get-WindowsEventLog -MockWith { - $properties = @{ - MaximumSizeInBytes = 5000kb - IsEnabled = $true - LogMode = 'AutoBackup' - LogFilePath = 'c:\logs\test.evtx' - SecurityDescriptor = 'TestDescriptor' - LogRetentionDays = '7' - LogName = 'TestLog' - } - - return (New-Object -TypeName PSObject -Property $properties) - } - - Mock -CommandName Get-EventLog -MockWith { - $params = @{ - MinimumRetentionDays = '7' - Log = 'TestLog' - } - - return (New-Object -TypeName PSObject -Property $params) - } - - It 'Should set MaximumSizeInBytes to 1028kb' { - Mock -CommandName Save-LogFile - Set-TargetResource -MaximumSizeInBytes 1028kb -IsEnabled $true -LogName 'TestLog' - Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 1 -Scope It - } - - It 'MaximumSizeInBytes is in desired state' { - Mock -CommandName Save-LogFile - Set-TargetResource -MaximumSizeInBytes 5000kb -IsEnabled $true -LogName 'TestLog' - Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 0 -Scope It - } - - It 'Should set SecurityDescriptor to OtherTestDescriptor' { - Mock -CommandName Save-LogFile - Set-TargetResource -IsEnabled $true -LogName 'TestLog' -SecurityDescriptor 'OtherTestDescriptor' - Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 1 -Scope It - } - - It 'SecurityDescriptor is in desired state' { - Mock -CommandName Save-LogFile - Set-TargetResource -IsEnabled $true -LogName 'TestLog' -SecurityDescriptor 'TestDescriptor' - Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 0 -Scope It - } - - It 'Should set LogFilePath to default path' { - Mock -CommandName Save-LogFile - Set-TargetResource -IsEnabled $true -LogName 'TestLog' -LogFilePath '%SystemRoot%\System32\Winevt\Logs\Application.evtx' - Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 1 -Scope It - } - - It 'LogFilePath is in desired state' { - Mock -CommandName Save-LogFile - Set-TargetResource -IsEnabled $true -LogName 'TestLog' -LogFilePath 'c:\logs\test.evtx' - Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 0 -Scope It - } - - It 'Should set LogRetentionDays to 14 days' { - Mock -CommandName Set-LogRetentionDays - Set-TargetResource -LogRetentionDays '14' -IsEnabled $true -LogName 'TestLog' -LogMode 'Autobackup' - Assert-MockCalled -CommandName Set-LogRetentionDays -Exactly -Times 1 -Scope It - } - - It 'Should set LogRetentionDays to 32 days, wrong Logmode' { - Mock -CommandName Set-LogRetentionDays - Set-TargetResource -LogRetentionDays '32' -IsEnabled $true -LogName 'TestLog' -LogMode 'Circular' - Assert-MockCalled -CommandName Set-LogRetentionDays -Exactly -Times 0 -Scope It - } - - It 'Should set LogRetentionDays is in desired state' { - Mock -CommandName Set-LogRetentionDays - Set-TargetResource -LogRetentionDays '7' -IsEnabled $true -LogName 'TestLog' -LogMode 'Autobackup' - Assert-MockCalled -CommandName Set-LogRetentionDays -Exactly -Times 0 -Scope It - } - - It 'Should set IsEnabled to false' { - Mock -CommandName Save-LogFile - Set-TargetResource -IsEnabled $false -LogName 'TestLog' - Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 1 -Scope It - } - - It 'IsEnabled is in desired state' { - Mock -CommandName Save-LogFile - Set-TargetResource -IsEnabled $true -LogName 'TestLog' - Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 0 -Scope It - } - - It 'IsEnabled is not in desired state' { - Mock -CommandName Save-LogFile - Set-TargetResource -IsEnabled $false -LogName 'TestLog' - Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 1 -Scope It - } - - It 'Should throw if IsEnabled is not in desired state' { - Mock -CommandName Save-LogFile - Mock -CommandName Get-WindowsEventLog -MockWith { throw } - { Set-TargetResource -LogName 'SomeLog' -IsEnabled $false } | Should -Throw - } - - It 'IsEnabled is not in desired state' { - Mock -CommandName Get-WindowsEventLog -MockWith { - $properties = @{ - MaximumSizeInBytes = 5000kb - IsEnabled = $false - LogMode = 'AutoBackup' - LogFilePath = 'c:\logs\test.evtx' - SecurityDescriptor = 'TestDescriptor' - LogRetentionDays = '7' - LogName = 'TestLog' - } - - return (New-Object -TypeName PSObject -Property $properties) - } - - Set-TargetResource -IsEnabled $true -LogName 'TestLog' - Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 1 -Scope It - } - - Describe "$($script:dscResourceName)\Save-LogFile" -Tag 'Helper' { - Mock -CommandName Limit-Eventlog -MockWith { throw } - - It 'Should throw if we are unable to get a log' { - { Limit-Eventlog -LogName 'Application' -OverflowAction 'OverwriteOlder' -RetentionDays 30 } | Should -Throw - } - } - - Describe "$($script:dscResourceName)\Set-LogRetentionDays" -Tag 'Helper' { - Mock -CommandName Limit-Eventlog -MockWith { throw } - - It 'Should throw if we are unable to get a log' { - { Limit-Eventlog -LogName 'Application' -OverflowAction 'OverwriteOlder' -RetentionDays 30 } | Should -Throw - } - } - } - } -} -finally -{ - Restore-TestEnvironment -TestEnvironment $TestEnvironment -} diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 84c8d717..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,44 +0,0 @@ -#---------------------------------# -# environment configuration # -#---------------------------------# -version: 1.9.{build}.0 -environment: - gallery_api: - secure: 9ekJzfsPCDBkyLrfmov83XbbhZ6E2N3z+B/Io8NbDetbHc6hWS19zsDmy7t0Vvxv -install: - - git clone https://github.com/PowerShell/DscResource.Tests - - - ps: | - $moduleName = 'ComputerManagementDsc' - Import-Module "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" - Invoke-AppveyorInstallTask - -#---------------------------------# -# build configuration # -#---------------------------------# - -build: false - -#---------------------------------# -# test configuration # -#---------------------------------# - -test_script: - - ps: | - Invoke-AppveyorTestScriptTask ` - -CodeCoverage ` - -CodeCovIo ` - -ExcludeTag @() - -#---------------------------------# -# deployment configuration # -#---------------------------------# - -# scripts to run before deployment -deploy_script: - - ps: | - Invoke-AppveyorAfterTestTask ` - -Type 'Wiki' ` - -ResourceModuleName $moduleName - - Invoke-AppVeyorDeployTask diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 00000000..f272d3ed --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,293 @@ +trigger: + branches: + include: + - master + paths: + exclude: + - CHANGELOG.md + tags: + include: + - "v*" + exclude: + - "*-*" + +stages: + - stage: Build + jobs: + - job: Package_Module + displayName: 'Package Module' + pool: + vmImage: 'ubuntu 16.04' + steps: + - task: GitVersion@5 + name: gitversion + displayName: 'Evaluate Next Version' + inputs: + runtime: 'core' + configFilePath: 'GitVersion.yml' + + - task: PowerShell@2 + name: package + displayName: 'Build & Package Module' + inputs: + filePath: './build.ps1' + arguments: '-Tasks pack -ResolveDependency' + pwsh: true + env: + ModuleVersion: $(gitVersion.Informationalversion) + + - task: PublishBuildArtifacts@1 + displayName: 'Publish Build Artifact' + inputs: + PathtoPublish: 'output/' + ArtifactName: 'output' + publishLocation: 'Container' + + - stage: Test + dependsOn: Build + jobs: + - job: Test_HQRM + displayName: 'HQRM' + pool: + vmImage: 'windows-2019' + timeoutInMinutes: 0 + steps: + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifact' + inputs: + buildType: 'current' + downloadType: 'single' + artifactName: 'output' + downloadPath: '$(Build.SourcesDirectory)' + + - task: PowerShell@2 + name: test + displayName: 'Run HQRM Test' + inputs: + filePath: './build.ps1' + arguments: '-Tasks hqrmtest' + pwsh: false + + - task: PublishTestResults@2 + displayName: 'Publish Test Results' + inputs: + testResultsFormat: 'NUnit' + testResultsFiles: 'output/testResults/NUnit*.xml' + testRunTitle: 'HQRM' + condition: succeededOrFailed() + + - job: Test_Unit_2016 + displayName: 'Unit (Windows Server 2016)' + pool: + vmImage: 'vs2017-win2016' + timeoutInMinutes: 0 + steps: + - powershell: | + $repositoryOwner,$repositoryName = $env:BUILD_REPOSITORY_NAME -split '/' + echo "##vso[task.setvariable variable=RepositoryOwner;isOutput=true]$repositoryOwner" + echo "##vso[task.setvariable variable=RepositoryName;isOutput=true]$repositoryName" + name: dscBuildVariable + displayName: 'Set Environment Variables' + + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifact' + inputs: + buildType: 'current' + downloadType: 'single' + artifactName: 'output' + downloadPath: '$(Build.SourcesDirectory)' + + - task: PowerShell@2 + name: test + displayName: 'Run Unit Test' + inputs: + filePath: './build.ps1' + arguments: "-Tasks test -PesterScript 'tests/Unit'" + pwsh: false + + - task: PublishTestResults@2 + displayName: 'Publish Test Results' + inputs: + testResultsFormat: 'NUnit' + testResultsFiles: 'output/testResults/NUnit*.xml' + testRunTitle: 'Unit (Windows Server 2016)' + condition: succeededOrFailed() + + - task: PublishCodeCoverageResults@1 + displayName: 'Publish Code Coverage' + condition: succeededOrFailed() + inputs: + codeCoverageTool: 'JaCoCo' + summaryFileLocation: 'output/testResults/CodeCov*.xml' + pathToSources: '$(Build.SourcesDirectory)/output/$(DscBuildVariable.RepositoryName)' + + - job: Test_Integration_2016 + displayName: 'Integration (Windows Server 2016)' + pool: + vmImage: 'vs2017-win2016' + timeoutInMinutes: 0 + steps: + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifact' + inputs: + buildType: 'current' + downloadType: 'single' + artifactName: 'output' + downloadPath: '$(Build.SourcesDirectory)' + + - task: PowerShell@2 + name: configureWinRM + displayName: 'Configure WinRM' + inputs: + targetType: 'inline' + script: 'winrm quickconfig -quiet' + pwsh: false + + - powershell: | + Set-Service -Name wuauserv -StartupType Manual -Verbose + Start-Service -name wuauserv -Verbose + + - task: PowerShell@2 + name: test + displayName: 'Run Integration Test' + inputs: + filePath: './build.ps1' + arguments: "-Tasks test -PesterScript 'tests/Integration' -CodeCoverageThreshold 0" + pwsh: false + + - task: PublishTestResults@2 + displayName: 'Publish Test Results' + inputs: + testResultsFormat: 'NUnit' + testResultsFiles: 'output/testResults/NUnit*.xml' + testRunTitle: 'Integration (Windows Server 2016)' + condition: succeededOrFailed() + + - job: Test_Unit_2019 + displayName: 'Unit (Windows Server 2019)' + pool: + vmImage: 'windows-2019' + timeoutInMinutes: 0 + steps: + - powershell: | + $repositoryOwner,$repositoryName = $env:BUILD_REPOSITORY_NAME -split '/' + echo "##vso[task.setvariable variable=RepositoryOwner;isOutput=true]$repositoryOwner" + echo "##vso[task.setvariable variable=RepositoryName;isOutput=true]$repositoryName" + name: dscBuildVariable + displayName: 'Set Environment Variables' + + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifact' + inputs: + buildType: 'current' + downloadType: 'single' + artifactName: 'output' + downloadPath: '$(Build.SourcesDirectory)' + + - task: PowerShell@2 + name: test + displayName: 'Run Unit Test' + inputs: + filePath: './build.ps1' + arguments: "-Tasks test -PesterScript 'tests/Unit'" + pwsh: false + + - task: PublishTestResults@2 + displayName: 'Publish Test Results' + inputs: + testResultsFormat: 'NUnit' + testResultsFiles: 'output/testResults/NUnit*.xml' + testRunTitle: 'Unit (Windows Server 2019)' + condition: succeededOrFailed() + + - task: PublishCodeCoverageResults@1 + displayName: 'Publish Code Coverage' + condition: succeededOrFailed() + inputs: + codeCoverageTool: 'JaCoCo' + summaryFileLocation: 'output/testResults/CodeCov*.xml' + pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)' + + - job: Test_Integration_2019 + displayName: 'Integration (Windows Server 2019)' + pool: + vmImage: 'windows-2019' + timeoutInMinutes: 0 + steps: + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifact' + inputs: + buildType: 'current' + downloadType: 'single' + artifactName: 'output' + downloadPath: '$(Build.SourcesDirectory)' + + - task: PowerShell@2 + name: configureWinRM + displayName: 'Configure WinRM' + inputs: + targetType: 'inline' + script: 'winrm quickconfig -quiet' + pwsh: false + + - task: PowerShell@2 + name: test + displayName: 'Run Integration Test' + inputs: + filePath: './build.ps1' + arguments: "-Tasks test -PesterScript 'tests/Integration' -CodeCoverageThreshold 0" + pwsh: false + + - task: PublishTestResults@2 + displayName: 'Publish Test Results' + inputs: + testResultsFormat: 'NUnit' + testResultsFiles: 'output/testResults/NUnit*.xml' + testRunTitle: 'Integration (Windows Server 2019)' + condition: succeededOrFailed() + + - stage: Deploy + dependsOn: Test + condition: | + and( + succeeded(), + or( + eq(variables['Build.SourceBranch'], 'refs/heads/master'), + startsWith(variables['Build.SourceBranch'], 'refs/tags/') + ), + contains(variables['System.TeamFoundationCollectionUri'], 'dsccommunity') + ) + jobs: + - job: Deploy_Module + displayName: 'Deploy Module' + pool: + vmImage: 'ubuntu 16.04' + steps: + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifact' + inputs: + buildType: 'current' + downloadType: 'single' + artifactName: 'output' + downloadPath: '$(Build.SourcesDirectory)' + + - task: PowerShell@2 + name: publishRelease + displayName: 'Publish Release' + inputs: + filePath: './build.ps1' + arguments: '-tasks publish' + pwsh: true + env: + GitHubToken: $(GitHubToken) + GalleryApiToken: $(GalleryApiToken) + + - task: PowerShell@2 + name: sendChangelogPR + displayName: 'Send Changelog PR' + inputs: + filePath: './build.ps1' + arguments: '-tasks Create_ChangeLog_GitHub_PR' + pwsh: true + env: + GitHubToken: $(GitHubToken) diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 00000000..ff53c84f --- /dev/null +++ b/build.ps1 @@ -0,0 +1,354 @@ +<# + +.DESCRIPTION + Bootstrap and build script for PowerShell module pipeline + +#> +[CmdletBinding()] +param +( + [Parameter(Position = 0)] + [string[]]$Tasks = '.', + + [Parameter()] + [String] + $CodeCoverageThreshold = '', + + [Parameter()] + [validateScript( + { Test-Path -Path $_ } + )] + $BuildConfig = './build.yaml', + + [Parameter()] + # A Specific folder to build the artefact into. + $OutputDirectory = 'output', + + [Parameter()] + # Subdirectory name to build the module (under $OutputDirectory) + $BuiltModuleSubdirectory = '', + + # Can be a path (relative to $PSScriptRoot or absolute) to tell Resolve-Dependency & PSDepend where to save the required modules, + # or use CurrentUser, AllUsers to target where to install missing dependencies + # You can override the value for PSDepend in the Build.psd1 build manifest + # This defaults to $OutputDirectory/modules (by default: ./output/modules) + [Parameter()] + $RequiredModulesDirectory = $(Join-Path 'output' 'RequiredModules'), + + # Filter which tags to run when invoking Pester tests + # This is used in the Invoke-Pester.pester.build.ps1 tasks + [Parameter()] + [string[]] + $PesterTag, + + [Parameter()] + [string[]] + $PesterScript, + + # Filter which tags to exclude when invoking Pester tests + # This is used in the Invoke-Pester.pester.build.ps1 tasks + [Parameter()] + [string[]] + $PesterExcludeTag, + + [Parameter()] + [Alias('bootstrap')] + [switch] + $ResolveDependency, + + [Parameter(DontShow)] + [AllowNull()] + $BuildInfo, + + [Parameter()] + [switch] + $AutoRestore +) + +# The BEGIN block (at the end of this file) handles the Bootstrap of the Environment before Invoke-Build can run the tasks +# if the -ResolveDependency (aka Bootstrap) is specified, the modules are already available, and can be auto loaded + +process +{ + + if ($MyInvocation.ScriptName -notLike '*Invoke-Build.ps1') + { + # Only run the process block through InvokeBuild (Look at the Begin block at the bottom of this script) + return + } + + # Execute the Build Process from the .build.ps1 path. + Push-Location -Path $PSScriptRoot -StackName BeforeBuild + + try + { + Write-Host -ForeGroundColor magenta "[build] Parsing defined tasks" + + # Load Default BuildInfo if not provided as parameter + if (!$PSBoundParameters.ContainsKey('BuildInfo')) + { + try + { + if (Test-Path $BuildConfig) + { + $ConfigFile = (Get-Item -Path $BuildConfig) + Write-Host "[build] Loading Configuration from $ConfigFile" + $BuildInfo = switch -Regex ($ConfigFile.Extension) + { + # Native Support for PSD1 + '\.psd1' + { + Import-PowerShellDataFile -Path $BuildConfig + } + # Support for yaml when module PowerShell-Yaml is available + '\.[yaml|yml]' + { + Import-Module -ErrorAction Stop -Name 'powershell-yaml' + ConvertFrom-Yaml -Yaml (Get-Content -Raw $ConfigFile) + } + # Native Support for JSON and JSONC (by Removing comments) + '\.[json|jsonc]' + { + $JSONC = (Get-Content -Raw -Path $ConfigFile) + $JSON = $JSONC -replace '(?m)\s*//.*?$' -replace '(?ms)/\*.*?\*/' + # This should probably be converted to hashtable for splatting + $JSON | ConvertFrom-Json + } + default + { + Write-Error "Extension '$_' not supported. using @{}" + @{ } + } + } + } + else + { + Write-Host -Object "Configuration file $BuildConfig not found" -ForegroundColor Red + $BuildInfo = @{ } + } + } + catch + { + Write-Host -Object "Error loading Config $ConfigFile.`r`n Are you missing dependencies?" -ForegroundColor Yellow + Write-Host -Object "Make sure you run './build.ps1 -ResolveDependency -tasks noop' to restore the Required modules the first time" -ForegroundColor Yellow + $BuildInfo = @{ } + Write-Error $_.Exception.Message + } + } + + # If the Invoke-Build Task Header is specified in the Build Info, set it + if ($BuildInfo.TaskHeader) + { + Set-BuildHeader ([scriptblock]::Create($BuildInfo.TaskHeader)) + } + + # Import Tasks from modules via their exported aliases when defined in BUild Manifest + # https://github.com/nightroman/Invoke-Build/tree/master/Tasks/Import#example-2-import-from-a-module-with-tasks + if ($BuildInfo.containsKey('ModuleBuildTasks')) + { + foreach ($Module in $BuildInfo['ModuleBuildTasks'].Keys) + { + try + { + Write-Host -ForegroundColor DarkGray -Verbose "Importing tasks from module $Module" + $LoadedModule = Import-Module $Module -PassThru -ErrorAction Stop + foreach ($TaskToExport in $BuildInfo['ModuleBuildTasks'].($Module)) + { + $LoadedModule.ExportedAliases.GetEnumerator().Where{ + # using -like to support wildcard + Write-Host -ForegroundColor DarkGray "`t Loading $($_.Key)..." + $_.Key -like $TaskToExport + }.ForEach{ + # Dot sourcing the Tasks via their exported aliases + . (Get-Alias $_.Key) + } + } + } + catch + { + Write-Host -ForegroundColor Red -Object "Could not load tasks for module $Module." + Write-Error $_ + } + } + } + + # Loading Build Tasks defined in the .build/ folder (will override the ones imported above if same task name) + Get-ChildItem -Path ".build/" -Recurse -Include *.ps1 -ErrorAction Ignore | ForEach-Object { + "Importing file $($_.BaseName)" | Write-Verbose + . $_.FullName + } + + # Synopsis: Empty task, useful to test the bootstrap process + task noop { } + + # Define default task sequence ("."), can be overridden in the $BuildInfo + task . { + Write-Build Yellow "No sequence currently defined for the default task" + } + + # Load Invoke-Build task sequences/workflows from $BuildInfo + Write-Host -ForegroundColor DarkGray "Adding Workflow from configuration:" + foreach ($Workflow in $BuildInfo.BuildWorkflow.keys) + { + Write-Verbose "Creating Build Workflow '$Workflow' with tasks $($BuildInfo.BuildWorkflow.($Workflow) -join ', ')" + $WorkflowItem = $BuildInfo.BuildWorkflow.($Workflow) + if ($WorkflowItem.Trim() -match '^\{(?[\w\W]*)\}$') + { + $WorkflowItem = [ScriptBlock]::Create($Matches['sb']) + } + Write-Host -ForegroundColor DarkGray " +-> $Workflow" + task $Workflow $WorkflowItem + } + + Write-Host -ForeGroundColor magenta "[build] Executing requested workflow: $($Tasks -join ', ')" + + } + finally + { + Pop-Location -StackName BeforeBuild + } +} + +Begin +{ + # Bootstrapping the environment before using Invoke-Build as task runner + + if ($MyInvocation.ScriptName -notLike '*Invoke-Build.ps1') + { + Write-Host -foregroundColor Green "[pre-build] Starting Build Init" + Push-Location $PSScriptRoot -StackName BuildModule + } + + if ($RequiredModulesDirectory -in @('CurrentUser', 'AllUsers')) + { + # Installing modules instead of saving them + Write-Host -foregroundColor Green "[pre-build] Required Modules will be installed for $RequiredModulesDirectory, not saved." + # Tell Resolve-Dependency to use provided scope as the -PSDependTarget if not overridden in Build.psd1 + $PSDependTarget = $RequiredModulesDirectory + } + else + { + if (-Not (Split-Path -IsAbsolute -Path $OutputDirectory)) + { + $OutputDirectory = Join-Path -Path $PSScriptRoot -ChildPath $OutputDirectory + } + + # Resolving the absolute path to save the required modules to + if (-Not (Split-Path -IsAbsolute -Path $RequiredModulesDirectory)) + { + $RequiredModulesDirectory = Join-Path -Path $PSScriptRoot -ChildPath $RequiredModulesDirectory + } + + # Create the output/modules folder if not exists, or resolve the Absolute path otherwise + if (Resolve-Path $RequiredModulesDirectory -ErrorAction SilentlyContinue) + { + Write-Debug "[pre-build] Required Modules path already exist at $RequiredModulesDirectory" + $RequiredModulesPath = Convert-Path $RequiredModulesDirectory + } + else + { + Write-Host -foregroundColor Green "[pre-build] Creating required modules directory $RequiredModulesDirectory." + $RequiredModulesPath = (New-Item -ItemType Directory -Force -Path $RequiredModulesDirectory).FullName + } + + # Prepending $RequiredModulesPath folder to PSModulePath to resolve from this folder FIRST + if ($RequiredModulesDirectory -notIn @('CurrentUser', 'AllUsers') -and + (($Env:PSModulePath -split [io.path]::PathSeparator) -notContains $RequiredModulesDirectory)) + { + Write-Host -foregroundColor Green "[pre-build] Prepending '$RequiredModulesDirectory' folder to PSModulePath" + $Env:PSModulePath = $RequiredModulesDirectory + [io.path]::PathSeparator + $Env:PSModulePath + } + + # Checking if the user should -ResolveDependency + if ((!(Get-Module -ListAvailable powershell-yaml) -or !(Get-Module -ListAvailable InvokeBuild) -or !(Get-Module -ListAvailable PSDepend)) -and !$ResolveDependency) + { + if ($AutoRestore -or !$PSBoundParameters.ContainsKey('Tasks') -or $Tasks -contains 'build') + { + Write-Host -ForegroundColor Yellow "[pre-build] Dependency missing, running './build.ps1 -ResolveDependency -Tasks noop' for you `r`n" + $ResolveDependency = $true + } + else + { + Write-Warning "Some required Modules are missing, make sure you first run with the '-ResolveDependency' parameter." + Write-Warning "Running 'build.ps1 -ResolveDependency -Tasks noop' will pull required modules without running the build task." + } + } + + if ($BuiltModuleSubdirectory) + { + if (-Not (Split-Path -IsAbsolute $BuiltModuleSubdirectory)) + { + $BuildModuleOutput = Join-Path $OutputDirectory $BuiltModuleSubdirectory + } + else + { + $BuildModuleOutput = $BuiltModuleSubdirectory + } + } + else + { + $BuildModuleOutput = $OutputDirectory + } + + # Prepending $BuildModuleOutput folder to PSModulePath to resolve built module from this folder + if (($Env:PSModulePath -split [io.path]::PathSeparator) -notContains $BuildModuleOutput) + { + Write-Host -foregroundColor Green "[pre-build] Prepending '$BuildModuleOutput' folder to PSModulePath" + $Env:PSModulePath = $BuildModuleOutput + [io.path]::PathSeparator + $Env:PSModulePath + } + + # Tell Resolve-Dependency to use $RequiredModulesPath as -PSDependTarget if not overridden in Build.psd1 + $PSDependTarget = $RequiredModulesPath + } + + if ($ResolveDependency) + { + Write-Host -Object "[pre-build] Resolving dependencies." -foregroundColor Green + $ResolveDependencyParams = @{ } + + # If BuildConfig is a Yaml file, bootstrap powershell-yaml via ResolveDependency + if ($BuildConfig -match '\.[yaml|yml]$') + { + $ResolveDependencyParams.add('WithYaml', $true) + } + + $ResolveDependencyAvailableParams = (Get-Command -Name '.\Resolve-Dependency.ps1').parameters.keys + foreach ($CmdParameter in $ResolveDependencyAvailableParams) + { + + # The parameter has been explicitly used for calling the .build.ps1 + if ($MyInvocation.BoundParameters.ContainsKey($CmdParameter)) + { + $ParamValue = $MyInvocation.BoundParameters.ContainsKey($CmdParameter) + Write-Debug " adding $CmdParameter :: $ParamValue [from user-provided parameters to Build.ps1]" + $ResolveDependencyParams.Add($CmdParameter, $ParamValue) + } + # Use defaults parameter value from Build.ps1, if any + else + { + if ($ParamValue = Get-Variable -Name $CmdParameter -ValueOnly -ErrorAction Ignore) + { + Write-Debug " adding $CmdParameter :: $ParamValue [from default Build.ps1 variable]" + $ResolveDependencyParams.add($CmdParameter, $ParamValue) + } + } + } + + Write-Host -foregroundColor Green "[pre-build] Starting bootstrap process." + .\Resolve-Dependency.ps1 @ResolveDependencyParams + } + + if ($MyInvocation.ScriptName -notLike '*Invoke-Build.ps1') + { + Write-Verbose "Bootstrap completed. Handing back to InvokeBuild." + if ($PSBoundParameters.ContainsKey('ResolveDependency')) + { + Write-Verbose "Dependency already resolved. Removing task" + $null = $PSBoundParameters.Remove('ResolveDependency') + } + Write-Host -foregroundColor Green "[build] Starting build with InvokeBuild." + Invoke-Build @PSBoundParameters -Task $Tasks -File $MyInvocation.MyCommand.Path + Pop-Location -StackName BuildModule + return + } +} diff --git a/build.yaml b/build.yaml new file mode 100644 index 00000000..1c486101 --- /dev/null +++ b/build.yaml @@ -0,0 +1,88 @@ +--- +#################################################### +# ModuleBuilder Configuration # +#################################################### +CopyDirectories: + - en-US + - DSCResources + - Modules +Encoding: UTF8 +VersionedOutputDirectory: true + +#################################################### +# Pipeline Configuration # +#################################################### +BuildWorkflow: + '.': + - build + - test + + build: + - Clean + - Build_Module_ModuleBuilder + - Build_NestedModules_ModuleBuilder + - Create_changelog_release_output + + pack: + - build + - package_module_nupkg + + hqrmtest: + - DscResource_Tests_Stop_On_Fail + + test: + - Pester_Tests_Stop_On_Fail + - Pester_if_Code_Coverage_Under_Threshold + + publish: + - Publish_release_to_GitHub + - publish_module_to_gallery + + +#################################################### +# PESTER Configuration # +#################################################### + +Pester: + OutputFormat: NUnitXML + ExcludeFromCodeCoverage: + Script: + - tests/Unit + - tests/Integration + ExcludeTag: + Tag: + CodeCoverageThreshold: 70 + +DscTest: + OutputFormat: NUnitXML + ExcludeTag: + - 'Common Tests - New Error-Level Script Analyzer Rules' + ExcludeSourceFile: + - output + +Resolve-Dependency: + Gallery: 'PSGallery' + AllowPrerelease: false + Verbose: false + +ModuleBuildTasks: + Sampler: + - '*.build.Sampler.ib.tasks' + +TaskHeader: | + param($Path) + "" + "=" * 79 + Write-Build Cyan "`t`t`t$($Task.Name.replace("_"," ").ToUpper())" + Write-Build DarkGray "$(Get-BuildSynopsis $Task)" + "-" * 79 + Write-Build DarkGray " $Path" + Write-Build DarkGray " $($Task.InvocationInfo.ScriptName):$($Task.InvocationInfo.ScriptLineNumber)" + "" + +GitHubConfig: + GitHubFilesToAdd: + - 'CHANGELOG.md' + GitHubConfigUserName: dscbot + GitHubConfigUserEmail: dsccommunity@outlook.com + UpdateChangelogOnPrerelease: false diff --git a/source/Build.psd1 b/source/Build.psd1 new file mode 100644 index 00000000..3009ed89 --- /dev/null +++ b/source/Build.psd1 @@ -0,0 +1,5 @@ +@{ + Path = 'ComputerManagementDsc.psd1' +} +# Waiting for ModuleBuilder to do away with this file +# when all parameters are provided to the function diff --git a/source/ComputerManagementDsc.psd1 b/source/ComputerManagementDsc.psd1 new file mode 100644 index 00000000..5f88f3d0 --- /dev/null +++ b/source/ComputerManagementDsc.psd1 @@ -0,0 +1,79 @@ +@{ + # Version number of this module. + moduleVersion = '0.0.1' + + # ID used to uniquely identify this module + GUID = 'B5004952-489E-43EA-999C-F16A25355B89' + + # Author of this module + Author = 'DSC Community' + + # Company or vendor of this module + CompanyName = 'DSC Community' + + # Copyright statement for this module + Copyright = 'Copyright the DSC Community contributors. All rights reserved.' + + # Description of the functionality provided by this module + Description = 'DSC resources for configuration of a Windows computer. These DSC resources allow you to perform computer management tasks, such as renaming the computer, joining a domain and scheduling tasks as well as configuring items such as virtual memory, event logs, time zones and power settings.' + + # Minimum version of the Windows PowerShell engine required by this module + PowerShellVersion = '4.0' + + # Minimum version of the common language runtime (CLR) required by this module + CLRVersion = '4.0' + + # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. + FunctionsToExport = @() + + # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. + CmdletsToExport = @() + + # Variables to export from this module + VariablesToExport = @() + + # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. + AliasesToExport = @() + + # DSC resources to export from this module + DscResourcesToExport = @( + 'Computer' + 'OfflineDomainJoin' + 'PendingReboot' + 'PowerPlan' + 'PowerShellExecutionPolicy' + 'RemoteDesktopAdmin' + 'ScheduledTask' + 'SmbServerConfiguration' + 'SmbShare' + 'SystemLocale' + 'TimeZone' + 'VirtualMemory' + 'WindowsEventLog' + 'WindowsCapability' + ) + + # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. + PrivateData = @{ + + PSData = @{ + # Set to a prerelease string value if the release should be a prerelease. + Prerelease = '' + + # Tags applied to this module. These help with module discovery in online galleries. + Tags = @('DesiredStateConfiguration', 'DSC', 'DSCResource') + + # A URL to the license for this module. + LicenseUri = 'https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE' + + # A URL to the main website for this project. + ProjectUri = 'https://github.com/dsccommunity/ComputerManagementDsc' + + # A URL to an icon representing this module. + IconUri = 'https://dsccommunity.org/images/DSC_Logo_300p.png' + + # ReleaseNotes of this module + ReleaseNotes = '' + } # End of PSData hashtable + } # End of PrivateData hashtable +} diff --git a/DSCResources/MSFT_Computer/MSFT_Computer.psm1 b/source/DSCResources/DSC_Computer/DSC_Computer.psm1 similarity index 96% rename from DSCResources/MSFT_Computer/MSFT_Computer.psm1 rename to source/DSCResources/DSC_Computer/DSC_Computer.psm1 index 19b973af..9664928f 100644 --- a/DSCResources/MSFT_Computer/MSFT_Computer.psm1 +++ b/source/DSCResources/DSC_Computer/DSC_Computer.psm1 @@ -11,7 +11,7 @@ Import-Module -Name (Join-Path -Path $modulePath ` -ChildPath 'ComputerManagementDsc.Common.psm1')) # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_Computer' +$script:localizedData = Get-LocalizedData -ResourceName 'DSC_Computer' $FailToRenameAfterJoinDomainErrorId = 'FailToRenameAfterJoinDomain,Microsoft.PowerShell.Commands.AddComputerCommand' @@ -52,7 +52,7 @@ function Get-TargetResource ( [Parameter(Mandatory = $true)] [ValidateLength(1, 15)] - [ValidateScript( {$_ -inotmatch '[\/\\:*?"<>|]' })] + [ValidateScript( { $_ -inotmatch '[\/\\:*?"<>|]' })] [System.String] $Name, @@ -88,7 +88,7 @@ function Get-TargetResource Write-Verbose -Message ($script:localizedData.GettingComputerStateMessage -f $Name) $convertToCimCredential = New-CimInstance ` - -ClassName MSFT_Credential ` + -ClassName DSC_Credential ` -Property @{ Username = [System.String] $Credential.UserName Password = [System.String] $null @@ -97,7 +97,7 @@ function Get-TargetResource -ClientOnly $convertToCimUnjoinCredential = New-CimInstance ` - -ClassName MSFT_Credential ` + -ClassName DSC_Credential ` -Property @{ Username = [System.String] $UnjoinCredential.UserName Password = [System.String] $null @@ -156,7 +156,7 @@ function Set-TargetResource ( [Parameter(Mandatory = $true)] [ValidateLength(1, 15)] - [ValidateScript( {$_ -inotmatch '[\/\\:*?"<>|]' })] + [ValidateScript( { $_ -inotmatch '[\/\\:*?"<>|]' })] [System.String] $Name, @@ -221,7 +221,7 @@ function Set-TargetResource $addComputerParameters = @{ DomainName = $DomainName Credential = $Credential - Force = $true + Force = $true } $rename = $false if ($Name -ne $env:COMPUTERNAME) @@ -275,7 +275,7 @@ function Set-TargetResource if ($rename) { - Write-Verbose -Message ($script:localizedData.RenamedComputerAndJoinedDomainMessage -f $Name,$DomainName) + Write-Verbose -Message ($script:localizedData.RenamedComputerAndJoinedDomainMessage -f $Name, $DomainName) } else { @@ -304,7 +304,7 @@ function Set-TargetResource -WorkgroupName $WorkGroupName ` -Force - Write-Verbose -Message ($script:localizedData.RenamedComputerAndJoinedWorkgroupMessage -f $Name,$WorkGroupName) + Write-Verbose -Message ($script:localizedData.RenamedComputerAndJoinedWorkgroupMessage -f $Name, $WorkGroupName) } else { @@ -368,7 +368,7 @@ function Set-TargetResource -WorkgroupName $WorkGroupName ` -NewName $Name - Write-Verbose -Message ($script:localizedData.RenamedComputerAndJoinedWorkgroupMessage -f $Name,$WorkGroupName) + Write-Verbose -Message ($script:localizedData.RenamedComputerAndJoinedWorkgroupMessage -f $Name, $WorkGroupName) } else { @@ -429,7 +429,7 @@ function Test-TargetResource ( [Parameter(Mandatory = $true)] [ValidateLength(1, 15)] - [ValidateScript( {$_ -inotmatch '[\/\\:*?"<>|]' })] + [ValidateScript( { $_ -inotmatch '[\/\\:*?"<>|]' })] [System.String] $Name, @@ -641,7 +641,7 @@ function Get-LogonServer [OutputType([System.String])] param () - $logonserver = $env:LOGONSERVER -replace "\\","" + $logonserver = $env:LOGONSERVER -replace "\\", "" return $logonserver } diff --git a/DSCResources/MSFT_Computer/MSFT_Computer.schema.mof b/source/DSCResources/DSC_Computer/DSC_Computer.schema.mof similarity index 96% rename from DSCResources/MSFT_Computer/MSFT_Computer.schema.mof rename to source/DSCResources/DSC_Computer/DSC_Computer.schema.mof index bcf895ac..96eae764 100644 --- a/DSCResources/MSFT_Computer/MSFT_Computer.schema.mof +++ b/source/DSCResources/DSC_Computer/DSC_Computer.schema.mof @@ -1,5 +1,5 @@ [ClassVersion("1.0.1.0"), FriendlyName("Computer")] -class MSFT_Computer : OMI_BaseResource +class DSC_Computer : OMI_BaseResource { [Key, Description("The desired computer name.")] String Name; [Write, Description("The name of the domain to join.")] String DomainName; diff --git a/DSCResources/MSFT_Computer/README.md b/source/DSCResources/DSC_Computer/README.md similarity index 100% rename from DSCResources/MSFT_Computer/README.md rename to source/DSCResources/DSC_Computer/README.md diff --git a/DSCResources/MSFT_Computer/en-US/MSFT_Computer.strings.psd1 b/source/DSCResources/DSC_Computer/en-US/DSC_Computer.strings.psd1 similarity index 100% rename from DSCResources/MSFT_Computer/en-US/MSFT_Computer.strings.psd1 rename to source/DSCResources/DSC_Computer/en-US/DSC_Computer.strings.psd1 diff --git a/DSCResources/MSFT_OfflineDomainJoin/MSFT_OfflineDomainJoin.psm1 b/source/DSCResources/DSC_OfflineDomainJoin/DSC_OfflineDomainJoin.psm1 similarity index 98% rename from DSCResources/MSFT_OfflineDomainJoin/MSFT_OfflineDomainJoin.psm1 rename to source/DSCResources/DSC_OfflineDomainJoin/DSC_OfflineDomainJoin.psm1 index 70579054..4000af22 100644 --- a/DSCResources/MSFT_OfflineDomainJoin/MSFT_OfflineDomainJoin.psm1 +++ b/source/DSCResources/DSC_OfflineDomainJoin/DSC_OfflineDomainJoin.psm1 @@ -11,7 +11,7 @@ Import-Module -Name (Join-Path -Path $modulePath ` -ChildPath 'ComputerManagementDsc.Common.psm1')) # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_OfflineDomainJoin' +$script:localizedData = Get-LocalizedData -ResourceName 'DSC_OfflineDomainJoin' <# .SYNOPSIS diff --git a/DSCResources/MSFT_OfflineDomainJoin/MSFT_OfflineDomainJoin.schema.mof b/source/DSCResources/DSC_OfflineDomainJoin/DSC_OfflineDomainJoin.schema.mof similarity index 87% rename from DSCResources/MSFT_OfflineDomainJoin/MSFT_OfflineDomainJoin.schema.mof rename to source/DSCResources/DSC_OfflineDomainJoin/DSC_OfflineDomainJoin.schema.mof index 4301693c..787469c6 100644 --- a/DSCResources/MSFT_OfflineDomainJoin/MSFT_OfflineDomainJoin.schema.mof +++ b/source/DSCResources/DSC_OfflineDomainJoin/DSC_OfflineDomainJoin.schema.mof @@ -1,5 +1,5 @@ [ClassVersion("1.0.0.0"), FriendlyName("OfflineDomainJoin")] -class MSFT_OfflineDomainJoin : OMI_BaseResource +class DSC_OfflineDomainJoin : OMI_BaseResource { [Key, Description("Specifies the resource is a single instance, the value must be 'Yes'."), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance; [Required, Description("The full path to the Offline Domain Join Request file to use.")] String RequestFile; diff --git a/DSCResources/MSFT_OfflineDomainJoin/README.md b/source/DSCResources/DSC_OfflineDomainJoin/README.md similarity index 100% rename from DSCResources/MSFT_OfflineDomainJoin/README.md rename to source/DSCResources/DSC_OfflineDomainJoin/README.md diff --git a/DSCResources/MSFT_OfflineDomainJoin/en-US/MSFT_OfflineDomainJoin.strings.psd1 b/source/DSCResources/DSC_OfflineDomainJoin/en-US/DSC_OfflineDomainJoin.strings.psd1 similarity index 100% rename from DSCResources/MSFT_OfflineDomainJoin/en-US/MSFT_OfflineDomainJoin.strings.psd1 rename to source/DSCResources/DSC_OfflineDomainJoin/en-US/DSC_OfflineDomainJoin.strings.psd1 diff --git a/DSCResources/MSFT_PendingReboot/MSFT_PendingReboot.psm1 b/source/DSCResources/DSC_PendingReboot/DSC_PendingReboot.psm1 similarity index 98% rename from DSCResources/MSFT_PendingReboot/MSFT_PendingReboot.psm1 rename to source/DSCResources/DSC_PendingReboot/DSC_PendingReboot.psm1 index 77582d3e..8436157b 100644 --- a/DSCResources/MSFT_PendingReboot/MSFT_PendingReboot.psm1 +++ b/source/DSCResources/DSC_PendingReboot/DSC_PendingReboot.psm1 @@ -9,7 +9,7 @@ Import-Module -Name (Join-Path -Path $modulePath ` -ChildPath 'ComputerManagementDsc.Common.psm1')) # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_PendingReboot' +$script:localizedData = Get-LocalizedData -ResourceName 'DSC_PendingReboot' <# This data file contains a list of reboot triggers that will be checked @@ -17,7 +17,7 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_PendingReboot' data file so that it can also be used in testing. #> $script:localizedResourceData = Get-LocalizedData ` - -ResourceName 'MSFT_PendingReboot' ` + -ResourceName 'DSC_PendingReboot' ` -Postfix 'data' $script:rebootTriggers = $script:localizedResourceData.RebootTriggers <# diff --git a/DSCResources/MSFT_PendingReboot/MSFT_PendingReboot.schema.mof b/source/DSCResources/DSC_PendingReboot/DSC_PendingReboot.schema.mof similarity index 97% rename from DSCResources/MSFT_PendingReboot/MSFT_PendingReboot.schema.mof rename to source/DSCResources/DSC_PendingReboot/DSC_PendingReboot.schema.mof index db815172..f11e51f9 100644 --- a/DSCResources/MSFT_PendingReboot/MSFT_PendingReboot.schema.mof +++ b/source/DSCResources/DSC_PendingReboot/DSC_PendingReboot.schema.mof @@ -1,5 +1,5 @@ [ClassVersion("1.0.0.0"), FriendlyName("PendingReboot")] -class MSFT_PendingReboot : OMI_BaseResource +class DSC_PendingReboot : OMI_BaseResource { [Key, Description("Specifies the name of this pending reboot check.")] String Name; [Write, Description("Specifies whether to skip reboots triggered by the Component-Based Servicing component.")] Boolean SkipComponentBasedServicing; diff --git a/DSCResources/MSFT_PendingReboot/README.md b/source/DSCResources/DSC_PendingReboot/README.md similarity index 100% rename from DSCResources/MSFT_PendingReboot/README.md rename to source/DSCResources/DSC_PendingReboot/README.md diff --git a/DSCResources/MSFT_PendingReboot/en-US/MSFT_PendingReboot.data.psd1 b/source/DSCResources/DSC_PendingReboot/en-US/DSC_PendingReboot.data.psd1 similarity index 100% rename from DSCResources/MSFT_PendingReboot/en-US/MSFT_PendingReboot.data.psd1 rename to source/DSCResources/DSC_PendingReboot/en-US/DSC_PendingReboot.data.psd1 diff --git a/DSCResources/MSFT_PendingReboot/en-US/MSFT_PendingReboot.strings.psd1 b/source/DSCResources/DSC_PendingReboot/en-US/DSC_PendingReboot.strings.psd1 similarity index 100% rename from DSCResources/MSFT_PendingReboot/en-US/MSFT_PendingReboot.strings.psd1 rename to source/DSCResources/DSC_PendingReboot/en-US/DSC_PendingReboot.strings.psd1 diff --git a/DSCResources/MSFT_PowerPlan/MSFT_PowerPlan.psm1 b/source/DSCResources/DSC_PowerPlan/DSC_PowerPlan.psm1 similarity index 98% rename from DSCResources/MSFT_PowerPlan/MSFT_PowerPlan.psm1 rename to source/DSCResources/DSC_PowerPlan/DSC_PowerPlan.psm1 index 580e7941..f6cc17f8 100644 --- a/DSCResources/MSFT_PowerPlan/MSFT_PowerPlan.psm1 +++ b/source/DSCResources/DSC_PowerPlan/DSC_PowerPlan.psm1 @@ -6,7 +6,7 @@ Import-Module -Name (Join-Path -Path $modulePath ` -ChildPath 'ComputerManagementDsc.Common.psm1')) # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_PowerPlan' +$script:localizedData = Get-LocalizedData -ResourceName 'DSC_PowerPlan' <# .SYNOPSIS diff --git a/DSCResources/MSFT_PowerPlan/MSFT_PowerPlan.schema.mof b/source/DSCResources/DSC_PowerPlan/DSC_PowerPlan.schema.mof similarity index 90% rename from DSCResources/MSFT_PowerPlan/MSFT_PowerPlan.schema.mof rename to source/DSCResources/DSC_PowerPlan/DSC_PowerPlan.schema.mof index 41820d6f..f8f0a62b 100644 --- a/DSCResources/MSFT_PowerPlan/MSFT_PowerPlan.schema.mof +++ b/source/DSCResources/DSC_PowerPlan/DSC_PowerPlan.schema.mof @@ -1,5 +1,5 @@ [ClassVersion("1.0.0.0"), FriendlyName("PowerPlan")] -class MSFT_PowerPlan : OMI_BaseResource +class DSC_PowerPlan : OMI_BaseResource { [Key, Description("Specifies the resource is a single instance, the value must be 'Yes'."), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance; [Required, Description("The name or GUID of the power plan to activate.")] String Name; diff --git a/DSCResources/MSFT_PowerPlan/README.md b/source/DSCResources/DSC_PowerPlan/README.md similarity index 100% rename from DSCResources/MSFT_PowerPlan/README.md rename to source/DSCResources/DSC_PowerPlan/README.md diff --git a/DSCResources/MSFT_PowerPlan/en-US/MSFT_PowerPlan.schema.mfl b/source/DSCResources/DSC_PowerPlan/en-US/DSC_PowerPlan.schema.mfl similarity index 89% rename from DSCResources/MSFT_PowerPlan/en-US/MSFT_PowerPlan.schema.mfl rename to source/DSCResources/DSC_PowerPlan/en-US/DSC_PowerPlan.schema.mfl index 3b208b85..6cd3ff22 100644 --- a/DSCResources/MSFT_PowerPlan/en-US/MSFT_PowerPlan.schema.mfl +++ b/source/DSCResources/DSC_PowerPlan/en-US/DSC_PowerPlan.schema.mfl @@ -1,5 +1,5 @@ [Description("This resource is used to activate a power plan.") : Amended,AMENDMENT, LOCALE("MS_409")] -class MSFT_PowerPlan : OMI_BaseResource +class DSC_PowerPlan : OMI_BaseResource { [Key, Description("Specifies the resource is a single instance, the value must be 'Yes'.") : Amended] String IsSingleInstance; [Description("The name or GUID of the power plan to activate.") : Amended] String Name; diff --git a/DSCResources/MSFT_PowerPlan/en-US/MSFT_PowerPlan.strings.psd1 b/source/DSCResources/DSC_PowerPlan/en-US/DSC_PowerPlan.strings.psd1 similarity index 100% rename from DSCResources/MSFT_PowerPlan/en-US/MSFT_PowerPlan.strings.psd1 rename to source/DSCResources/DSC_PowerPlan/en-US/DSC_PowerPlan.strings.psd1 diff --git a/DSCResources/MSFT_PowerShellExecutionPolicy/MSFT_PowerShellExecutionPolicy.psm1 b/source/DSCResources/DSC_PowerShellExecutionPolicy/DSC_PowerShellExecutionPolicy.psm1 similarity index 97% rename from DSCResources/MSFT_PowerShellExecutionPolicy/MSFT_PowerShellExecutionPolicy.psm1 rename to source/DSCResources/DSC_PowerShellExecutionPolicy/DSC_PowerShellExecutionPolicy.psm1 index 3dd45a19..1bbb6a8b 100644 --- a/DSCResources/MSFT_PowerShellExecutionPolicy/MSFT_PowerShellExecutionPolicy.psm1 +++ b/source/DSCResources/DSC_PowerShellExecutionPolicy/DSC_PowerShellExecutionPolicy.psm1 @@ -6,7 +6,7 @@ Import-Module -Name (Join-Path -Path $modulePath ` -ChildPath 'ComputerManagementDsc.Common.psm1')) # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_PowershellExecutionPolicy' +$script:localizedData = Get-LocalizedData -ResourceName 'DSC_PowershellExecutionPolicy' <# .SYNOPSIS diff --git a/DSCResources/MSFT_PowerShellExecutionPolicy/MSFT_PowerShellExecutionPolicy.schema.mof b/source/DSCResources/DSC_PowerShellExecutionPolicy/DSC_PowerShellExecutionPolicy.schema.mof similarity index 91% rename from DSCResources/MSFT_PowerShellExecutionPolicy/MSFT_PowerShellExecutionPolicy.schema.mof rename to source/DSCResources/DSC_PowerShellExecutionPolicy/DSC_PowerShellExecutionPolicy.schema.mof index 4c6c6d28..f0a9cef6 100644 --- a/DSCResources/MSFT_PowerShellExecutionPolicy/MSFT_PowerShellExecutionPolicy.schema.mof +++ b/source/DSCResources/DSC_PowerShellExecutionPolicy/DSC_PowerShellExecutionPolicy.schema.mof @@ -1,5 +1,5 @@ [ClassVersion("1.0.0.0"), FriendlyName("PowerShellExecutionPolicy")] -class MSFT_PowerShellExecutionPolicy : OMI_BaseResource +class DSC_PowerShellExecutionPolicy : OMI_BaseResource { [Key, Description("Defines the scope for the preference of the Windows PowerShell execution policy."), ValueMap{"CurrentUser","LocalMachine","MachinePolicy","Process","UserPolicy"},Values{"CurrentUser","LocalMachine","MachinePolicy","Process","UserPolicy"}] String ExecutionPolicyScope; [Required, Description("Changes the preference for the Windows PowerShell execution policy."), ValueMap{"Bypass","Restricted","AllSigned","RemoteSigned","Unrestricted"}, Values{"Bypass","Restricted","AllSigned","RemoteSigned","Unrestricted"}] String ExecutionPolicy; diff --git a/DSCResources/MSFT_PowerShellExecutionPolicy/README.md b/source/DSCResources/DSC_PowerShellExecutionPolicy/README.md similarity index 100% rename from DSCResources/MSFT_PowerShellExecutionPolicy/README.md rename to source/DSCResources/DSC_PowerShellExecutionPolicy/README.md diff --git a/DSCResources/MSFT_PowerShellExecutionPolicy/en-US/MSFT_PowerShellExecutionPolicy.strings.psd1 b/source/DSCResources/DSC_PowerShellExecutionPolicy/en-US/DSC_PowerShellExecutionPolicy.strings.psd1 similarity index 100% rename from DSCResources/MSFT_PowerShellExecutionPolicy/en-US/MSFT_PowerShellExecutionPolicy.strings.psd1 rename to source/DSCResources/DSC_PowerShellExecutionPolicy/en-US/DSC_PowerShellExecutionPolicy.strings.psd1 diff --git a/DSCResources/MSFT_RemoteDesktopAdmin/MSFT_RemoteDesktopAdmin.psm1 b/source/DSCResources/DSC_RemoteDesktopAdmin/DSC_RemoteDesktopAdmin.psm1 similarity index 98% rename from DSCResources/MSFT_RemoteDesktopAdmin/MSFT_RemoteDesktopAdmin.psm1 rename to source/DSCResources/DSC_RemoteDesktopAdmin/DSC_RemoteDesktopAdmin.psm1 index 68214c58..078d6a27 100644 --- a/DSCResources/MSFT_RemoteDesktopAdmin/MSFT_RemoteDesktopAdmin.psm1 +++ b/source/DSCResources/DSC_RemoteDesktopAdmin/DSC_RemoteDesktopAdmin.psm1 @@ -6,7 +6,7 @@ Import-Module -Name (Join-Path -Path $modulePath ` -ChildPath 'ComputerManagementDsc.Common.psm1')) # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_RemoteDesktopAdmin' +$script:localizedData = Get-LocalizedData -ResourceName 'DSC_RemoteDesktopAdmin' $script:tSRegistryKey = 'HKLM:\System\CurrentControlSet\Control\Terminal Server' $script:winStationsRegistryKey = 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' diff --git a/DSCResources/MSFT_RemoteDesktopAdmin/MSFT_RemoteDesktopAdmin.schema.mof b/source/DSCResources/DSC_RemoteDesktopAdmin/DSC_RemoteDesktopAdmin.schema.mof similarity index 93% rename from DSCResources/MSFT_RemoteDesktopAdmin/MSFT_RemoteDesktopAdmin.schema.mof rename to source/DSCResources/DSC_RemoteDesktopAdmin/DSC_RemoteDesktopAdmin.schema.mof index d79c8eb1..6b2bac1e 100644 --- a/DSCResources/MSFT_RemoteDesktopAdmin/MSFT_RemoteDesktopAdmin.schema.mof +++ b/source/DSCResources/DSC_RemoteDesktopAdmin/DSC_RemoteDesktopAdmin.schema.mof @@ -1,6 +1,6 @@ [ClassVersion("1.0.0.0"), FriendlyName("RemoteDesktopAdmin")] -class MSFT_RemoteDesktopAdmin : OMI_BaseResource +class DSC_RemoteDesktopAdmin : OMI_BaseResource { [Key, Description("Specifies the resource is a single instance, the value must be 'Yes'"), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance; [Write, Description("Determines whether or not the computer should accept remote desktop connections. Present sets the value to Enabled and Absent sets the value to Disabled."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; diff --git a/DSCResources/MSFT_RemoteDesktopAdmin/README.md b/source/DSCResources/DSC_RemoteDesktopAdmin/README.md similarity index 100% rename from DSCResources/MSFT_RemoteDesktopAdmin/README.md rename to source/DSCResources/DSC_RemoteDesktopAdmin/README.md diff --git a/DSCResources/MSFT_RemoteDesktopAdmin/en-US/MSFT_RemoteDesktopAdmin.strings.psd1 b/source/DSCResources/DSC_RemoteDesktopAdmin/en-US/DSC_RemoteDesktopAdmin.strings.psd1 similarity index 100% rename from DSCResources/MSFT_RemoteDesktopAdmin/en-US/MSFT_RemoteDesktopAdmin.strings.psd1 rename to source/DSCResources/DSC_RemoteDesktopAdmin/en-US/DSC_RemoteDesktopAdmin.strings.psd1 diff --git a/DSCResources/MSFT_ScheduledTask/MSFT_ScheduledTask.psm1 b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 similarity index 99% rename from DSCResources/MSFT_ScheduledTask/MSFT_ScheduledTask.psm1 rename to source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 index a618dadc..60969b6b 100644 --- a/DSCResources/MSFT_ScheduledTask/MSFT_ScheduledTask.psm1 +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1 @@ -22,7 +22,7 @@ Import-Module -Name (Join-Path -Path $modulePath ` -ChildPath 'ComputerManagementDsc.Common.psm1')) # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_ScheduledTask' +$script:localizedData = Get-LocalizedData -ResourceName 'DSC_ScheduledTask' <# .SYNOPSIS @@ -1456,7 +1456,7 @@ function Test-TargetResource <# All forms of whitespace is automatically trimmed from the description when it is set, so we must not compare it here. See issue #258: - https://github.com/PowerShell/ComputerManagementDsc/issues/258 + https://github.com/dsccommunity/ComputerManagementDsc/issues/258 #> $PSBoundParameters['Description'] = $PSBoundParameters.Description.Trim() } diff --git a/DSCResources/MSFT_ScheduledTask/MSFT_ScheduledTask.schema.mof b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.schema.mof similarity index 99% rename from DSCResources/MSFT_ScheduledTask/MSFT_ScheduledTask.schema.mof rename to source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.schema.mof index 1ae7465f..6583b6b9 100644 --- a/DSCResources/MSFT_ScheduledTask/MSFT_ScheduledTask.schema.mof +++ b/source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.schema.mof @@ -1,5 +1,5 @@ [ClassVersion("1.0.0.0"), FriendlyName("ScheduledTask")] -class MSFT_ScheduledTask : OMI_BaseResource +class DSC_ScheduledTask : OMI_BaseResource { [Key, Description("The name of the task.")] string TaskName; [Write, Description("The path to the task - defaults to the root directory.")] string TaskPath; diff --git a/DSCResources/MSFT_ScheduledTask/README.md b/source/DSCResources/DSC_ScheduledTask/README.md similarity index 100% rename from DSCResources/MSFT_ScheduledTask/README.md rename to source/DSCResources/DSC_ScheduledTask/README.md diff --git a/DSCResources/MSFT_ScheduledTask/en-US/MSFT_ScheduledTask.strings.psd1 b/source/DSCResources/DSC_ScheduledTask/en-US/DSC_ScheduledTask.strings.psd1 similarity index 100% rename from DSCResources/MSFT_ScheduledTask/en-US/MSFT_ScheduledTask.strings.psd1 rename to source/DSCResources/DSC_ScheduledTask/en-US/DSC_ScheduledTask.strings.psd1 diff --git a/DSCResources/MSFT_SmbServerConfiguration/MSFT_SmbServerConfiguration.data.psd1 b/source/DSCResources/DSC_SmbServerConfiguration/DSC_SmbServerConfiguration.data.psd1 similarity index 100% rename from DSCResources/MSFT_SmbServerConfiguration/MSFT_SmbServerConfiguration.data.psd1 rename to source/DSCResources/DSC_SmbServerConfiguration/DSC_SmbServerConfiguration.data.psd1 diff --git a/DSCResources/MSFT_SmbServerConfiguration/MSFT_SmbServerConfiguration.psm1 b/source/DSCResources/DSC_SmbServerConfiguration/DSC_SmbServerConfiguration.psm1 similarity index 99% rename from DSCResources/MSFT_SmbServerConfiguration/MSFT_SmbServerConfiguration.psm1 rename to source/DSCResources/DSC_SmbServerConfiguration/DSC_SmbServerConfiguration.psm1 index baf64b12..824e8a85 100644 --- a/DSCResources/MSFT_SmbServerConfiguration/MSFT_SmbServerConfiguration.psm1 +++ b/source/DSCResources/DSC_SmbServerConfiguration/DSC_SmbServerConfiguration.psm1 @@ -11,11 +11,11 @@ Import-Module -Name (Join-Path -Path $modulePath ` -ChildPath 'ComputerManagementDsc.Common.psm1')) # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SmbServerConfiguration' +$script:localizedData = Get-LocalizedData -ResourceName 'DSC_SmbServerConfiguration' $resourceData = Import-LocalizedData ` -BaseDirectory $PSScriptRoot ` - -FileName 'MSFT_SmbServerConfiguration.data.psd1' + -FileName 'DSC_SmbServerConfiguration.data.psd1' $script:smbServerSettings = $resourceData.smbServerSettings diff --git a/DSCResources/MSFT_SmbServerConfiguration/MSFT_SmbServerConfiguration.schema.mof b/source/DSCResources/DSC_SmbServerConfiguration/DSC_SmbServerConfiguration.schema.mof similarity index 98% rename from DSCResources/MSFT_SmbServerConfiguration/MSFT_SmbServerConfiguration.schema.mof rename to source/DSCResources/DSC_SmbServerConfiguration/DSC_SmbServerConfiguration.schema.mof index 53e90b51..4c434584 100644 --- a/DSCResources/MSFT_SmbServerConfiguration/MSFT_SmbServerConfiguration.schema.mof +++ b/source/DSCResources/DSC_SmbServerConfiguration/DSC_SmbServerConfiguration.schema.mof @@ -1,6 +1,6 @@ [ClassVersion("1.0.0.0"), FriendlyName("SmbServerConfiguration")] -class MSFT_SmbServerConfiguration : OMI_BaseResource +class DSC_SmbServerConfiguration : OMI_BaseResource { [Key, Description("Specifies the resource is a single instance, the value must be 'Yes'"), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance; [Write, Description("Specifies the announce comment string.")] String AnnounceComment; diff --git a/DSCResources/MSFT_SmbServerConfiguration/README.md b/source/DSCResources/DSC_SmbServerConfiguration/README.md similarity index 100% rename from DSCResources/MSFT_SmbServerConfiguration/README.md rename to source/DSCResources/DSC_SmbServerConfiguration/README.md diff --git a/DSCResources/MSFT_SmbServerConfiguration/en-US/MSFT_SmbServerConfiguration.schema.mfl b/source/DSCResources/DSC_SmbServerConfiguration/en-US/DSC_SmbServerConfiguration.schema.mfl similarity index 98% rename from DSCResources/MSFT_SmbServerConfiguration/en-US/MSFT_SmbServerConfiguration.schema.mfl rename to source/DSCResources/DSC_SmbServerConfiguration/en-US/DSC_SmbServerConfiguration.schema.mfl index 053144f9..6b862f43 100644 --- a/DSCResources/MSFT_SmbServerConfiguration/en-US/MSFT_SmbServerConfiguration.schema.mfl +++ b/source/DSCResources/DSC_SmbServerConfiguration/en-US/DSC_SmbServerConfiguration.schema.mfl @@ -1,5 +1,5 @@ [Write, Description("This resource is used to configure SMB Server.")] -class MSFT_SmbServerConfiguration : OMI_BaseResource +class DSC_SmbServerConfiguration : OMI_BaseResource { [Key, Description("Specifies the resource is a single instance, the value must be 'Yes'"), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance; [Write, Description("Specifies the announce comment string.")] String AnnounceComment; diff --git a/DSCResources/MSFT_SmbServerConfiguration/en-US/MSFT_SmbServerConfiguration.strings.psd1 b/source/DSCResources/DSC_SmbServerConfiguration/en-US/DSC_SmbServerConfiguration.strings.psd1 similarity index 100% rename from DSCResources/MSFT_SmbServerConfiguration/en-US/MSFT_SmbServerConfiguration.strings.psd1 rename to source/DSCResources/DSC_SmbServerConfiguration/en-US/DSC_SmbServerConfiguration.strings.psd1 diff --git a/DSCResources/MSFT_SmbShare/MSFT_SmbShare.psm1 b/source/DSCResources/DSC_SmbShare/DSC_SmbShare.psm1 similarity index 99% rename from DSCResources/MSFT_SmbShare/MSFT_SmbShare.psm1 rename to source/DSCResources/DSC_SmbShare/DSC_SmbShare.psm1 index 3a12940c..53ac25a2 100644 --- a/DSCResources/MSFT_SmbShare/MSFT_SmbShare.psm1 +++ b/source/DSCResources/DSC_SmbShare/DSC_SmbShare.psm1 @@ -11,7 +11,7 @@ Import-Module -Name (Join-Path -Path $modulePath ` -ChildPath 'ComputerManagementDsc.Common.psm1')) # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SmbShare' +$script:localizedData = Get-LocalizedData -ResourceName 'DSC_SmbShare' <# .SYNOPSIS diff --git a/DSCResources/MSFT_SmbShare/MSFT_SmbShare.schema.mof b/source/DSCResources/DSC_SmbShare/DSC_SmbShare.schema.mof similarity index 98% rename from DSCResources/MSFT_SmbShare/MSFT_SmbShare.schema.mof rename to source/DSCResources/DSC_SmbShare/DSC_SmbShare.schema.mof index a1b01e36..2c00fff8 100644 --- a/DSCResources/MSFT_SmbShare/MSFT_SmbShare.schema.mof +++ b/source/DSCResources/DSC_SmbShare/DSC_SmbShare.schema.mof @@ -1,6 +1,6 @@ [ClassVersion("1.0.0.0"), FriendlyName("SmbShare")] -class MSFT_SmbShare : OMI_BaseResource +class DSC_SmbShare : OMI_BaseResource { [Key, Description("Specifies the name of the SMB share.")] String Name; [Required, Description("Specifies the path of the SMB share.")] String Path; diff --git a/DSCResources/MSFT_SmbShare/README.md b/source/DSCResources/DSC_SmbShare/README.md similarity index 100% rename from DSCResources/MSFT_SmbShare/README.md rename to source/DSCResources/DSC_SmbShare/README.md diff --git a/DSCResources/MSFT_SmbShare/en-US/MSFT_SmbShare.schema.mfl b/source/DSCResources/DSC_SmbShare/en-US/DSC_SmbShare.schema.mfl similarity index 98% rename from DSCResources/MSFT_SmbShare/en-US/MSFT_SmbShare.schema.mfl rename to source/DSCResources/DSC_SmbShare/en-US/DSC_SmbShare.schema.mfl index 9d2fd5ec..299a9d30 100644 --- a/DSCResources/MSFT_SmbShare/en-US/MSFT_SmbShare.schema.mfl +++ b/source/DSCResources/DSC_SmbShare/en-US/DSC_SmbShare.schema.mfl @@ -1,5 +1,5 @@ [Description("This resource is used to configure SMB shares.") : Amended,AMENDMENT, LOCALE("MS_409")] -class MSFT_SmbShare : OMI_BaseResource +class DSC_SmbShare : OMI_BaseResource { [Key, Description("Specifies the name of the SMB share.") : Amended] String Name; [Description("Specifies the path of the SMB share.") : Amended] String Path; diff --git a/DSCResources/MSFT_SmbShare/en-US/MSFT_SmbShare.strings.psd1 b/source/DSCResources/DSC_SmbShare/en-US/DSC_SmbShare.strings.psd1 similarity index 100% rename from DSCResources/MSFT_SmbShare/en-US/MSFT_SmbShare.strings.psd1 rename to source/DSCResources/DSC_SmbShare/en-US/DSC_SmbShare.strings.psd1 diff --git a/DSCResources/MSFT_SystemLocale/MSFT_SystemLocale.psm1 b/source/DSCResources/DSC_SystemLocale/DSC_SystemLocale.psm1 similarity index 98% rename from DSCResources/MSFT_SystemLocale/MSFT_SystemLocale.psm1 rename to source/DSCResources/DSC_SystemLocale/DSC_SystemLocale.psm1 index 572fc0f6..4c5a3890 100644 --- a/DSCResources/MSFT_SystemLocale/MSFT_SystemLocale.psm1 +++ b/source/DSCResources/DSC_SystemLocale/DSC_SystemLocale.psm1 @@ -11,7 +11,7 @@ Import-Module -Name (Join-Path -Path $modulePath ` -ChildPath 'ComputerManagementDsc.Common.psm1')) # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SystemLocale' +$script:localizedData = Get-LocalizedData -ResourceName 'DSC_SystemLocale' <# .SYNOPSIS diff --git a/DSCResources/MSFT_SystemLocale/MSFT_SystemLocale.schema.mof b/source/DSCResources/DSC_SystemLocale/DSC_SystemLocale.schema.mof similarity index 87% rename from DSCResources/MSFT_SystemLocale/MSFT_SystemLocale.schema.mof rename to source/DSCResources/DSC_SystemLocale/DSC_SystemLocale.schema.mof index 1272747a..caaf3eec 100644 --- a/DSCResources/MSFT_SystemLocale/MSFT_SystemLocale.schema.mof +++ b/source/DSCResources/DSC_SystemLocale/DSC_SystemLocale.schema.mof @@ -1,5 +1,5 @@ [ClassVersion("1.0.0.0"), FriendlyName("SystemLocale")] -class MSFT_SystemLocale : OMI_BaseResource +class DSC_SystemLocale : OMI_BaseResource { [Key, Description("Specifies the resource is a single instance, the value must be 'Yes'"), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance; [Required, Description("Specifies the System Locale.")] String SystemLocale; diff --git a/DSCResources/MSFT_SystemLocale/README.md b/source/DSCResources/DSC_SystemLocale/README.md similarity index 100% rename from DSCResources/MSFT_SystemLocale/README.md rename to source/DSCResources/DSC_SystemLocale/README.md diff --git a/DSCResources/MSFT_SystemLocale/en-US/MSFT_SystemLocale.strings.psd1 b/source/DSCResources/DSC_SystemLocale/en-US/DSC_SystemLocale.strings.psd1 similarity index 100% rename from DSCResources/MSFT_SystemLocale/en-US/MSFT_SystemLocale.strings.psd1 rename to source/DSCResources/DSC_SystemLocale/en-US/DSC_SystemLocale.strings.psd1 diff --git a/DSCResources/MSFT_TimeZone/MSFT_TimeZone.psm1 b/source/DSCResources/DSC_TimeZone/DSC_TimeZone.psm1 similarity index 97% rename from DSCResources/MSFT_TimeZone/MSFT_TimeZone.psm1 rename to source/DSCResources/DSC_TimeZone/DSC_TimeZone.psm1 index 2b77af99..b0ee6a90 100644 --- a/DSCResources/MSFT_TimeZone/MSFT_TimeZone.psm1 +++ b/source/DSCResources/DSC_TimeZone/DSC_TimeZone.psm1 @@ -6,7 +6,7 @@ Import-Module -Name (Join-Path -Path $modulePath ` -ChildPath 'ComputerManagementDsc.Common.psm1')) # Import Localization Strings. -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_TimeZone' +$script:localizedData = Get-LocalizedData -ResourceName 'DSC_TimeZone' <# .SYNOPSIS diff --git a/DSCResources/MSFT_TimeZone/MSFT_TimeZone.schema.mof b/source/DSCResources/DSC_TimeZone/DSC_TimeZone.schema.mof similarity index 87% rename from DSCResources/MSFT_TimeZone/MSFT_TimeZone.schema.mof rename to source/DSCResources/DSC_TimeZone/DSC_TimeZone.schema.mof index 98d971f0..e272ca82 100644 --- a/DSCResources/MSFT_TimeZone/MSFT_TimeZone.schema.mof +++ b/source/DSCResources/DSC_TimeZone/DSC_TimeZone.schema.mof @@ -1,5 +1,5 @@ [ClassVersion("1.0.0.0"), FriendlyName("TimeZone")] -class MSFT_TimeZone : OMI_BaseResource +class DSC_TimeZone : OMI_BaseResource { [Key, Description("Specifies the resource is a single instance, the value must be 'Yes'."), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance; [Required, Description("Specifies the TimeZone.")] String TimeZone; diff --git a/DSCResources/MSFT_TimeZone/README.md b/source/DSCResources/DSC_TimeZone/README.md similarity index 100% rename from DSCResources/MSFT_TimeZone/README.md rename to source/DSCResources/DSC_TimeZone/README.md diff --git a/DSCResources/MSFT_TimeZone/en-US/MSFT_TimeZone.strings.psd1 b/source/DSCResources/DSC_TimeZone/en-US/DSC_TimeZone.strings.psd1 similarity index 100% rename from DSCResources/MSFT_TimeZone/en-US/MSFT_TimeZone.strings.psd1 rename to source/DSCResources/DSC_TimeZone/en-US/DSC_TimeZone.strings.psd1 diff --git a/DSCResources/MSFT_VirtualMemory/MSFT_VirtualMemory.psm1 b/source/DSCResources/DSC_VirtualMemory/DSC_VirtualMemory.psm1 similarity index 99% rename from DSCResources/MSFT_VirtualMemory/MSFT_VirtualMemory.psm1 rename to source/DSCResources/DSC_VirtualMemory/DSC_VirtualMemory.psm1 index f678f36a..721852e3 100644 --- a/DSCResources/MSFT_VirtualMemory/MSFT_VirtualMemory.psm1 +++ b/source/DSCResources/DSC_VirtualMemory/DSC_VirtualMemory.psm1 @@ -9,7 +9,7 @@ Import-Module -Name (Join-Path -Path $modulePath ` -ChildPath 'ComputerManagementDsc.Common.psm1')) # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_VirtualMemory' +$script:localizedData = Get-LocalizedData -ResourceName 'DSC_VirtualMemory' <# .SYNOPSIS diff --git a/DSCResources/MSFT_VirtualMemory/MSFT_VirtualMemory.schema.mof b/source/DSCResources/DSC_VirtualMemory/DSC_VirtualMemory.schema.mof similarity index 94% rename from DSCResources/MSFT_VirtualMemory/MSFT_VirtualMemory.schema.mof rename to source/DSCResources/DSC_VirtualMemory/DSC_VirtualMemory.schema.mof index 9dc46109..11c4182f 100644 --- a/DSCResources/MSFT_VirtualMemory/MSFT_VirtualMemory.schema.mof +++ b/source/DSCResources/DSC_VirtualMemory/DSC_VirtualMemory.schema.mof @@ -1,6 +1,6 @@ [ClassVersion("1.0.0.0"), FriendlyName("VirtualMemory")] -class MSFT_VirtualMemory : OMI_BaseResource +class DSC_VirtualMemory : OMI_BaseResource { [Key, Description("The drive letter for which paging settings should be set. Can be letter only, letter and colon or letter with colon and trailing slash.")] String Drive; [Key, Description("The type of the paging setting to use. If set to AutoManagePagingFile, the drive letter will be ignored. If set to SystemManagedSize, the values for InitialSize and MaximumSize will be ignored"), ValueMap{"AutoManagePagingFile","CustomSize","SystemManagedSize","NoPagingFile"}, Values{"AutoManagePagingFile","CustomSize","SystemManagedSize","NoPagingFile"}] String Type; diff --git a/DSCResources/MSFT_VirtualMemory/README.md b/source/DSCResources/DSC_VirtualMemory/README.md similarity index 100% rename from DSCResources/MSFT_VirtualMemory/README.md rename to source/DSCResources/DSC_VirtualMemory/README.md diff --git a/DSCResources/MSFT_VirtualMemory/en-US/MSFT_VirtualMemory.strings.psd1 b/source/DSCResources/DSC_VirtualMemory/en-US/DSC_VirtualMemory.strings.psd1 similarity index 100% rename from DSCResources/MSFT_VirtualMemory/en-US/MSFT_VirtualMemory.strings.psd1 rename to source/DSCResources/DSC_VirtualMemory/en-US/DSC_VirtualMemory.strings.psd1 diff --git a/DSCResources/MSFT_WindowsCapability/MSFT_WindowsCapability.psm1 b/source/DSCResources/DSC_WindowsCapability/DSC_WindowsCapability.psm1 similarity index 60% rename from DSCResources/MSFT_WindowsCapability/MSFT_WindowsCapability.psm1 rename to source/DSCResources/DSC_WindowsCapability/DSC_WindowsCapability.psm1 index 0819b5bd..92ae611f 100644 --- a/DSCResources/MSFT_WindowsCapability/MSFT_WindowsCapability.psm1 +++ b/source/DSCResources/DSC_WindowsCapability/DSC_WindowsCapability.psm1 @@ -6,17 +6,14 @@ Import-Module -Name (Join-Path -Path $modulePath ` -ChildPath 'ComputerManagementDsc.Common.psm1')) # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_WindowsCapability' +$script:localizedData = Get-LocalizedData -ResourceName 'DSC_WindowsCapability' <# .SYNOPSIS Gets the current state of the Windows Capability. .PARAMETER Name - Specifies the given name of a Windows Capability. - - .PARAMETER Name - Specifies the given name of a Windows Capability. + Specifies the name of the Windows Capability. #> function Get-TargetResource { @@ -26,18 +23,23 @@ function Get-TargetResource ( [Parameter(Mandatory = $true)] [System.String] - $Name, - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present' + $Name ) Write-Verbose -Message ($script:localizedData.GetTargetResourceStartMessage -f $Name) - $windowsCapability = Get-WindowsCapability -Online @PSBoundParameters + if ([System.String]::IsNullOrEmpty($windowsCapability.Name)) + { + New-InvalidArgumentException ` + -Message ($script:localizedData.CapabilityNameNotFound -f $Name) ` + -ArgumentName 'Name' + } + else + { + Write-Verbose -Message ($script:localizedData.CapabilityNameFound -f $Name) + } + if ($windowsCapability.State -eq 'Installed') { $Ensure = 'Present' @@ -48,11 +50,10 @@ function Get-TargetResource } $returnValue = @{ - Name = $Name - LogLevel = $windowsCapability.LogLevel - State = $windowsCapability.State - Ensure = $Ensure - IsSingleInstance = 'Yes' + Name = $Name + LogLevel = $windowsCapability.LogLevel + LogPath = $windowsCapability.LogPath + Ensure = $Ensure } Write-Verbose -Message ($script:localizedData.GetTargetResourceEndMessage -f $Name) @@ -64,18 +65,21 @@ function Get-TargetResource Sets if the the current state of the Windows Capability is in the desired state. .PARAMETER Name - Specifies the given name of a Windows Capability. + Specifies the name of the Windows Capability. .PARAMETER Ensure - Specifies whether the Windows Capability should be installed or uninstalled. + Specifies whether the Windows Capability should be installed + or uninstalled. .PARAMETER LogLevel - Specifies the given LogLevel of a Windows Capability. - Default LogLevel is: 'WarningsInfo' + Specifies the given Log Level of a Windows Capability. This is a write + only parameter that is used when updating the status of a Windows + Capability. If not specified, the default is 'WarningsInfo'. .PARAMETER LogPath - Specifies the full path and file name to log to. - If not set, the default is %WINDIR%\Logs\Dism\dism.log + Specifies the full path and file name to log to. This is a write + only parameter that is used when updating the status of a Windows + Capability. If not specified, the default is '%WINDIR%\Logs\Dism\dism.log'. #> function Set-TargetResource { @@ -103,22 +107,13 @@ function Set-TargetResource Write-Verbose -Message ($script:localizedData.SetTargetResourceStartMessage -f $Name) $null = $PSBoundParameters.Remove('Ensure') - $windowsCapability = Get-WindowsCapability -Online @PSBoundParameters - - if ($windowsCapability.State -eq 'Installed') - { - $ensureResult = 'Present' - } - else - { - $ensureResult = 'Absent' - } + $currentState = Get-TargetResource -Name $Name switch ($Ensure) { 'Present' { - if ($Ensure -ne $ensureResult) + if ($Ensure -ne $currentState.Ensure) { Write-Verbose -Message ($script:localizedData.SetTargetAddMessage -f $Name) $null = Add-WindowsCapability -Online @PSBoundParameters @@ -127,7 +122,7 @@ function Set-TargetResource 'Absent' { - if ($Ensure -ne $ensureResult) + if ($Ensure -ne $currentState.Ensure) { Write-Verbose -Message ($script:localizedData.SetTargetRemoveMessage -f $Name) $null = Remove-WindowsCapability -Online @PSBoundParameters @@ -141,18 +136,29 @@ function Set-TargetResource Tests if the the current state of the Windows Capability is in the desired state. .PARAMETER Name - Specifies the given name of a Windows Capability. + Specifies the name of the Windows Capability. .PARAMETER Ensure - Specifies whether the Windows Capability should be installed or uninstalled. + Specifies whether the Windows Capability should be installed + or uninstalled. .PARAMETER LogLevel - Specifies the given LogLevel of a Windows Capability. - Default LogLevel is: 'WarningsInfo' + Specifies the given Log Level of a Windows Capability. This is a write + only parameter that is used when updating the status of a Windows + Capability. If not specified, the default is 'WarningsInfo'. .PARAMETER LogPath - Specifies the full path and file name to log to. - If not set, the default is %WINDIR%\Logs\Dism\dism.log + Specifies the full path and file name to log to. This is a write + only parameter that is used when updating the status of a Windows + Capability. If not specified, the default is '%WINDIR%\Logs\Dism\dism.log'. + + .NOTES + Get-WindowsCapability will return the LogLevel and LogPath + properties, but these values don't reflect the values set + when calling Add-WindowsCapability or Remove-WindowsCapability. + + Therefore, these values can not be used to determine if the + resource is in state. #> function Test-TargetResource { @@ -167,7 +173,7 @@ function Test-TargetResource [Parameter()] [ValidateSet('Present', 'Absent')] [System.String] - $Ensure, + $Ensure = 'Present', [Parameter()] [ValidateSet('Errors', 'Warnings', 'WarningsInfo')] @@ -179,53 +185,23 @@ function Test-TargetResource $LogPath ) - Write-Verbose -Message ($script:localizedData.TestTargetResourceStartMessage -f $Name) - - $desiredState = $true - - $windowsCapability = Get-WindowsCapability -Online @PSBoundParameters - - if ($null -eq $windowsCapability.Name) - { - New-InvalidArgumentException -Message ($script:localizedData.CapabilityNameNotFound -f $Name) - } - else - { - Write-Verbose -Message ($script:localizedData.CapabilityNameFound -f $Name) - } - - if ($LogPath) - { - if (-not (Test-Path $LogPath)) - { - New-InvalidArgumentException -Message ($script:localizedData.LogPathFailedMessage -f $LogPath) - } - else - { - Write-Verbose -Message ($script:localizedData.LogPathFoundMessage -f $LogPath) - } - } + $inDesiredState = $true - if ($windowsCapability.State -eq 'Installed') - { - $ensureResult = 'Present' - } - else - { - $ensureResult = 'Absent' - } + Write-Verbose -Message ($script:localizedData.TestTargetResourceStartMessage -f $Name) + $currentState = Get-TargetResource -Name $Name - if ($PSBoundParameters.ContainsKey('Ensure') -and $Ensure -ne $ensureResult) + if ($Ensure -ne $currentState.Ensure) { Write-Verbose -Message ($script:localizedData.SetResourceIsNotInDesiredState -f $Name) - $desiredState = $false + $inDesiredState = $false } else { Write-Verbose -Message ($script:localizedData.SetResourceIsInDesiredState -f $Name) - $desiredState = $true + $inDesiredState = $true } - return $desiredState + + return $inDesiredState } Export-ModuleMember -Function *-TargetResource diff --git a/source/DSCResources/DSC_WindowsCapability/DSC_WindowsCapability.schema.mof b/source/DSCResources/DSC_WindowsCapability/DSC_WindowsCapability.schema.mof new file mode 100644 index 00000000..339247a5 --- /dev/null +++ b/source/DSCResources/DSC_WindowsCapability/DSC_WindowsCapability.schema.mof @@ -0,0 +1,9 @@ + +[ClassVersion("1.0.0.1"), FriendlyName("WindowsCapability")] +class DSC_WindowsCapability : OMI_BaseResource +{ + [Key, Description("Specifies the name of the Windows Capability.")] String Name; + [Write, Description("Specifies whether the Windows Capability should be installed or uninstalled. To install the Windows Capability, set this property to Present. To uninstall the Windows Capability, set the property to Absent."), ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure; + [Write, Description("Specifies the given Log Level of a Windows Capability. This is a write only parameter that is used when updating the status of a Windows Capability. If not specified, the default is 'WarningsInfo'."), ValueMap{"Errors", "Warnings", "WarningsInfo"}, Values{"Errors", "Warnings", "WarningsInfo"}] String LogLevel; + [Write, Description("Specifies the full path and file name to log to. This is a write only parameter that is used when updating the status of a Windows Capability. If not specified, the default is '%WINDIR%\\Logs\\Dism\\dism.log'.")] String LogPath; +}; diff --git a/source/DSCResources/DSC_WindowsCapability/README.md b/source/DSCResources/DSC_WindowsCapability/README.md new file mode 100644 index 00000000..5be0f6d5 --- /dev/null +++ b/source/DSCResources/DSC_WindowsCapability/README.md @@ -0,0 +1,10 @@ +# Description + +This resource enables installation or removal of a Windows Capability. + +The LogLevel and LogPath parameters can be passed to the resource but +are not used to determine if the resource is in the desired state. + +This is because the LogLevel and LogPath properties returned by +`Get-WindowsCapability` do not reflect the values that may have been +set with `Add-WindowsCapability` or `Remove-WindowsCapability`. diff --git a/DSCResources/MSFT_WindowsCapability/en-US/MSFT_WindowsCapability.strings.psd1 b/source/DSCResources/DSC_WindowsCapability/en-US/DSC_WindowsCapability.strings.psd1 similarity index 89% rename from DSCResources/MSFT_WindowsCapability/en-US/MSFT_WindowsCapability.strings.psd1 rename to source/DSCResources/DSC_WindowsCapability/en-US/DSC_WindowsCapability.strings.psd1 index 185fb528..55dc8056 100644 --- a/DSCResources/MSFT_WindowsCapability/en-US/MSFT_WindowsCapability.strings.psd1 +++ b/source/DSCResources/DSC_WindowsCapability/en-US/DSC_WindowsCapability.strings.psd1 @@ -8,8 +8,6 @@ ConvertFrom-StringData -StringData @' SetTargetRemoveMessage = Executing Remove functionality on Windows Capability '{0}'. SetTargetAddMessage = Executing Add functionality on Windows Capability '{0}'. TestTargetResourceStartMessage = Begin executing Test functionality on Windows Capability '{0}'. - LogPathFailedMessage = LogPath '{0}' not found. - LogPathFoundMessage = LogPath '{0}' found. CapabilityNameFound = Specified Windows Capability '{0}' found. CapabilityNameNotFound = Specified Windows Capability '{0}' not found. '@ diff --git a/DSCResources/MSFT_WindowsEventLog/MSFT_WindowsEventLog.psm1 b/source/DSCResources/DSC_WindowsEventLog/DSC_WindowsEventLog.psm1 similarity index 99% rename from DSCResources/MSFT_WindowsEventLog/MSFT_WindowsEventLog.psm1 rename to source/DSCResources/DSC_WindowsEventLog/DSC_WindowsEventLog.psm1 index b3a2516f..e5281517 100644 --- a/DSCResources/MSFT_WindowsEventLog/MSFT_WindowsEventLog.psm1 +++ b/source/DSCResources/DSC_WindowsEventLog/DSC_WindowsEventLog.psm1 @@ -6,7 +6,7 @@ Import-Module -Name (Join-Path -Path $modulePath ` -ChildPath 'ComputerManagementDsc.Common.psm1')) # Import Localization Strings -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_WindowsEventLog' +$script:localizedData = Get-LocalizedData -ResourceName 'DSC_WindowsEventLog' <# .SYNOPSIS diff --git a/DSCResources/MSFT_WindowsEventLog/MSFT_WindowsEventLog.schema.mof b/source/DSCResources/DSC_WindowsEventLog/DSC_WindowsEventLog.schema.mof similarity index 95% rename from DSCResources/MSFT_WindowsEventLog/MSFT_WindowsEventLog.schema.mof rename to source/DSCResources/DSC_WindowsEventLog/DSC_WindowsEventLog.schema.mof index 60cfc45d..379bfd77 100644 --- a/DSCResources/MSFT_WindowsEventLog/MSFT_WindowsEventLog.schema.mof +++ b/source/DSCResources/DSC_WindowsEventLog/DSC_WindowsEventLog.schema.mof @@ -1,6 +1,6 @@ [ClassVersion("1.0.0.1"), FriendlyName("WindowsEventLog")] -class MSFT_WindowsEventLog : OMI_BaseResource +class DSC_WindowsEventLog : OMI_BaseResource { [Key, Description("Specifies the given name of a Windows Event Log")] String LogName; [Write, Description("Specifies the given state of a Windows Event Log")] Boolean IsEnabled; diff --git a/DSCResources/MSFT_WindowsEventLog/README.md b/source/DSCResources/DSC_WindowsEventLog/README.md similarity index 100% rename from DSCResources/MSFT_WindowsEventLog/README.md rename to source/DSCResources/DSC_WindowsEventLog/README.md diff --git a/DSCResources/MSFT_WindowsEventLog/en-US/MSFT_WindowsEventLog.strings.psd1 b/source/DSCResources/DSC_WindowsEventLog/en-US/DSC_WindowsEventLog.strings.psd1 similarity index 100% rename from DSCResources/MSFT_WindowsEventLog/en-US/MSFT_WindowsEventLog.strings.psd1 rename to source/DSCResources/DSC_WindowsEventLog/en-US/DSC_WindowsEventLog.strings.psd1 diff --git a/Examples/Resources/Computer/1-Computer_RenameComputerAndSetWorkgroup_Config.ps1 b/source/Examples/Resources/Computer/1-Computer_RenameComputerAndSetWorkgroup_Config.ps1 similarity index 73% rename from Examples/Resources/Computer/1-Computer_RenameComputerAndSetWorkgroup_Config.ps1 rename to source/Examples/Resources/Computer/1-Computer_RenameComputerAndSetWorkgroup_Config.ps1 index b551ac12..9a1d0581 100644 --- a/Examples/Resources/Computer/1-Computer_RenameComputerAndSetWorkgroup_Config.ps1 +++ b/source/Examples/Resources/Computer/1-Computer_RenameComputerAndSetWorkgroup_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 594bfeff-8e83-4cc4-8141-f3b39795c85b -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/Computer/2-Computer_JoinDomain_Config.ps1 b/source/Examples/Resources/Computer/2-Computer_JoinDomain_Config.ps1 similarity index 78% rename from Examples/Resources/Computer/2-Computer_JoinDomain_Config.ps1 rename to source/Examples/Resources/Computer/2-Computer_JoinDomain_Config.ps1 index 57aafc02..748bd4c9 100644 --- a/Examples/Resources/Computer/2-Computer_JoinDomain_Config.ps1 +++ b/source/Examples/Resources/Computer/2-Computer_JoinDomain_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID a8b9b735-a13d-4901-8edd-a2eb3a589183 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/Computer/3-Computer_RenameComputerInDomain_Config.ps1 b/source/Examples/Resources/Computer/3-Computer_RenameComputerInDomain_Config.ps1 similarity index 78% rename from Examples/Resources/Computer/3-Computer_RenameComputerInDomain_Config.ps1 rename to source/Examples/Resources/Computer/3-Computer_RenameComputerInDomain_Config.ps1 index c26ea420..9f2bdb22 100644 --- a/Examples/Resources/Computer/3-Computer_RenameComputerInDomain_Config.ps1 +++ b/source/Examples/Resources/Computer/3-Computer_RenameComputerInDomain_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 7e77ef8f-69ac-4e86-8a95-e38d3350118f -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/Computer/4-Computer_RenameComputerInWorkgroup_Config.ps1 b/source/Examples/Resources/Computer/4-Computer_RenameComputerInWorkgroup_Config.ps1 similarity index 70% rename from Examples/Resources/Computer/4-Computer_RenameComputerInWorkgroup_Config.ps1 rename to source/Examples/Resources/Computer/4-Computer_RenameComputerInWorkgroup_Config.ps1 index 6d99e6bc..73519a98 100644 --- a/Examples/Resources/Computer/4-Computer_RenameComputerInWorkgroup_Config.ps1 +++ b/source/Examples/Resources/Computer/4-Computer_RenameComputerInWorkgroup_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 7a5bc1c3-5229-48ec-9145-816d02e4544d -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/Computer/5-Computer_UnjoinDomainAndJoinWorkgroup_Config.ps1 b/source/Examples/Resources/Computer/5-Computer_UnjoinDomainAndJoinWorkgroup_Config.ps1 similarity index 78% rename from Examples/Resources/Computer/5-Computer_UnjoinDomainAndJoinWorkgroup_Config.ps1 rename to source/Examples/Resources/Computer/5-Computer_UnjoinDomainAndJoinWorkgroup_Config.ps1 index 2d880fbc..b9c09ec7 100644 --- a/Examples/Resources/Computer/5-Computer_UnjoinDomainAndJoinWorkgroup_Config.ps1 +++ b/source/Examples/Resources/Computer/5-Computer_UnjoinDomainAndJoinWorkgroup_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 9625caff-9065-4d04-9585-934998d81591 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/Computer/6-Computer_SetComputerDescriptionInWorkgroup_Config.ps1 b/source/Examples/Resources/Computer/6-Computer_SetComputerDescriptionInWorkgroup_Config.ps1 similarity index 71% rename from Examples/Resources/Computer/6-Computer_SetComputerDescriptionInWorkgroup_Config.ps1 rename to source/Examples/Resources/Computer/6-Computer_SetComputerDescriptionInWorkgroup_Config.ps1 index 6a9c8d6d..96e733b4 100644 --- a/Examples/Resources/Computer/6-Computer_SetComputerDescriptionInWorkgroup_Config.ps1 +++ b/source/Examples/Resources/Computer/6-Computer_SetComputerDescriptionInWorkgroup_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 315d9349-c340-4c6d-970e-8e5d2bb5b12b -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/Computer/7-Computer_JoinDomainSpecifyingDC_Config.ps1 b/source/Examples/Resources/Computer/7-Computer_JoinDomainSpecifyingDC_Config.ps1 similarity index 79% rename from Examples/Resources/Computer/7-Computer_JoinDomainSpecifyingDC_Config.ps1 rename to source/Examples/Resources/Computer/7-Computer_JoinDomainSpecifyingDC_Config.ps1 index 0ef74f61..35165de1 100644 --- a/Examples/Resources/Computer/7-Computer_JoinDomainSpecifyingDC_Config.ps1 +++ b/source/Examples/Resources/Computer/7-Computer_JoinDomainSpecifyingDC_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 5964d0b3-be15-455e-8233-4f655150de79 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/OfflineDomainJoin/1-OfflineDomainJoin_JoinDomainUsingODJBlob_Config.ps1 b/source/Examples/Resources/OfflineDomainJoin/1-OfflineDomainJoin_JoinDomainUsingODJBlob_Config.ps1 similarity index 72% rename from Examples/Resources/OfflineDomainJoin/1-OfflineDomainJoin_JoinDomainUsingODJBlob_Config.ps1 rename to source/Examples/Resources/OfflineDomainJoin/1-OfflineDomainJoin_JoinDomainUsingODJBlob_Config.ps1 index cd7e208b..b53fd49b 100644 --- a/Examples/Resources/OfflineDomainJoin/1-OfflineDomainJoin_JoinDomainUsingODJBlob_Config.ps1 +++ b/source/Examples/Resources/OfflineDomainJoin/1-OfflineDomainJoin_JoinDomainUsingODJBlob_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID fc143221-396c-4407-9aa8-c5878326e4ff -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/PendingReboot/1-PendingReboot_RebootAfterDomainJoin_Config.ps1 b/source/Examples/Resources/PendingReboot/1-PendingReboot_RebootAfterDomainJoin_Config.ps1 similarity index 80% rename from Examples/Resources/PendingReboot/1-PendingReboot_RebootAfterDomainJoin_Config.ps1 rename to source/Examples/Resources/PendingReboot/1-PendingReboot_RebootAfterDomainJoin_Config.ps1 index 3232643b..e90d670b 100644 --- a/Examples/Resources/PendingReboot/1-PendingReboot_RebootAfterDomainJoin_Config.ps1 +++ b/source/Examples/Resources/PendingReboot/1-PendingReboot_RebootAfterDomainJoin_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID ca17d716-4ded-4822-8f02-6363e9fa2c71 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/PendingReboot/2-PendingReboot_ConfigMgrReboot_Config.ps1 b/source/Examples/Resources/PendingReboot/2-PendingReboot_ConfigMgrReboot_Config.ps1 similarity index 81% rename from Examples/Resources/PendingReboot/2-PendingReboot_ConfigMgrReboot_Config.ps1 rename to source/Examples/Resources/PendingReboot/2-PendingReboot_ConfigMgrReboot_Config.ps1 index 111acb61..126590a5 100644 --- a/Examples/Resources/PendingReboot/2-PendingReboot_ConfigMgrReboot_Config.ps1 +++ b/source/Examples/Resources/PendingReboot/2-PendingReboot_ConfigMgrReboot_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 0d920405-2238-4ab5-871a-995e9baa0e28 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/PowerPlan/1-PowerPlan_SetPowerPlan_Config.ps1 b/source/Examples/Resources/PowerPlan/1-PowerPlan_SetPowerPlan_Config.ps1 similarity index 62% rename from Examples/Resources/PowerPlan/1-PowerPlan_SetPowerPlan_Config.ps1 rename to source/Examples/Resources/PowerPlan/1-PowerPlan_SetPowerPlan_Config.ps1 index 9142e10f..61318277 100644 --- a/Examples/Resources/PowerPlan/1-PowerPlan_SetPowerPlan_Config.ps1 +++ b/source/Examples/Resources/PowerPlan/1-PowerPlan_SetPowerPlan_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 547354f3-f5d1-4c76-8988-72887938e852 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS @@ -29,8 +29,8 @@ Configuration PowerPlan_SetPowerPlan_Config { PowerPlan SetPlanHighPerformance { - IsSingleInstance = 'Yes' - Name = 'High performance' + IsSingleInstance = 'Yes' + Name = 'High performance' } } } diff --git a/Examples/Resources/PowerShellExecutionPolicy/1-PowerShellExecutionPolicy_SetPolicy_Config.ps1 b/source/Examples/Resources/PowerShellExecutionPolicy/1-PowerShellExecutionPolicy_SetPolicy_Config.ps1 similarity index 75% rename from Examples/Resources/PowerShellExecutionPolicy/1-PowerShellExecutionPolicy_SetPolicy_Config.ps1 rename to source/Examples/Resources/PowerShellExecutionPolicy/1-PowerShellExecutionPolicy_SetPolicy_Config.ps1 index 316f5253..f0c5388d 100644 --- a/Examples/Resources/PowerShellExecutionPolicy/1-PowerShellExecutionPolicy_SetPolicy_Config.ps1 +++ b/source/Examples/Resources/PowerShellExecutionPolicy/1-PowerShellExecutionPolicy_SetPolicy_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID d878a4e7-da0b-4099-b8e3-3442717b4c97 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/PowerShellExecutionPolicy/2-PowerShellExecutionPolicy_SetPolicyForMultipleScopes_Config.ps1 b/source/Examples/Resources/PowerShellExecutionPolicy/2-PowerShellExecutionPolicy_SetPolicyForMultipleScopes_Config.ps1 similarity index 80% rename from Examples/Resources/PowerShellExecutionPolicy/2-PowerShellExecutionPolicy_SetPolicyForMultipleScopes_Config.ps1 rename to source/Examples/Resources/PowerShellExecutionPolicy/2-PowerShellExecutionPolicy_SetPolicyForMultipleScopes_Config.ps1 index c9f0bc58..779d2818 100644 --- a/Examples/Resources/PowerShellExecutionPolicy/2-PowerShellExecutionPolicy_SetPolicyForMultipleScopes_Config.ps1 +++ b/source/Examples/Resources/PowerShellExecutionPolicy/2-PowerShellExecutionPolicy_SetPolicyForMultipleScopes_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 6900f247-5477-4821-9718-480f485db688 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/RemoteDesktopAdmin/1-RemoteDesktopAdmin_SetSecureRemoteDesktopAdmin_Config.ps1 b/source/Examples/Resources/RemoteDesktopAdmin/1-RemoteDesktopAdmin_SetSecureRemoteDesktopAdmin_Config.ps1 similarity index 75% rename from Examples/Resources/RemoteDesktopAdmin/1-RemoteDesktopAdmin_SetSecureRemoteDesktopAdmin_Config.ps1 rename to source/Examples/Resources/RemoteDesktopAdmin/1-RemoteDesktopAdmin_SetSecureRemoteDesktopAdmin_Config.ps1 index 6831d2d2..c9e8c4aa 100644 --- a/Examples/Resources/RemoteDesktopAdmin/1-RemoteDesktopAdmin_SetSecureRemoteDesktopAdmin_Config.ps1 +++ b/source/Examples/Resources/RemoteDesktopAdmin/1-RemoteDesktopAdmin_SetSecureRemoteDesktopAdmin_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID f177571b-c54b-46f2-9d55-903b794ecccd -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/ScheduledTask/1-ScheduledTask_CreateScheduledTaskOnce_Config.ps1 b/source/Examples/Resources/ScheduledTask/1-ScheduledTask_CreateScheduledTaskOnce_Config.ps1 similarity index 85% rename from Examples/Resources/ScheduledTask/1-ScheduledTask_CreateScheduledTaskOnce_Config.ps1 rename to source/Examples/Resources/ScheduledTask/1-ScheduledTask_CreateScheduledTaskOnce_Config.ps1 index bf96ef2a..9a76c81f 100644 --- a/Examples/Resources/ScheduledTask/1-ScheduledTask_CreateScheduledTaskOnce_Config.ps1 +++ b/source/Examples/Resources/ScheduledTask/1-ScheduledTask_CreateScheduledTaskOnce_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 4310a6c2-9f34-4ebc-8895-feda5286e532 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/ScheduledTask/10-ScheduledTask_RunPowerShellTaskOnceAsUserInteractiveOnly_Config.ps1 b/source/Examples/Resources/ScheduledTask/10-ScheduledTask_RunPowerShellTaskOnceAsUserInteractiveOnly_Config.ps1 similarity index 84% rename from Examples/Resources/ScheduledTask/10-ScheduledTask_RunPowerShellTaskOnceAsUserInteractiveOnly_Config.ps1 rename to source/Examples/Resources/ScheduledTask/10-ScheduledTask_RunPowerShellTaskOnceAsUserInteractiveOnly_Config.ps1 index 176d5ec0..74ade60e 100644 --- a/Examples/Resources/ScheduledTask/10-ScheduledTask_RunPowerShellTaskOnceAsUserInteractiveOnly_Config.ps1 +++ b/source/Examples/Resources/ScheduledTask/10-ScheduledTask_RunPowerShellTaskOnceAsUserInteractiveOnly_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 0323fac5-e026-4f41-a9be-9fdcd0967b60 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/ScheduledTask/11-ScheduledTask_DisableABuiltInTask_Config.ps1 b/source/Examples/Resources/ScheduledTask/11-ScheduledTask_DisableABuiltInTask_Config.ps1 similarity index 74% rename from Examples/Resources/ScheduledTask/11-ScheduledTask_DisableABuiltInTask_Config.ps1 rename to source/Examples/Resources/ScheduledTask/11-ScheduledTask_DisableABuiltInTask_Config.ps1 index b2ee1706..48e956d3 100644 --- a/Examples/Resources/ScheduledTask/11-ScheduledTask_DisableABuiltInTask_Config.ps1 +++ b/source/Examples/Resources/ScheduledTask/11-ScheduledTask_DisableABuiltInTask_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID c3422e70-79ea-4afa-9558-1fcbe18dd0bd -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/ScheduledTask/12-ScheduledTask_DeleteABuiltInTask_Config.ps1 b/source/Examples/Resources/ScheduledTask/12-ScheduledTask_DeleteABuiltInTask_Config.ps1 similarity index 74% rename from Examples/Resources/ScheduledTask/12-ScheduledTask_DeleteABuiltInTask_Config.ps1 rename to source/Examples/Resources/ScheduledTask/12-ScheduledTask_DeleteABuiltInTask_Config.ps1 index 4b322f27..d7c36520 100644 --- a/Examples/Resources/ScheduledTask/12-ScheduledTask_DeleteABuiltInTask_Config.ps1 +++ b/source/Examples/Resources/ScheduledTask/12-ScheduledTask_DeleteABuiltInTask_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 8bed07fe-c88f-4a22-bdd8-8ec95cf8739b -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/ScheduledTask/13-ScheduledTask_CreateScheduledTasksOnEvent_Config.ps1 b/source/Examples/Resources/ScheduledTask/13-ScheduledTask_CreateScheduledTasksOnEvent_Config.ps1 similarity index 85% rename from Examples/Resources/ScheduledTask/13-ScheduledTask_CreateScheduledTasksOnEvent_Config.ps1 rename to source/Examples/Resources/ScheduledTask/13-ScheduledTask_CreateScheduledTasksOnEvent_Config.ps1 index 4f690ffd..b3ed2de4 100644 --- a/Examples/Resources/ScheduledTask/13-ScheduledTask_CreateScheduledTasksOnEvent_Config.ps1 +++ b/source/Examples/Resources/ScheduledTask/13-ScheduledTask_CreateScheduledTasksOnEvent_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID cff7293a-5b43-491c-9628-d6eca35c8bfd -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/ScheduledTask/14-ScheduledTask_RunPowerShellTaskOnceAsGroupManagedServiceAccount_Config.ps1 b/source/Examples/Resources/ScheduledTask/14-ScheduledTask_RunPowerShellTaskOnceAsGroupManagedServiceAccount_Config.ps1 similarity index 84% rename from Examples/Resources/ScheduledTask/14-ScheduledTask_RunPowerShellTaskOnceAsGroupManagedServiceAccount_Config.ps1 rename to source/Examples/Resources/ScheduledTask/14-ScheduledTask_RunPowerShellTaskOnceAsGroupManagedServiceAccount_Config.ps1 index 6924e46d..cbb5c99f 100644 --- a/Examples/Resources/ScheduledTask/14-ScheduledTask_RunPowerShellTaskOnceAsGroupManagedServiceAccount_Config.ps1 +++ b/source/Examples/Resources/ScheduledTask/14-ScheduledTask_RunPowerShellTaskOnceAsGroupManagedServiceAccount_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID cc614ca9-5994-48fb-9528-46107b3eea91 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/ScheduledTask/15-ScheduledTask_CreateScheduledTaskOnceSynchronizeAcrossTimeZoneEnabled_Config.ps1 b/source/Examples/Resources/ScheduledTask/15-ScheduledTask_CreateScheduledTaskOnceSynchronizeAcrossTimeZoneEnabled_Config.ps1 similarity index 83% rename from Examples/Resources/ScheduledTask/15-ScheduledTask_CreateScheduledTaskOnceSynchronizeAcrossTimeZoneEnabled_Config.ps1 rename to source/Examples/Resources/ScheduledTask/15-ScheduledTask_CreateScheduledTaskOnceSynchronizeAcrossTimeZoneEnabled_Config.ps1 index 3ebe8e0d..dc8fcb08 100644 --- a/Examples/Resources/ScheduledTask/15-ScheduledTask_CreateScheduledTaskOnceSynchronizeAcrossTimeZoneEnabled_Config.ps1 +++ b/source/Examples/Resources/ScheduledTask/15-ScheduledTask_CreateScheduledTaskOnceSynchronizeAcrossTimeZoneEnabled_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID ee32fb99-4150-4616-a46c-d2132ffb5205 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/ScheduledTask/16-ScheduledTask_CreateScheduledTasksAsBuiltInServiceAccount_Config.ps1 b/source/Examples/Resources/ScheduledTask/16-ScheduledTask_CreateScheduledTasksAsBuiltInServiceAccount_Config.ps1 similarity index 84% rename from Examples/Resources/ScheduledTask/16-ScheduledTask_CreateScheduledTasksAsBuiltInServiceAccount_Config.ps1 rename to source/Examples/Resources/ScheduledTask/16-ScheduledTask_CreateScheduledTasksAsBuiltInServiceAccount_Config.ps1 index 627a1e43..a051e24c 100644 --- a/Examples/Resources/ScheduledTask/16-ScheduledTask_CreateScheduledTasksAsBuiltInServiceAccount_Config.ps1 +++ b/source/Examples/Resources/ScheduledTask/16-ScheduledTask_CreateScheduledTasksAsBuiltInServiceAccount_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID a2984c97-f4fc-4936-b5d7-f8ccf726744f -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/ScheduledTask/2-ScheduledTask_CreateScheduledTaskDaily_Config.ps1 b/source/Examples/Resources/ScheduledTask/2-ScheduledTask_CreateScheduledTaskDaily_Config.ps1 similarity index 85% rename from Examples/Resources/ScheduledTask/2-ScheduledTask_CreateScheduledTaskDaily_Config.ps1 rename to source/Examples/Resources/ScheduledTask/2-ScheduledTask_CreateScheduledTaskDaily_Config.ps1 index 6ba8a35c..54cfd4d5 100644 --- a/Examples/Resources/ScheduledTask/2-ScheduledTask_CreateScheduledTaskDaily_Config.ps1 +++ b/source/Examples/Resources/ScheduledTask/2-ScheduledTask_CreateScheduledTaskDaily_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID ce544d27-c44f-44d9-a771-1ae9b22b180c -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/ScheduledTask/3-ScheduledTask_CreateScheduledTasksDailyIndefinitely_Config.ps1 b/source/Examples/Resources/ScheduledTask/3-ScheduledTask_CreateScheduledTasksDailyIndefinitely_Config.ps1 similarity index 81% rename from Examples/Resources/ScheduledTask/3-ScheduledTask_CreateScheduledTasksDailyIndefinitely_Config.ps1 rename to source/Examples/Resources/ScheduledTask/3-ScheduledTask_CreateScheduledTasksDailyIndefinitely_Config.ps1 index 047bb1dc..f240b533 100644 --- a/Examples/Resources/ScheduledTask/3-ScheduledTask_CreateScheduledTasksDailyIndefinitely_Config.ps1 +++ b/source/Examples/Resources/ScheduledTask/3-ScheduledTask_CreateScheduledTasksDailyIndefinitely_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID ae57d854-a9ae-4b3b-808d-3f23423beb29 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/ScheduledTask/4-ScheduledTask_CreateScheduledTasksWeekly_Config.ps1 b/source/Examples/Resources/ScheduledTask/4-ScheduledTask_CreateScheduledTasksWeekly_Config.ps1 similarity index 84% rename from Examples/Resources/ScheduledTask/4-ScheduledTask_CreateScheduledTasksWeekly_Config.ps1 rename to source/Examples/Resources/ScheduledTask/4-ScheduledTask_CreateScheduledTasksWeekly_Config.ps1 index 5e7b5112..4b25015b 100644 --- a/Examples/Resources/ScheduledTask/4-ScheduledTask_CreateScheduledTasksWeekly_Config.ps1 +++ b/source/Examples/Resources/ScheduledTask/4-ScheduledTask_CreateScheduledTasksWeekly_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 8817eedf-02f5-4477-8b2d-55fa73f33902 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/ScheduledTask/5-ScheduledTask_CreateScheduledTasksAtLogon_Config.ps1 b/source/Examples/Resources/ScheduledTask/5-ScheduledTask_CreateScheduledTasksAtLogon_Config.ps1 similarity index 80% rename from Examples/Resources/ScheduledTask/5-ScheduledTask_CreateScheduledTasksAtLogon_Config.ps1 rename to source/Examples/Resources/ScheduledTask/5-ScheduledTask_CreateScheduledTasksAtLogon_Config.ps1 index f436230f..d4d6441c 100644 --- a/Examples/Resources/ScheduledTask/5-ScheduledTask_CreateScheduledTasksAtLogon_Config.ps1 +++ b/source/Examples/Resources/ScheduledTask/5-ScheduledTask_CreateScheduledTasksAtLogon_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 282cba27-4cf3-43b8-86f2-f6ef0f8b4489 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/ScheduledTask/6-ScheduledTask_CreateScheduledTasksAtStartup_Config.ps1 b/source/Examples/Resources/ScheduledTask/6-ScheduledTask_CreateScheduledTasksAtStartup_Config.ps1 similarity index 80% rename from Examples/Resources/ScheduledTask/6-ScheduledTask_CreateScheduledTasksAtStartup_Config.ps1 rename to source/Examples/Resources/ScheduledTask/6-ScheduledTask_CreateScheduledTasksAtStartup_Config.ps1 index dd786617..9dfd20a8 100644 --- a/Examples/Resources/ScheduledTask/6-ScheduledTask_CreateScheduledTasksAtStartup_Config.ps1 +++ b/source/Examples/Resources/ScheduledTask/6-ScheduledTask_CreateScheduledTasksAtStartup_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID d5cfbf76-5123-48bb-a856-5ea44504b4eb -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/ScheduledTask/7-ScheduledTask_RunPowerShellTaskEvery15Minutes_Config.ps1 b/source/Examples/Resources/ScheduledTask/7-ScheduledTask_RunPowerShellTaskEvery15Minutes_Config.ps1 similarity index 80% rename from Examples/Resources/ScheduledTask/7-ScheduledTask_RunPowerShellTaskEvery15Minutes_Config.ps1 rename to source/Examples/Resources/ScheduledTask/7-ScheduledTask_RunPowerShellTaskEvery15Minutes_Config.ps1 index 3f095da9..a54ae12d 100644 --- a/Examples/Resources/ScheduledTask/7-ScheduledTask_RunPowerShellTaskEvery15Minutes_Config.ps1 +++ b/source/Examples/Resources/ScheduledTask/7-ScheduledTask_RunPowerShellTaskEvery15Minutes_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 6a249767-c480-453f-9e10-1ed7ef465d87 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/ScheduledTask/8-ScheduledTask_RunPowerShellTaskEvery15MinutesIndefinitely_Config.ps1 b/source/Examples/Resources/ScheduledTask/8-ScheduledTask_RunPowerShellTaskEvery15MinutesIndefinitely_Config.ps1 similarity index 80% rename from Examples/Resources/ScheduledTask/8-ScheduledTask_RunPowerShellTaskEvery15MinutesIndefinitely_Config.ps1 rename to source/Examples/Resources/ScheduledTask/8-ScheduledTask_RunPowerShellTaskEvery15MinutesIndefinitely_Config.ps1 index 7cb24823..d36dc4df 100644 --- a/Examples/Resources/ScheduledTask/8-ScheduledTask_RunPowerShellTaskEvery15MinutesIndefinitely_Config.ps1 +++ b/source/Examples/Resources/ScheduledTask/8-ScheduledTask_RunPowerShellTaskEvery15MinutesIndefinitely_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID dffe47fd-73f7-47d2-8604-f381e6c18f26 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/ScheduledTask/9-ScheduledTask_RunPowerShellTaskOnceAsUserWithHighestPriveleges_Config.ps1 b/source/Examples/Resources/ScheduledTask/9-ScheduledTask_RunPowerShellTaskOnceAsUserWithHighestPriveleges_Config.ps1 similarity index 84% rename from Examples/Resources/ScheduledTask/9-ScheduledTask_RunPowerShellTaskOnceAsUserWithHighestPriveleges_Config.ps1 rename to source/Examples/Resources/ScheduledTask/9-ScheduledTask_RunPowerShellTaskOnceAsUserWithHighestPriveleges_Config.ps1 index 81b67a47..fb8e6224 100644 --- a/Examples/Resources/ScheduledTask/9-ScheduledTask_RunPowerShellTaskOnceAsUserWithHighestPriveleges_Config.ps1 +++ b/source/Examples/Resources/ScheduledTask/9-ScheduledTask_RunPowerShellTaskOnceAsUserWithHighestPriveleges_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 718e81fa-c553-4715-8f5d-734fb8a02204 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/SmbServerConfiguration/1-SmbServerConfiguration_AllProperties_Config.ps1 b/source/Examples/Resources/SmbServerConfiguration/1-SmbServerConfiguration_AllProperties_Config.ps1 similarity index 91% rename from Examples/Resources/SmbServerConfiguration/1-SmbServerConfiguration_AllProperties_Config.ps1 rename to source/Examples/Resources/SmbServerConfiguration/1-SmbServerConfiguration_AllProperties_Config.ps1 index 63fdced8..d1ed7045 100644 --- a/Examples/Resources/SmbServerConfiguration/1-SmbServerConfiguration_AllProperties_Config.ps1 +++ b/source/Examples/Resources/SmbServerConfiguration/1-SmbServerConfiguration_AllProperties_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 4a847e98-a3f9-4552-8654-6c7006ef25cf -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/c/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/SmbServerConfiguration/1-SmbServerConfiguration_DisableSmb1_Config.ps1 b/source/Examples/Resources/SmbServerConfiguration/1-SmbServerConfiguration_DisableSmb1_Config.ps1 similarity index 73% rename from Examples/Resources/SmbServerConfiguration/1-SmbServerConfiguration_DisableSmb1_Config.ps1 rename to source/Examples/Resources/SmbServerConfiguration/1-SmbServerConfiguration_DisableSmb1_Config.ps1 index 087668a0..b26312be 100644 --- a/Examples/Resources/SmbServerConfiguration/1-SmbServerConfiguration_DisableSmb1_Config.ps1 +++ b/source/Examples/Resources/SmbServerConfiguration/1-SmbServerConfiguration_DisableSmb1_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID e1ed9aff-7171-425b-a513-6965662816d8 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/SmbShare/1-SmbShare_CreateShare_Config.ps1 b/source/Examples/Resources/SmbShare/1-SmbShare_CreateShare_Config.ps1 similarity index 74% rename from Examples/Resources/SmbShare/1-SmbShare_CreateShare_Config.ps1 rename to source/Examples/Resources/SmbShare/1-SmbShare_CreateShare_Config.ps1 index 47154bb7..b042687f 100644 --- a/Examples/Resources/SmbShare/1-SmbShare_CreateShare_Config.ps1 +++ b/source/Examples/Resources/SmbShare/1-SmbShare_CreateShare_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID d0847694-6a83-4f5b-bf6f-30cb078033bc -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/SmbShare/2-SmbShare_CreateShareAllProperties_Config.ps1 b/source/Examples/Resources/SmbShare/2-SmbShare_CreateShareAllProperties_Config.ps1 similarity index 82% rename from Examples/Resources/SmbShare/2-SmbShare_CreateShareAllProperties_Config.ps1 rename to source/Examples/Resources/SmbShare/2-SmbShare_CreateShareAllProperties_Config.ps1 index 3afe5d23..2c5b2522 100644 --- a/Examples/Resources/SmbShare/2-SmbShare_CreateShareAllProperties_Config.ps1 +++ b/source/Examples/Resources/SmbShare/2-SmbShare_CreateShareAllProperties_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 27cc4f2a-e366-49cb-93d6-2f094567ebf3 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/SmbShare/3-SmbShare_RemoveShare_Config.ps1 b/source/Examples/Resources/SmbShare/3-SmbShare_RemoveShare_Config.ps1 similarity index 73% rename from Examples/Resources/SmbShare/3-SmbShare_RemoveShare_Config.ps1 rename to source/Examples/Resources/SmbShare/3-SmbShare_RemoveShare_Config.ps1 index a2e26eb3..7b465390 100644 --- a/Examples/Resources/SmbShare/3-SmbShare_RemoveShare_Config.ps1 +++ b/source/Examples/Resources/SmbShare/3-SmbShare_RemoveShare_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID f11d7558-0748-4a72-b743-34424cbf4407 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/c/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/SmbShare/4-SmbShare_RecreateShare_Config.ps1 b/source/Examples/Resources/SmbShare/4-SmbShare_RecreateShare_Config.ps1 similarity index 78% rename from Examples/Resources/SmbShare/4-SmbShare_RecreateShare_Config.ps1 rename to source/Examples/Resources/SmbShare/4-SmbShare_RecreateShare_Config.ps1 index 2ce8974a..0ef20cb2 100644 --- a/Examples/Resources/SmbShare/4-SmbShare_RecreateShare_Config.ps1 +++ b/source/Examples/Resources/SmbShare/4-SmbShare_RecreateShare_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID ea641782-74b4-4673-94fe-336cbd196c16 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/SystemLocale/1-SystemLocale_SetSystemLocale_Config.ps1 b/source/Examples/Resources/SystemLocale/1-SystemLocale_SetSystemLocale_Config.ps1 similarity index 75% rename from Examples/Resources/SystemLocale/1-SystemLocale_SetSystemLocale_Config.ps1 rename to source/Examples/Resources/SystemLocale/1-SystemLocale_SetSystemLocale_Config.ps1 index 5a478bb1..4e487da2 100644 --- a/Examples/Resources/SystemLocale/1-SystemLocale_SetSystemLocale_Config.ps1 +++ b/source/Examples/Resources/SystemLocale/1-SystemLocale_SetSystemLocale_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 66476d02-bd04-4d5d-ac49-d64724716f41 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/TimeZone/1-TimeZone_SetTimeZone_Config.ps1 b/source/Examples/Resources/TimeZone/1-TimeZone_SetTimeZone_Config.ps1 similarity index 71% rename from Examples/Resources/TimeZone/1-TimeZone_SetTimeZone_Config.ps1 rename to source/Examples/Resources/TimeZone/1-TimeZone_SetTimeZone_Config.ps1 index 184f1a82..096a2892 100644 --- a/Examples/Resources/TimeZone/1-TimeZone_SetTimeZone_Config.ps1 +++ b/source/Examples/Resources/TimeZone/1-TimeZone_SetTimeZone_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID d39a7d09-4baa-44d2-bcb4-b37ae3f2e16b -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/VirtualMemory/1-VirtualMemory_SetVirtualMemory_Config.ps1 b/source/Examples/Resources/VirtualMemory/1-VirtualMemory_SetVirtualMemory_Config.ps1 similarity index 73% rename from Examples/Resources/VirtualMemory/1-VirtualMemory_SetVirtualMemory_Config.ps1 rename to source/Examples/Resources/VirtualMemory/1-VirtualMemory_SetVirtualMemory_Config.ps1 index 3b178a11..d88e9139 100644 --- a/Examples/Resources/VirtualMemory/1-VirtualMemory_SetVirtualMemory_Config.ps1 +++ b/source/Examples/Resources/VirtualMemory/1-VirtualMemory_SetVirtualMemory_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 8ea6bdd3-8822-4e6e-9957-d8576a45c55a -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/WindowsCapability/1-WindowsCapability_AddWindowsCapability_Config.ps1 b/source/Examples/Resources/WindowsCapability/1-WindowsCapability_AddWindowsCapability_Config.ps1 similarity index 71% rename from Examples/Resources/WindowsCapability/1-WindowsCapability_AddWindowsCapability_Config.ps1 rename to source/Examples/Resources/WindowsCapability/1-WindowsCapability_AddWindowsCapability_Config.ps1 index d59b4a44..d154a920 100644 --- a/Examples/Resources/WindowsCapability/1-WindowsCapability_AddWindowsCapability_Config.ps1 +++ b/source/Examples/Resources/WindowsCapability/1-WindowsCapability_AddWindowsCapability_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID adade795-9143-4f4a-ae2d-4e31e81029a2 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/WindowsCapability/2-WindowsCapability_RemoveWindowsCapability_Config.ps1 b/source/Examples/Resources/WindowsCapability/2-WindowsCapability_RemoveWindowsCapability_Config.ps1 similarity index 71% rename from Examples/Resources/WindowsCapability/2-WindowsCapability_RemoveWindowsCapability_Config.ps1 rename to source/Examples/Resources/WindowsCapability/2-WindowsCapability_RemoveWindowsCapability_Config.ps1 index ea140253..492d6851 100644 --- a/Examples/Resources/WindowsCapability/2-WindowsCapability_RemoveWindowsCapability_Config.ps1 +++ b/source/Examples/Resources/WindowsCapability/2-WindowsCapability_RemoveWindowsCapability_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 87cc15cc-113a-410a-acad-7333768d648b -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/WindowsCapability/3-WindowsCapability_AddWindowsCapabilitywithLogLevelandLogPath_Config.ps1 b/source/Examples/Resources/WindowsCapability/3-WindowsCapability_AddWindowsCapabilitywithLogLevelandLogPath_Config.ps1 similarity index 76% rename from Examples/Resources/WindowsCapability/3-WindowsCapability_AddWindowsCapabilitywithLogLevelandLogPath_Config.ps1 rename to source/Examples/Resources/WindowsCapability/3-WindowsCapability_AddWindowsCapabilitywithLogLevelandLogPath_Config.ps1 index c44fcec0..e288efcd 100644 --- a/Examples/Resources/WindowsCapability/3-WindowsCapability_AddWindowsCapabilitywithLogLevelandLogPath_Config.ps1 +++ b/source/Examples/Resources/WindowsCapability/3-WindowsCapability_AddWindowsCapabilitywithLogLevelandLogPath_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID c966b525-2764-461e-b48e-b9f479c86a64 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/WindowsEventlog/1-WindowsEventlog_SetWindowsEventlogSize_Config.ps1 b/source/Examples/Resources/WindowsEventlog/1-WindowsEventlog_SetWindowsEventlogSize_Config.ps1 similarity index 77% rename from Examples/Resources/WindowsEventlog/1-WindowsEventlog_SetWindowsEventlogSize_Config.ps1 rename to source/Examples/Resources/WindowsEventlog/1-WindowsEventlog_SetWindowsEventlogSize_Config.ps1 index d481b56b..5690f4b4 100644 --- a/Examples/Resources/WindowsEventlog/1-WindowsEventlog_SetWindowsEventlogSize_Config.ps1 +++ b/source/Examples/Resources/WindowsEventlog/1-WindowsEventlog_SetWindowsEventlogSize_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID f8fb71fd-9f4a-4ae5-93b8-53362752e37d -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/WindowsEventlog/2-WindowsEventlog_SetWindowsEventlogLogMode_Config.ps1 b/source/Examples/Resources/WindowsEventlog/2-WindowsEventlog_SetWindowsEventlogLogMode_Config.ps1 similarity index 79% rename from Examples/Resources/WindowsEventlog/2-WindowsEventlog_SetWindowsEventlogLogMode_Config.ps1 rename to source/Examples/Resources/WindowsEventlog/2-WindowsEventlog_SetWindowsEventlogLogMode_Config.ps1 index 7c437c81..338ae385 100644 --- a/Examples/Resources/WindowsEventlog/2-WindowsEventlog_SetWindowsEventlogLogMode_Config.ps1 +++ b/source/Examples/Resources/WindowsEventlog/2-WindowsEventlog_SetWindowsEventlogLogMode_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 5e3f845c-58ce-4e46-baaf-2422d30176ca -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/WindowsEventlog/3-WindowsEventlog_EnableWindowsEventLog_Config.ps1 b/source/Examples/Resources/WindowsEventlog/3-WindowsEventlog_EnableWindowsEventLog_Config.ps1 similarity index 79% rename from Examples/Resources/WindowsEventlog/3-WindowsEventlog_EnableWindowsEventLog_Config.ps1 rename to source/Examples/Resources/WindowsEventlog/3-WindowsEventlog_EnableWindowsEventLog_Config.ps1 index ddd51c02..4a2d01ec 100644 --- a/Examples/Resources/WindowsEventlog/3-WindowsEventlog_EnableWindowsEventLog_Config.ps1 +++ b/source/Examples/Resources/WindowsEventlog/3-WindowsEventlog_EnableWindowsEventLog_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID f05286e4-e357-40f8-ba62-e49d4d50eb0f -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/WindowsEventlog/4-WindowsEventlog_SetWindowsEventlogLogMode_Config.ps1 b/source/Examples/Resources/WindowsEventlog/4-WindowsEventlog_SetWindowsEventlogLogMode_Config.ps1 similarity index 77% rename from Examples/Resources/WindowsEventlog/4-WindowsEventlog_SetWindowsEventlogLogMode_Config.ps1 rename to source/Examples/Resources/WindowsEventlog/4-WindowsEventlog_SetWindowsEventlogLogMode_Config.ps1 index 135dd66d..792a8818 100644 --- a/Examples/Resources/WindowsEventlog/4-WindowsEventlog_SetWindowsEventlogLogMode_Config.ps1 +++ b/source/Examples/Resources/WindowsEventlog/4-WindowsEventlog_SetWindowsEventlogLogMode_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 1e24ee07-cb2f-489b-af15-ebf6ffa864fe -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/WindowsEventlog/5-WindowsEventlog_SetWindowsEventlogSecurityDescriptor_Config.ps1 b/source/Examples/Resources/WindowsEventlog/5-WindowsEventlog_SetWindowsEventlogSecurityDescriptor_Config.ps1 similarity index 80% rename from Examples/Resources/WindowsEventlog/5-WindowsEventlog_SetWindowsEventlogSecurityDescriptor_Config.ps1 rename to source/Examples/Resources/WindowsEventlog/5-WindowsEventlog_SetWindowsEventlogSecurityDescriptor_Config.ps1 index 003835d4..0f8c89ee 100644 --- a/Examples/Resources/WindowsEventlog/5-WindowsEventlog_SetWindowsEventlogSecurityDescriptor_Config.ps1 +++ b/source/Examples/Resources/WindowsEventlog/5-WindowsEventlog_SetWindowsEventlogSecurityDescriptor_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 07323d21-39a0-4f62-bed7-7acc943f9234 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Examples/Resources/WindowsEventlog/6-WindowsEventlog_DisableWindowsEventlog_Config.ps1 b/source/Examples/Resources/WindowsEventlog/6-WindowsEventlog_DisableWindowsEventlog_Config.ps1 similarity index 74% rename from Examples/Resources/WindowsEventlog/6-WindowsEventlog_DisableWindowsEventlog_Config.ps1 rename to source/Examples/Resources/WindowsEventlog/6-WindowsEventlog_DisableWindowsEventlog_Config.ps1 index 61ee8b5f..1004de27 100644 --- a/Examples/Resources/WindowsEventlog/6-WindowsEventlog_DisableWindowsEventlog_Config.ps1 +++ b/source/Examples/Resources/WindowsEventlog/6-WindowsEventlog_DisableWindowsEventlog_Config.ps1 @@ -1,12 +1,12 @@ <#PSScriptInfo .VERSION 1.0.0 .GUID 1d426e51-df3b-4723-96ac-e7d790744f69 -.AUTHOR Microsoft Corporation -.COMPANYNAME Microsoft Corporation -.COPYRIGHT (c) Microsoft Corporation. All rights reserved. +.AUTHOR DSC Community +.COMPANYNAME DSC Community +.COPYRIGHT Copyright the DSC Community contributors. All rights reserved. .TAGS DSCConfiguration -.LICENSEURI https://github.com/PowerShell/ComputerManagementDsc/blob/master/LICENSE -.PROJECTURI https://github.com/PowerShell/ComputerManagementDsc +.LICENSEURI https://github.com/dsccommunity/ComputerManagementDsc/blob/master/LICENSE +.PROJECTURI https://github.com/dsccommunity/ComputerManagementDsc .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS diff --git a/Modules/ComputerManagementDsc.Common/ComputerManagementDsc.Common.psm1 b/source/Modules/ComputerManagementDsc.Common/ComputerManagementDsc.Common.psm1 similarity index 98% rename from Modules/ComputerManagementDsc.Common/ComputerManagementDsc.Common.psm1 rename to source/Modules/ComputerManagementDsc.Common/ComputerManagementDsc.Common.psm1 index ebad769f..16250bf1 100644 --- a/Modules/ComputerManagementDsc.Common/ComputerManagementDsc.Common.psm1 +++ b/source/Modules/ComputerManagementDsc.Common/ComputerManagementDsc.Common.psm1 @@ -6,9 +6,9 @@ .PARAMETER ResourceName The name of the resource as it appears before '.strings.psd1' of the localized string file. For example: - For WindowsOptionalFeature: MSFT_WindowsOptionalFeature - For Service: MSFT_ServiceResource - For Registry: MSFT_RegistryResource + For WindowsOptionalFeature: DSC_WindowsOptionalFeature + For Service: DSC_ServiceResource + For Registry: DSC_RegistryResource For Helper: SqlServerDscHelper .PARAMETER ScriptRoot @@ -82,7 +82,7 @@ function Test-IsNanoServer $computerInfo = Get-ComputerInfo if ('Server' -eq $computerInfo.OsProductType ` - -and 'NanoServer' -eq $computerInfo.OsServerLevel) + -and 'NanoServer' -eq $computerInfo.OsServerLevel) { return $true } @@ -120,7 +120,7 @@ function New-InvalidArgumentException $argumentException = New-Object -TypeName 'ArgumentException' -ArgumentList @( $Message, $ArgumentName ) $newObjectParams = @{ - TypeName = 'System.Management.Automation.ErrorRecord' + TypeName = 'System.Management.Automation.ErrorRecord' ArgumentList = @( $argumentException, $ArgumentName, 'InvalidArgument', $null ) } $errorRecord = New-Object @newObjectParams @@ -157,17 +157,17 @@ function New-InvalidOperationException if ($null -eq $ErrorRecord) { $invalidOperationException = - New-Object -TypeName 'InvalidOperationException' -ArgumentList @( $Message ) + New-Object -TypeName 'InvalidOperationException' -ArgumentList @( $Message ) } else { $invalidOperationException = - New-Object -TypeName 'InvalidOperationException' -ArgumentList @( $Message, - $ErrorRecord.Exception ) + New-Object -TypeName 'InvalidOperationException' -ArgumentList @( $Message, + $ErrorRecord.Exception ) } $newObjectParams = @{ - TypeName = 'System.Management.Automation.ErrorRecord' + TypeName = 'System.Management.Automation.ErrorRecord' ArgumentList = @( $invalidOperationException.ToString(), 'MachineStateIncorrect', 'InvalidOperation', $null ) } @@ -719,7 +719,7 @@ function Get-TimeZoneId Write-Verbose -Message ($script:localizedData.CurrentTimeZoneMessage -f $timeZone) $timeZoneInfo = [System.TimeZoneInfo]::GetSystemTimeZones() | - Where-Object -Property StandardName -EQ $timeZone + Where-Object -Property StandardName -EQ $timeZone return $timeZoneInfo.Id } # function Get-TimeZoneId @@ -1215,7 +1215,7 @@ function Set-ActivePowerPlan try { # Set the active power scheme with the native function - $returnCode = $powrprof::PowerSetActiveScheme([System.IntPtr]::Zero,$PowerPlanGuid) + $returnCode = $powrprof::PowerSetActiveScheme([System.IntPtr]::Zero, $PowerPlanGuid) # Check for non 0 return codes / errors form the native function if ($returnCode -ne 0) diff --git a/Modules/ComputerManagementDsc.Common/SetTimeZone.cs b/source/Modules/ComputerManagementDsc.Common/SetTimeZone.cs similarity index 100% rename from Modules/ComputerManagementDsc.Common/SetTimeZone.cs rename to source/Modules/ComputerManagementDsc.Common/SetTimeZone.cs diff --git a/Modules/ComputerManagementDsc.Common/en-US/ComputerManagementDsc.Common.strings.psd1 b/source/Modules/ComputerManagementDsc.Common/en-US/ComputerManagementDsc.Common.strings.psd1 similarity index 100% rename from Modules/ComputerManagementDsc.Common/en-US/ComputerManagementDsc.Common.strings.psd1 rename to source/Modules/ComputerManagementDsc.Common/en-US/ComputerManagementDsc.Common.strings.psd1 diff --git a/source/en-US/about_ComputerManagementDsc.help.txt b/source/en-US/about_ComputerManagementDsc.help.txt new file mode 100644 index 00000000..71a4fcbc --- /dev/null +++ b/source/en-US/about_ComputerManagementDsc.help.txt @@ -0,0 +1,34 @@ +TOPIC + about_ComputerManagementDsc + +SHORT DESCRIPTION + DSC resources for configuration of a Windows computer. These DSC resources + allow you to perform computer management tasks, such as renaming the computer, + joining a domain and scheduling tasks as well as configuring items such as + virtual memory, event logs, time zones and power settings. + +LONG DESCRIPTION + This module contains DSC resources for configuration of a Windows computer. + These DSC resources allow you to perform computer management tasks, such as + renaming the computer, joining a domain and scheduling tasks as well as + configuring items such as virtual memory, event logs, time zones and power + settings. + +EXAMPLES + PS C:\> Get-DscResource -Module ComputerManagementDsc + +NOTE: + Thank you to the DSC Community contributors who contributed to this module by + writing code, sharing opinions, and provided feedback. + +TROUBLESHOOTING NOTE: + Go to the Github repository for read about issues, submit a new issue, and read + about new releases. https://github.com/dsccommunity/ComputerManagementDsc + +SEE ALSO + - https://github.com/dsccommunity/ComputerManagementDsc + +KEYWORDS + DSC, DscResource, Computer, OfflineDomainJoin, PendingReboot, PowerPlan, + PowerShellExecutionPolicy, RemoteDesktopAdmin, ScheduledTask, SmbServerConfiguration + SmbShare, SystemLocale, TimeZone, VirtualMemory, WindowsEventLog, WindowsCapability diff --git a/Tests/Integration/ComputerManagementDsc.Common.Tests.ps1 b/tests/Integration/ComputerManagementDsc.Common.Tests.ps1 similarity index 63% rename from Tests/Integration/ComputerManagementDsc.Common.Tests.ps1 rename to tests/Integration/ComputerManagementDsc.Common.Tests.ps1 index a99b5a2b..c40aad94 100644 --- a/Tests/Integration/ComputerManagementDsc.Common.Tests.ps1 +++ b/tests/Integration/ComputerManagementDsc.Common.Tests.ps1 @@ -1,18 +1,25 @@ #region HEADER -$script:ModuleName = 'ComputerManagementDsc.Common' +$script:projectPath = "$PSScriptRoot\..\.." | Convert-Path +$script:projectName = (Get-ChildItem -Path "$script:projectPath\*\*.psd1" | Where-Object -FilterScript { + ($_.Directory.Name -match 'source|src' -or $_.Directory.Name -eq $_.BaseName) -and + $(try + { + Test-ModuleManifest -Path $_.FullName -ErrorAction Stop + } + catch + { + $false + }) + }).BaseName -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global +$script:parentModule = Get-Module -Name $script:projectName -ListAvailable | Select-Object -First 1 +$script:subModulesFolder = Join-Path -Path $script:parentModule.ModuleBase -ChildPath 'Modules' +Remove-Module -Name $script:parentModule -Force -ErrorAction 'SilentlyContinue' -# Unit Test Template Version: 1.2.4 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} +$script:subModuleName = (Split-Path -Path $PSCommandPath -Leaf) -replace '\.Tests.ps1' +$script:subModuleFile = Join-Path -Path $script:subModulesFolder -ChildPath "$($script:subModuleName)/$($script:subModuleName).psm1" -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force -Import-Module (Join-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'Modules' -ChildPath $script:ModuleName)) -ChildPath "$script:ModuleName.psm1") -Force +Import-Module $script:subModuleFile -Force -ErrorAction Stop #endregion HEADER # Store the test machine timezone @@ -24,8 +31,7 @@ tzutil.exe /s 'Eastern Standard Time' # Using try/finally to always cleanup even if something awful happens. try { - InModuleScope $script:ModuleName { - + InModuleScope $script:subModuleName { Describe 'ComputerManagementDsc.Common\Set-TimeZoneId' { <# The purpose of this test is to ensure the C# .NET code @@ -42,16 +48,16 @@ try Mock ` -CommandName Get-Command ` -ParameterFilter { - $Name -eq 'Add-Type' - } -MockWith { - 'Add-Type' - } + $Name -eq 'Add-Type' + } -MockWith { + 'Add-Type' + } Mock ` -CommandName Get-Command ` -ParameterFilter { - $Name -eq 'Set-TimeZone' - } + $Name -eq 'Set-TimeZone' + } Mock -CommandName 'TzUtil.exe' -MockWith { $Script:LASTEXITCODE = 0 @@ -70,14 +76,14 @@ try Assert-MockCalled ` -CommandName Get-Command ` -ParameterFilter { - $Name -eq 'Add-Type' - } -Exactly -Times 1 + $Name -eq 'Add-Type' + } -Exactly -Times 1 Assert-MockCalled ` -CommandName Get-Command ` -ParameterFilter { - $Name -eq 'Set-TimeZone' - } -Exactly -Times 1 + $Name -eq 'Set-TimeZone' + } -Exactly -Times 1 Assert-MockCalled -CommandName TzUtil.exe -Exactly -Times 0 } diff --git a/tests/Integration/DSC_PendingReboot.Tests.ps1 b/tests/Integration/DSC_PendingReboot.Tests.ps1 new file mode 100644 index 00000000..cf9a9854 --- /dev/null +++ b/tests/Integration/DSC_PendingReboot.Tests.ps1 @@ -0,0 +1,124 @@ +$script:dscModuleName = 'ComputerManagementDsc' +$script:dscResourceName = 'DSC_PendingReboot' + +try +{ + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' +} +catch [System.IO.FileNotFoundException] +{ + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' +} + +$script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Integration' + +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') + +# Begin Testing +try +{ + Describe 'PendingReboot Integration Tests' { + $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" + . $configFile + + Describe "$($script:dscResourceName)_Integration" { + <# + These integration tests will not actually reboot the node + because that would terminate the tests and cause them to fail. + + There does not appear to be a method of determining if the + reboot is in fact triggered, so this is not currently tested. + + Instead, we will preserve the current state of the Auto Update + 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. + #> + $windowsUpdateKeys = (Get-ChildItem -Path $rebootRegistryKeys.WindowsUpdate).Name + + if ($windowsUpdateKeys) + { + $script:currentAutoUpdateRebootState = $windowsUpdateKeys.Split('\') -contains 'RebootRequired' + } + + if (-not $script:currentAutoUpdateRebootState) + { + $null = New-Item ` + -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\' ` + -Name 'RebootRequired' + } + + $configData = @{ + AllNodes = @( + @{ + NodeName = 'localhost' + RebootName = 'TestReboot' + SkipComponentBasedServicing = $false + SkipWindowsUpdate = $false + SkipPendingFileRename = $false + SkipPendingComputerRename = $false + SkipCcmClientSDK = $true + } + ) + } + + It 'Should compile and apply the MOF without throwing' { + { + & "$($script:dscResourceName)_Config" ` + -OutputPath $TestDrive ` + -ConfigurationData $configData + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + Start-DscConfiguration @startDscConfigurationParameters + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { + Get-DscConfiguration -Verbose -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $current = Get-DscConfiguration | Where-Object -FilterScript { + $_.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 + } + } + } +} +finally +{ + if (-not $script:currentAutoUpdateRebootState) + { + $null = Remove-Item ` + -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired' ` + -ErrorAction SilentlyContinue + } + + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} diff --git a/Tests/Integration/MSFT_PendingReboot.Config.ps1 b/tests/Integration/DSC_PendingReboot.config.ps1 similarity index 88% rename from Tests/Integration/MSFT_PendingReboot.Config.ps1 rename to tests/Integration/DSC_PendingReboot.config.ps1 index 7e8d7c35..9736087a 100644 --- a/Tests/Integration/MSFT_PendingReboot.Config.ps1 +++ b/tests/Integration/DSC_PendingReboot.config.ps1 @@ -1,9 +1,10 @@ # Integration Test Config Template Version: 1.0.0 -configuration MSFT_PendingReboot_config +Configuration DSC_PendingReboot_config { Import-DscResource -ModuleName ComputerManagementDsc - node $AllNodes.NodeName { + node $AllNodes.NodeName + { PendingReboot TestReboot { Name = $Node.RebootName diff --git a/tests/Integration/DSC_PowerShellExecutionPolicy.Integration.Tests.ps1 b/tests/Integration/DSC_PowerShellExecutionPolicy.Integration.Tests.ps1 new file mode 100644 index 00000000..cbdba374 --- /dev/null +++ b/tests/Integration/DSC_PowerShellExecutionPolicy.Integration.Tests.ps1 @@ -0,0 +1,65 @@ +$script:dscModuleName = 'ComputerManagementDsc' +$script:dscResourceName = 'DSC_PowerShellExecutionPolicy' + +try +{ + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' +} +catch [System.IO.FileNotFoundException] +{ + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' +} + +$script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Integration' + +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') + +# Begin Testing +try +{ + Describe 'PowerShellExecutionPolicy Integration Tests' { + $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" + . $configFile + + Describe "$($script:dscResourceName)_Integration" { + It 'Should compile and apply the MOF without throwing' { + { + & "$($script:dscResourceName)_Config" -OutputPath $TestDrive + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + Start-DscConfiguration @startDscConfigurationParameters + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { + Get-DscConfiguration -Verbose -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $current = Get-DscConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq "$($script:dscResourceName)_Config" + } + $current.ExecutionPolicy | Should -Be 'RemoteSigned' + $current.ExecutionPolicyScope | Should -Be 'LocalMachine' + } + } + } +} +finally +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} diff --git a/Tests/Integration/MSFT_PowerShellExecutionPolicy.config.ps1 b/tests/Integration/DSC_PowerShellExecutionPolicy.config.ps1 similarity index 85% rename from Tests/Integration/MSFT_PowerShellExecutionPolicy.config.ps1 rename to tests/Integration/DSC_PowerShellExecutionPolicy.config.ps1 index c1fd0292..6355181a 100644 --- a/Tests/Integration/MSFT_PowerShellExecutionPolicy.config.ps1 +++ b/tests/Integration/DSC_PowerShellExecutionPolicy.config.ps1 @@ -1,6 +1,6 @@ # Integration Test Config Template Version: 1.0.0 -configuration MSFT_PowerShellExecutionPolicy_config - { +Configuration DSC_PowerShellExecutionPolicy_config +{ Import-DscResource -ModuleName ComputerManagementDsc node 'localhost' diff --git a/tests/Integration/DSC_RemoteDesktopAdmin.Integration.Tests.ps1 b/tests/Integration/DSC_RemoteDesktopAdmin.Integration.Tests.ps1 new file mode 100644 index 00000000..439d9ce8 --- /dev/null +++ b/tests/Integration/DSC_RemoteDesktopAdmin.Integration.Tests.ps1 @@ -0,0 +1,169 @@ +$script:dscModuleName = 'ComputerManagementDsc' +$script:dscResourceName = 'DSC_RemoteDesktopAdmin' + +try +{ + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' +} +catch [System.IO.FileNotFoundException] +{ + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' +} + +$script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Integration' + +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') + +# Begin Testing +try +{ + Describe 'RemoteDesktopAdmin Integration Tests' { + $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" + . $configFile + + $script:tSRegistryKey = 'HKLM:\System\CurrentControlSet\Control\Terminal Server' + $script:winStationsRegistryKey = 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' + + Describe "$($script:dscResourceName)_Integration" { + Context 'When setting Remote Desktop for Administration to Denied' { + $CurrentConfig = 'setToDenied' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file without error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -Be $true + } + + It 'Should return the correct values from Get-DscConfiguration' { + $Current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $CurrentConfig } + $Current.IsSingleInstance | Should -Be 'Yes' + $Current.Ensure | Should -Be 'Absent' + } + + It 'Should have set the correct registry values' { + (Get-ItemProperty -Path $script:tSRegistryKey -Name 'fDenyTSConnections').fDenyTSConnections | Should -Be 1 + } + } + + Context 'When setting Remote Desktop for Administration to Allowed' { + $CurrentConfig = 'setToAllowed' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file without error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -Be $true + } + + It 'Should return the correct values from Get-DscConfiguration' { + $Current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $CurrentConfig } + $Current.IsSingleInstance | Should -Be 'Yes' + $Current.Ensure | Should -Be 'Present' + } + + It 'Should have set the correct registry values' { + (Get-ItemProperty -Path $script:tSRegistryKey -Name 'fDenyTSConnections').fDenyTSConnections | Should -Be 0 + } + } + + Context 'When settting Remote Desktop for Administration to Allowed with Secure Authentication' { + $CurrentConfig = 'setToAllowedSecure' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file without error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -Be $true + } + + It 'Should return the correct values from Get-DscConfiguration' { + $Current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $CurrentConfig } + $Current.IsSingleInstance | Should -Be 'Yes' + $Current.Ensure | Should -Be 'Present' + $Current.UserAuthentication | Should -Be 'Secure' + } + + It 'Should have set the correct registry values' { + (Get-ItemProperty -Path $script:tSRegistryKey -Name 'fDenyTSConnections').fDenyTSConnections | Should -Be 0 + (Get-ItemProperty -Path $script:winStationsRegistryKey -Name 'UserAuthentication').UserAuthentication | Should -Be 1 + } + } + + Context 'When settting Remote Desktop for Administration to Allowed with NonSecure Authentication' { + $CurrentConfig = 'setToAllowedNonSecure' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file without error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -Be $true + } + + It 'Should return the correct values from Get-DscConfiguration' { + $Current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $CurrentConfig } + $Current.IsSingleInstance | Should -Be 'Yes' + $Current.Ensure | Should -Be 'Present' + $Current.UserAuthentication | Should -Be 'NonSecure' + } + + It 'Should have set the correct registry values' { + (Get-ItemProperty -Path $script:tSRegistryKey -Name 'fDenyTSConnections').fDenyTSConnections | Should -Be 0 + (Get-ItemProperty -Path $script:winStationsRegistryKey -Name 'UserAuthentication').UserAuthentication | Should -Be 0 + } + } + } + } +} +finally +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} diff --git a/Tests/Integration/MSFT_RemoteDesktopAdmin.Config.ps1 b/tests/Integration/DSC_RemoteDesktopAdmin.config.ps1 similarity index 67% rename from Tests/Integration/MSFT_RemoteDesktopAdmin.Config.ps1 rename to tests/Integration/DSC_RemoteDesktopAdmin.config.ps1 index 57f63e7b..0a0061c9 100644 --- a/Tests/Integration/MSFT_RemoteDesktopAdmin.Config.ps1 +++ b/tests/Integration/DSC_RemoteDesktopAdmin.config.ps1 @@ -1,6 +1,7 @@ -configuration setToDenied +Configuration setToDenied { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { RemoteDesktopAdmin RemoteDesktopAdmin { @@ -10,9 +11,10 @@ configuration setToDenied } } -configuration setToAllowed +Configuration setToAllowed { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { RemoteDesktopAdmin RemoteDesktopAdmin { @@ -22,28 +24,30 @@ configuration setToAllowed } } -configuration setToAllowedSecure +Configuration setToAllowedSecure { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { RemoteDesktopAdmin RemoteDesktopAdmin { - IsSingleInstance = 'Yes' - Ensure = 'Present' - UserAuthentication = 'Secure' + IsSingleInstance = 'Yes' + Ensure = 'Present' + UserAuthentication = 'Secure' } } } -configuration setToAllowedNonSecure +Configuration setToAllowedNonSecure { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { RemoteDesktopAdmin RemoteDesktopAdmin { - IsSingleInstance = 'Yes' - Ensure = 'Present' - UserAuthentication = 'NonSecure' + IsSingleInstance = 'Yes' + Ensure = 'Present' + UserAuthentication = 'NonSecure' } } } diff --git a/tests/Integration/DSC_ScheduledTask.Integration.Tests.ps1 b/tests/Integration/DSC_ScheduledTask.Integration.Tests.ps1 new file mode 100644 index 00000000..5d049666 --- /dev/null +++ b/tests/Integration/DSC_ScheduledTask.Integration.Tests.ps1 @@ -0,0 +1,390 @@ +#Requires -Version 5.0 + +$script:dscModuleName = 'ComputerManagementDsc' +$script:dscResourceName = 'DSC_ScheduledTask' + +try +{ + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' +} +catch [System.IO.FileNotFoundException] +{ + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' +} + +$script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Integration' + +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') + +# Begin Testing +try +{ + Describe 'ScheduledTask Integration Tests' { + $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" + . $configFile + + #region Pester Tests + Describe "$($script:dscResourceName)_Integration" { + $contexts = @{ + Once = 'ScheduledTaskOnce' + Daily = 'ScheduledTaskDaily' + DailyIndefinitely = 'ScheduledTaskDailyIndefinitely' + Weekly = 'ScheduledTaskWeekly' + AtLogon = 'ScheduledTaskLogon' + AtStartup = 'ScheduledTaskStartup' + ExecuteAs = 'ScheduledTaskExecuteAs' + ExecuteAsGroup = 'ScheduledTaskExecuteAsGroup' + OnEvent = 'ScheduledTaskOnEvent' + } + + $configData = @{ + AllNodes = @( + @{ + NodeName = 'localhost' + PSDscAllowPlainTextPassword = $true + } + ) + } + + foreach ($contextInfo in $contexts.GetEnumerator()) + { + Context "[$($contextInfo.Key)] No scheduled task exists but it should" { + $currentConfig = '{0}Add' -f $contextInfo.Value + $configDir = (Join-Path -Path $TestDrive -ChildPath $currentConfig) + $configMof = (Join-Path -Path $configDir -ChildPath 'localhost.mof') + + It 'Should compile the MOF without throwing' { + { + . $currentConfig ` + -OutputPath $configDir ` + -ConfigurationData $configData + } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration ` + -Path $configDir ` + -Wait ` + -Force ` + -Verbose ` + -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $configMof -Verbose).InDesiredState | Should -BeTrue + } + } + + Context "[$($contextInfo.Key)] A scheduled task exists with the wrong settings" { + $currentConfig = '{0}Mod' -f $contextInfo.Value + $configDir = (Join-Path -Path $TestDrive -ChildPath $currentConfig) + $configMof = (Join-Path -Path $configDir -ChildPath 'localhost.mof') + + It 'Should compile the MOF without throwing' { + { + . $currentConfig ` + -OutputPath $configDir ` + -ConfigurationData $configData + } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration ` + -Path $configDir ` + -Wait ` + -Force ` + -Verbose ` + -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $configMof -Verbose).InDesiredState | Should -BeTrue + } + } + + Context "[$($contextInfo.Key)] A scheduled tasks exists but it should not" { + $currentConfig = '{0}Del' -f $contextInfo.Value + $configDir = (Join-Path -Path $TestDrive -ChildPath $currentConfig) + $configMof = (Join-Path -Path $configDir -ChildPath 'localhost.mof') + + It 'Should compile the MOF without throwing' { + { + . $currentConfig ` + -OutputPath $configDir ` + -ConfigurationData $configData + } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration ` + -Path $configDir ` + -Wait ` + -Force ` + -Verbose ` + -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $configMof -Verbose).InDesiredState | Should -BeTrue + } + } + } + + Context 'MOF is created in a different timezone to node MOF being applied to' { + BeforeAll { + $currentTimeZoneId = Get-TimeZoneId + } + + $currentConfig = 'ScheduledTaskOnceCrossTimezone' + $configDir = (Join-Path -Path $TestDrive -ChildPath $currentConfig) + $configMof = (Join-Path -Path $configDir -ChildPath 'localhost.mof') + + It 'Should compile the MOF without throwing in W. Australia Standard Time Timezone' { + { + + Set-TimeZoneId -TimeZoneId 'W. Australia Standard Time' + . $currentConfig ` + -OutputPath $configDir + } | Should -Not -Throw + } + + It 'Should apply the MOF correctly in New Zealand Standard Time Timezone' { + { + Set-TimeZoneId -TimeZoneId 'New Zealand Standard Time' + Start-DscConfiguration ` + -Path $configDir ` + -Wait ` + -Force ` + -Verbose ` + -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $configMof -Verbose).InDesiredState | Should -BeTrue + } + + It 'Should have set the resource and all the parameters should match' { + $current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $currentConfig } + $current.TaskName | Should -Be 'Test task once cross timezone' + $current.TaskPath | Should -Be '\ComputerManagementDsc\' + $current.ActionExecutable | Should -Be 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' + $current.ScheduleType | Should -Be 'Once' + $current.RepeatInterval | Should -Be '00:15:00' + $current.RepetitionDuration | Should -Be '23:00:00' + $current.ActionWorkingPath | Should -Be (Get-Location).Path + $current.Enable | Should -BeTrue + $current.RandomDelay | Should -Be '01:00:00' + $current.DisallowHardTerminate | Should -BeTrue + $current.RunOnlyIfIdle | Should -BeFalse + $current.Priority | Should -Be 9 + $current.RunLevel | Should -Be 'Limited' + $current.ExecutionTimeLimit | Should -Be '00:00:00' + } + + AfterAll { + Set-TimeZoneId -TimeZoneId $currentTimeZoneId + } + } + + Context 'When a scheduled task is created and synchronize across time zone is disabled' { + $currentConfig = 'ScheduledTaskOnceSynchronizeAcrossTimeZoneDisabled' + $configDir = (Join-Path -Path $TestDrive -ChildPath $currentConfig) + $configMof = (Join-Path -Path $configDir -ChildPath 'localhost.mof') + + It 'Should compile the MOF without throwing' { + { + . $currentConfig ` + -OutputPath $configDir + } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration ` + -Path $configDir ` + -Wait ` + -Force ` + -Verbose ` + -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $configMof -Verbose).InDesiredState | Should -BeTrue + } + + $expectedStartTime = '2018-10-01T01:00:00' + + It 'Should have set the resource and all the parameters should match' { + $current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $currentConfig } + $current.TaskName | Should -Be 'Test task sync across time zone disabled' + $current.TaskPath | Should -Be '\ComputerManagementDsc\' + $current.ActionExecutable | Should -Be 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' + $current.ScheduleType | Should -Be 'Once' + $current.StartTime | Should -Be (Get-Date -Date $expectedStartTime) + $current.SynchronizeAcrossTimeZone | Should -BeFalse + $current.ActionWorkingPath | Should -Be (Get-Location).Path + $current.Enable | Should -BeTrue + } + + It "Should have the trigger startBoundary set to $expectedStartTime" { + $task = (Get-ScheduledTask -TaskName 'Test task sync across time zone disabled') + $task.Triggers[0].StartBoundary | Should -Be $expectedStartTime + } + } + + Context 'When a scheduled task is created and synchronize across time zone is enabled' { + $currentConfig = 'ScheduledTaskOnceSynchronizeAcrossTimeZoneEnabled' + $configDir = (Join-Path -Path $TestDrive -ChildPath $currentConfig) + $configMof = (Join-Path -Path $configDir -ChildPath 'localhost.mof') + + It 'Should compile the MOF without throwing' { + { + . $currentConfig ` + -OutputPath $configDir + } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration ` + -Path $configDir ` + -Wait ` + -Force ` + -Verbose ` + -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $configMof -Verbose).InDesiredState | Should -BeTrue + } + + $expectedStartTime = '2018-10-01T01:00:00' + (Get-Date -Format 'zzz') + + It 'Should have set the resource and all the parameters should match' { + $current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $currentConfig } + $current.TaskName | Should -Be 'Test task sync across time zone enabled' + $current.TaskPath | Should -Be '\ComputerManagementDsc\' + $current.ActionExecutable | Should -Be 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' + $current.ScheduleType | Should -Be 'Once' + $current.StartTime | Should -Be (Get-Date -Date $expectedStartTime) + $current.SynchronizeAcrossTimeZone | Should -BeTrue + $current.ActionWorkingPath | Should -Be (Get-Location).Path + $current.Enable | Should -BeTrue + } + + It "Should have the trigger startBoundary set to $expectedStartTime" { + $task = (Get-ScheduledTask -TaskName 'Test task sync across time zone enabled') + $task.Triggers[0].StartBoundary | Should -Be $expectedStartTime + } + } + + # Simulate a "built-in" scheduled task + $action = New-ScheduledTaskAction -Execute 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' + $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) + $task = New-ScheduledTask -Action $action -Trigger $trigger + Register-ScheduledTask -InputObject $task -TaskName 'Test task builtin' -TaskPath '\ComputerManagementDsc\' -User 'NT AUTHORITY\SYSTEM' + + Context 'Built-in task needs to be disabled' { + $currentConfig = 'ScheduledTaskDisableBuiltIn' + $configDir = (Join-Path -Path $TestDrive -ChildPath $currentConfig) + $configMof = (Join-Path -Path $configDir -ChildPath 'localhost.mof') + + It 'Should compile the MOF without throwing' { + { + . $currentConfig ` + -OutputPath $configDir ` + -ConfigurationData $configData + } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration ` + -Path $configDir ` + -Wait ` + -Force ` + -Verbose ` + -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $configMof -Verbose).InDesiredState | Should -BeTrue + } + + It 'Should have set the resource and all the parameters should match' { + $current = Get-DscConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq $currentConfig + } + $current.TaskName | Should -Be 'Test task builtin' + $current.TaskPath | Should -Be '\ComputerManagementDsc\' + $current.Enable | Should -BeFalse + } + } + + Context 'Built-in task needs to be removed' { + $currentConfig = 'ScheduledTaskRemoveBuiltIn' + $configDir = (Join-Path -Path $TestDrive -ChildPath $currentConfig) + $configMof = (Join-Path -Path $configDir -ChildPath 'localhost.mof') + + + It 'Should compile the MOF without throwing' { + { + . $currentConfig ` + -OutputPath $configDir ` + -ConfigurationData $configData + } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration ` + -Path $configDir ` + -Wait ` + -Force ` + -Verbose ` + -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $configMof -Verbose).InDesiredState | Should -BeTrue + } + + It 'Should have set the resource and all the parameters should match' { + $current = Get-DscConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq $currentConfig + } + $current.TaskName | Should -Be 'Test task builtin' + $current.TaskPath | Should -Be '\ComputerManagementDsc\' + $current.Ensure | Should -Be 'Absent' + } + } + } + } +} +finally +{ + # Remove any traces of the created tasks + Get-ScheduledTask -TaskPath '\ComputerManagementDsc\' -ErrorAction SilentlyContinue | Unregister-ScheduledTask -ErrorAction SilentlyContinue -Confirm:$false + + $scheduler = New-Object -ComObject Schedule.Service + $scheduler.Connect() + $rootFolder = $scheduler.GetFolder('\') + $rootFolder.DeleteFolder('ComputerManagementDsc', 0) + + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} diff --git a/Tests/Integration/MSFT_ScheduledTask.Config.ps1 b/tests/Integration/DSC_ScheduledTask.config.ps1 similarity index 98% rename from Tests/Integration/MSFT_ScheduledTask.Config.ps1 rename to tests/Integration/DSC_ScheduledTask.config.ps1 index 96b42fb0..90bea108 100644 --- a/Tests/Integration/MSFT_ScheduledTask.Config.ps1 +++ b/tests/Integration/DSC_ScheduledTask.config.ps1 @@ -1,6 +1,7 @@ Configuration ScheduledTaskOnceCrossTimezone { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskOnceAdd @@ -25,6 +26,7 @@ Configuration ScheduledTaskOnceCrossTimezone Configuration ScheduledTaskOnceSynchronizeAcrossTimeZoneDisabled { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskOnceSynchronizeAcrossTimeZoneDisabled @@ -44,6 +46,7 @@ Configuration ScheduledTaskOnceSynchronizeAcrossTimeZoneDisabled Configuration ScheduledTaskOnceSynchronizeAcrossTimeZoneEnabled { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskOnceSynchronizeAcrossTimeZoneEnabled @@ -63,6 +66,7 @@ Configuration ScheduledTaskOnceSynchronizeAcrossTimeZoneEnabled Configuration ScheduledTaskOnceAdd { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskOnceAdd @@ -87,6 +91,7 @@ Configuration ScheduledTaskOnceAdd Configuration ScheduledTaskDailyAdd { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskDailyAdd @@ -109,6 +114,7 @@ Configuration ScheduledTaskDailyAdd Configuration ScheduledTaskDailyIndefinitelyAdd { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskDailyAdd @@ -131,6 +137,7 @@ Configuration ScheduledTaskDailyIndefinitelyAdd Configuration ScheduledTaskWeeklyAdd { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskWeeklyAdd @@ -153,6 +160,7 @@ Configuration ScheduledTaskWeeklyAdd Configuration ScheduledTaskLogonAdd { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskOnceAdd @@ -170,6 +178,7 @@ Configuration ScheduledTaskLogonAdd Configuration ScheduledTaskStartupAdd { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskOnceAdd @@ -187,11 +196,12 @@ Configuration ScheduledTaskStartupAdd Configuration ScheduledTaskExecuteAsAdd { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { $executeAsCredential = New-Object ` -TypeName System.Management.Automation.PSCredential ` - -ArgumentList ($ENV:USERNAME, (ConvertTo-SecureString -String 'Ignore' -AsPlainText -Force)) + -ArgumentList ("$ENV:COMPUTERNAME\$ENV:USERNAME", (ConvertTo-SecureString -String 'Ignore' -AsPlainText -Force)) ScheduledTask ScheduledTaskExecuteAsAdd { @@ -209,11 +219,12 @@ Configuration ScheduledTaskExecuteAsAdd Configuration ScheduledTaskExecuteAsGroupAdd { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { $executeAsCredential = New-Object ` -TypeName System.Management.Automation.PSCredential ` - -ArgumentList ('Users', (ConvertTo-SecureString -String 'Ignore' -AsPlainText -Force)) + -ArgumentList ('BUILTIN\Users', (ConvertTo-SecureString -String 'Ignore' -AsPlainText -Force)) ScheduledTask ScheduledTaskExecuteAsAdd { @@ -231,6 +242,7 @@ Configuration ScheduledTaskExecuteAsGroupAdd Configuration ScheduledTaskOnEventAdd { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskOnEventAdd @@ -250,6 +262,7 @@ Configuration ScheduledTaskOnEventAdd Configuration ScheduledTaskOnceMod { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskOnceMod @@ -269,6 +282,7 @@ Configuration ScheduledTaskOnceMod Configuration ScheduledTaskDailyMod { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskDailyMod @@ -288,6 +302,7 @@ Configuration ScheduledTaskDailyMod Configuration ScheduledTaskDailyIndefinitelyMod { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskDailyMod @@ -307,6 +322,7 @@ Configuration ScheduledTaskDailyIndefinitelyMod Configuration ScheduledTaskWeeklyMod { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskWeeklyMod @@ -326,6 +342,7 @@ Configuration ScheduledTaskWeeklyMod Configuration ScheduledTaskLogonMod { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskLogonMod @@ -343,6 +360,7 @@ Configuration ScheduledTaskLogonMod Configuration ScheduledTaskStartupMod { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskStartupMod @@ -360,6 +378,7 @@ Configuration ScheduledTaskStartupMod Configuration ScheduledTaskExecuteAsMod { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskExecuteAsMod @@ -376,6 +395,7 @@ Configuration ScheduledTaskExecuteAsMod Configuration ScheduledTaskExecuteAsGroupMod { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskLogonMod @@ -392,6 +412,7 @@ Configuration ScheduledTaskExecuteAsGroupMod Configuration ScheduledTaskOnEventMod { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskOnEventMod @@ -411,6 +432,7 @@ Configuration ScheduledTaskOnEventMod Configuration ScheduledTaskOnceDel { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskOnceDel @@ -430,6 +452,7 @@ Configuration ScheduledTaskOnceDel Configuration ScheduledTaskDailyDel { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskDailyDel @@ -450,6 +473,7 @@ Configuration ScheduledTaskDailyDel Configuration ScheduledTaskDailyIndefinitelyDel { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskDailyDel @@ -470,6 +494,7 @@ Configuration ScheduledTaskDailyIndefinitelyDel Configuration ScheduledTaskWeeklyDel { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskWeeklyDel @@ -490,6 +515,7 @@ Configuration ScheduledTaskWeeklyDel Configuration ScheduledTaskLogonDel { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskLogonDel @@ -508,6 +534,7 @@ Configuration ScheduledTaskLogonDel Configuration ScheduledTaskStartupDel { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskStartupDel @@ -526,6 +553,7 @@ Configuration ScheduledTaskStartupDel Configuration ScheduledTaskExecuteAsDel { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskLogonDel @@ -542,6 +570,7 @@ Configuration ScheduledTaskExecuteAsDel Configuration ScheduledTaskExecuteAsGroupDel { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskLogonDel @@ -558,6 +587,7 @@ Configuration ScheduledTaskExecuteAsGroupDel Configuration ScheduledTaskOnEventDel { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskOnEventDel @@ -577,6 +607,7 @@ Configuration ScheduledTaskOnEventDel Configuration ScheduledTaskDisableBuiltIn { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskDisableBuiltIn @@ -591,6 +622,7 @@ Configuration ScheduledTaskDisableBuiltIn Configuration ScheduledTaskRemoveBuiltIn { Import-DscResource -ModuleName ComputerManagementDsc + node 'localhost' { ScheduledTask ScheduledTaskRemoveBuiltIn diff --git a/tests/Integration/DSC_SmbServerConfiguration.Tests.ps1 b/tests/Integration/DSC_SmbServerConfiguration.Tests.ps1 new file mode 100644 index 00000000..11106bb8 --- /dev/null +++ b/tests/Integration/DSC_SmbServerConfiguration.Tests.ps1 @@ -0,0 +1,205 @@ +$script:dscModuleName = 'ComputerManagementDsc' +$script:dscResourceName = 'DSC_SmbServerConfiguration' + +try +{ + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' +} +catch [System.IO.FileNotFoundException] +{ + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' +} + +$script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Integration' + +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') + +$script:CurrentSmbServerConfigBackup = Get-SmbServerConfiguration + +# Begin Testing +try +{ + Describe 'SmbServerConfiguration Integration Tests' { + $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" + . $configFile + + Describe "$($script:dscResourceName)_Integration" { + + $configData = @{ + AllNodes = @( + @{ + NodeName = 'localhost' + IsSingleInstance = 'Yes' + AnnounceComment = 'Test String' + AnnounceServer = $true + AsynchronousCredits = 32 + AuditSmb1Access = $true + AutoDisconnectTimeout = 30 + AutoShareServer = $false + AutoShareWorkstation = $false + CachedOpenLimit = 20 + DurableHandleV2TimeoutInSeconds = 90 + EnableAuthenticateUserSharing = $true + EnableDownlevelTimewarp = $true + EnableForcedLogoff = $false + EnableLeasing = $false + EnableMultiChannel = $false + EnableOplocks = $false + EnableSecuritySignature = $true + EnableSMB1Protocol = $false + EnableSMB2Protocol = $false + EnableStrictNameChecking = $false + EncryptData = $true + IrpStackSize = 20 + KeepAliveTime = 3 + MaxChannelPerSession = 16 + MaxMpxCount = 100 + MaxSessionPerConnection = 16000 + MaxThreadsPerQueue = 15 + MaxWorkItems = 2 + NullSessionPipes = 'TestPipe' + NullSessionShares = 'TestShare' + OplockBreakWait = 30 + PendingClientTimeoutInSeconds = 60 + RejectUnencryptedAccess = $false + RequireSecuritySignature = $true + ServerHidden = $false + Smb2CreditsMax = 2000 + Smb2CreditsMin = 256 + SmbServerNameHardeningLevel = 1 + TreatHostAsStableStorage = $true + ValidateAliasNotCircular = $false + ValidateShareScope = $false + ValidateShareScopeNotAliased = $false + ValidateTargetName = $false + } + ) + } + + It 'Should compile and apply the MOF without throwing' { + { + & "$($script:dscResourceName)_Config" ` + -OutputPath $TestDrive ` + -ConfigurationData $configData + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + Start-DscConfiguration @startDscConfigurationParameters + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { + Get-DscConfiguration -Verbose -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $current = Get-DscConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq "$($script:dscResourceName)_Config" + } + $current.AnnounceComment | Should -Be $configData.AllNodes[0].AnnounceComment + $current.AnnounceServer | Should -Be $configData.AllNodes[0].AnnounceServer + $current.AsynchronousCredits | Should -Be $configData.AllNodes[0].AsynchronousCredits + $current.AuditSmb1Access | Should -Be $configData.AllNodes[0].AuditSmb1Access + $current.AutoDisconnectTimeout | Should -Be $configData.AllNodes[0].AutoDisconnectTimeout + $current.AutoShareServer | Should -Be $configData.AllNodes[0].AutoShareServer + $current.AutoShareWorkstation | Should -Be $configData.AllNodes[0].AutoShareWorkstation + $current.CachedOpenLimit | Should -Be $configData.AllNodes[0].CachedOpenLimit + $current.DurableHandleV2TimeoutInSeconds | Should -Be $configData.AllNodes[0].DurableHandleV2TimeoutInSeconds + $current.EnableAuthenticateUserSharing | Should -Be $configData.AllNodes[0].EnableAuthenticateUserSharing + $current.EnableDownlevelTimewarp | Should -Be $configData.AllNodes[0].EnableDownlevelTimewarp + $current.EnableForcedLogoff | Should -Be $configData.AllNodes[0].EnableForcedLogoff + $current.EnableLeasing | Should -Be $configData.AllNodes[0].EnableLeasing + $current.EnableMultiChannel | Should -Be $configData.AllNodes[0].EnableMultiChannel + $current.EnableOplocks | Should -Be $configData.AllNodes[0].EnableOplocks + $current.EnableSecuritySignature | Should -Be $configData.AllNodes[0].EnableSecuritySignature + $current.EnableSMB1Protocol | Should -Be $configData.AllNodes[0].EnableSMB1Protocol + $current.EnableSMB2Protocol | Should -Be $configData.AllNodes[0].EnableSMB2Protocol + $current.EnableStrictNameChecking | Should -Be $configData.AllNodes[0].EnableStrictNameChecking + $current.EncryptData | Should -Be $configData.AllNodes[0].EncryptData + $current.IrpStackSize | Should -Be $configData.AllNodes[0].IrpStackSize + $current.KeepAliveTime | Should -Be $configData.AllNodes[0].KeepAliveTime + $current.MaxChannelPerSession | Should -Be $configData.AllNodes[0].MaxChannelPerSession + $current.MaxMpxCount | Should -Be $configData.AllNodes[0].MaxMpxCount + $current.MaxSessionPerConnection | Should -Be $configData.AllNodes[0].MaxSessionPerConnection + $current.MaxThreadsPerQueue | Should -Be $configData.AllNodes[0].MaxThreadsPerQueue + $current.MaxWorkItems | Should -Be $configData.AllNodes[0].MaxWorkItems + $current.NullSessionPipes | Should -Be $configData.AllNodes[0].NullSessionPipes + $current.NullSessionShares | Should -Be $configData.AllNodes[0].NullSessionShares + $current.OplockBreakWait | Should -Be $configData.AllNodes[0].OplockBreakWait + $current.PendingClientTimeoutInSeconds | Should -Be $configData.AllNodes[0].PendingClientTimeoutInSeconds + $current.RejectUnencryptedAccess | Should -Be $configData.AllNodes[0].RejectUnencryptedAccess + $current.RequireSecuritySignature | Should -Be $configData.AllNodes[0].RequireSecuritySignature + $current.ServerHidden | Should -Be $configData.AllNodes[0].ServerHidden + $current.Smb2CreditsMax | Should -Be $configData.AllNodes[0].Smb2CreditsMax + $current.Smb2CreditsMin | Should -Be $configData.AllNodes[0].Smb2CreditsMin + $current.SmbServerNameHardeningLevel | Should -Be $configData.AllNodes[0].SmbServerNameHardeningLevel + $current.TreatHostAsStableStorage | Should -Be $configData.AllNodes[0].TreatHostAsStableStorage + $current.ValidateAliasNotCircular | Should -Be $configData.AllNodes[0].ValidateAliasNotCircular + $current.ValidateShareScope | Should -Be $configData.AllNodes[0].ValidateShareScope + $current.ValidateShareScopeNotAliased | Should -Be $configData.AllNodes[0].ValidateShareScopeNotAliased + $current.ValidateTargetName | Should -Be $configData.AllNodes[0].ValidateTargetName + } + } + } +} +finally +{ + Set-SmbServerConfiguration -AnnounceComment $script:CurrentSmbServerConfigBackup.AnnounceComment ` + -AnnounceServer $script:CurrentSmbServerConfigBackup.AnnounceServer ` + -AsynchronousCredits $script:CurrentSmbServerConfigBackup.AsynchronousCredits ` + -AuditSmb1Access $script:CurrentSmbServerConfigBackup.AuditSmb1Access ` + -AutoDisconnectTimeout $script:CurrentSmbServerConfigBackup.AutoDisconnectTimeout ` + -AutoShareServer $script:CurrentSmbServerConfigBackup.AutoShareServer ` + -AutoShareWorkstation $script:CurrentSmbServerConfigBackup.AutoShareWorkstation ` + -CachedOpenLimit $script:CurrentSmbServerConfigBackup.CachedOpenLimit ` + -DurableHandleV2TimeoutInSeconds $script:CurrentSmbServerConfigBackup.DurableHandleV2TimeoutInSeconds ` + -EnableAuthenticateUserSharing $script:CurrentSmbServerConfigBackup.EnableAuthenticateUserSharing ` + -EnableDownlevelTimewarp $script:CurrentSmbServerConfigBackup.EnableDownlevelTimewarp ` + -EnableForcedLogoff $script:CurrentSmbServerConfigBackup.EnableForcedLogoff ` + -EnableLeasing $script:CurrentSmbServerConfigBackup.EnableLeasing ` + -EnableMultiChannel $script:CurrentSmbServerConfigBackup.EnableMultiChannel ` + -EnableOplocks $script:CurrentSmbServerConfigBackup.EnableOplocks ` + -EnableSecuritySignature $script:CurrentSmbServerConfigBackup.EnableSecuritySignature ` + -EnableSMB1Protocol $script:CurrentSmbServerConfigBackup.EnableSMB1Protocol ` + -EnableSMB2Protocol $script:CurrentSmbServerConfigBackup.EnableSMB2Protocol ` + -EnableStrictNameChecking $script:CurrentSmbServerConfigBackup.EnableStrictNameChecking ` + -EncryptData $script:CurrentSmbServerConfigBackup.EncryptData ` + -IrpStackSize $script:CurrentSmbServerConfigBackup.IrpStackSize ` + -KeepAliveTime $script:CurrentSmbServerConfigBackup.KeepAliveTime ` + -MaxChannelPerSession $script:CurrentSmbServerConfigBackup.MaxChannelPerSession ` + -MaxMpxCount $script:CurrentSmbServerConfigBackup.MaxMpxCount ` + -MaxSessionPerConnection $script:CurrentSmbServerConfigBackup.MaxSessionPerConnection ` + -MaxThreadsPerQueue $script:CurrentSmbServerConfigBackup.MaxThreadsPerQueue ` + -MaxWorkItems $script:CurrentSmbServerConfigBackup.MaxWorkItems ` + -NullSessionPipes $script:CurrentSmbServerConfigBackup.NullSessionPipes ` + -NullSessionShares $script:CurrentSmbServerConfigBackup.NullSessionShares ` + -OplockBreakWait $script:CurrentSmbServerConfigBackup.OplockBreakWait ` + -PendingClientTimeoutInSeconds $script:CurrentSmbServerConfigBackup.PendingClientTimeoutInSeconds ` + -RejectUnencryptedAccess $script:CurrentSmbServerConfigBackup.RejectUnencryptedAccess ` + -RequireSecuritySignature $script:CurrentSmbServerConfigBackup.RequireSecuritySignature ` + -ServerHidden $script:CurrentSmbServerConfigBackup.ServerHidden ` + -Smb2CreditsMax $script:CurrentSmbServerConfigBackup.Smb2CreditsMax ` + -Smb2CreditsMin $script:CurrentSmbServerConfigBackup.Smb2CreditsMin ` + -SmbServerNameHardeningLevel $script:CurrentSmbServerConfigBackup.SmbServerNameHardeningLevel ` + -TreatHostAsStableStorage $script:CurrentSmbServerConfigBackup.TreatHostAsStableStorage ` + -ValidateAliasNotCircular $script:CurrentSmbServerConfigBackup.ValidateAliasNotCircular ` + -ValidateShareScope $script:CurrentSmbServerConfigBackup.ValidateShareScope ` + -ValidateShareScopeNotAliased $script:CurrentSmbServerConfigBackup.ValidateShareScopeNotAliased ` + -ValidateTargetName $script:CurrentSmbServerConfigBackup.ValidateTargetName ` + -Confirm:$false + + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} diff --git a/Tests/Integration/MSFT_SmbServerConfiguration.Config.ps1 b/tests/Integration/DSC_SmbServerConfiguration.config.ps1 similarity index 98% rename from Tests/Integration/MSFT_SmbServerConfiguration.Config.ps1 rename to tests/Integration/DSC_SmbServerConfiguration.config.ps1 index a5b689d3..b6596410 100644 --- a/Tests/Integration/MSFT_SmbServerConfiguration.Config.ps1 +++ b/tests/Integration/DSC_SmbServerConfiguration.config.ps1 @@ -1,5 +1,5 @@ # Integration Test Config Template Version: 1.0.0 -configuration MSFT_SmbServerConfiguration_config +Configuration DSC_SmbServerConfiguration_config { Import-DscResource -ModuleName ComputerManagementDsc diff --git a/tests/Integration/DSC_SmbShare.Integration.Tests.ps1 b/tests/Integration/DSC_SmbShare.Integration.Tests.ps1 new file mode 100644 index 00000000..409508b7 --- /dev/null +++ b/tests/Integration/DSC_SmbShare.Integration.Tests.ps1 @@ -0,0 +1,480 @@ +$script:dscModuleName = 'ComputerManagementDsc' +$script:dscResourceName = 'DSC_SmbShare' + +try +{ + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' +} +catch [System.IO.FileNotFoundException] +{ + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' +} + +$script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Integration' + +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') + +# Begin Testing +try +{ + Describe 'SmbShare Integration Tests' { + $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" + . $configFile + + $configurationName = "$($script:dscResourceName)_Prerequisites_Config" + + Context ('When using configuration {0}' -f $configurationName) { + It 'Should compile and apply the MOF without throwing' { + { + $configurationParameters = @{ + OutputPath = $TestDrive + ConfigurationData = $ConfigurationData + } + + & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + Start-DscConfiguration @startDscConfigurationParameters + } | Should -Not -Throw + } + } + + $configurationName = "$($script:dscResourceName)_CreateShare1_Config" + + Context ('When using configuration {0}' -f $configurationName) { + It 'Should compile and apply the MOF without throwing' { + { + $configurationParameters = @{ + OutputPath = $TestDrive + ConfigurationData = $ConfigurationData + } + + & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + Start-DscConfiguration @startDscConfigurationParameters + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq $configurationName ` + -and $_.ResourceId -eq "[SmbShare]Integration_Test" + } + + $resourceCurrentState.Ensure | Should -Be 'Present' + $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.ShareName1 + $resourceCurrentState.Path | Should -Be $ConfigurationData.AllNodes.SharePath1 + $resourceCurrentState.Description | Should -BeNullOrEmpty + $resourceCurrentState.EncryptData | Should -BeFalse + $resourceCurrentState.ConcurrentUserLimit | Should -Be 0 + $resourceCurrentState.Description | Should -BeNullOrEmpty + $resourceCurrentState.CachingMode | Should -Be 'Manual' + $resourceCurrentState.ContinuouslyAvailable | Should -BeFalse + $resourceCurrentState.ShareState | Should -Be 'Online' + $resourceCurrentState.ShareType | Should -Be 'FileSystemDirectory' + $resourceCurrentState.ShadowCopy | Should -BeFalse + $resourceCurrentState.Special | Should -BeFalse + $resourceCurrentState.FullAccess | Should -BeNullOrEmpty + $resourceCurrentState.ChangeAccess | Should -BeNullOrEmpty + $resourceCurrentState.NoAccess | Should -BeNullOrEmpty + + <# + By design of the cmdlet `New-SmbShare`, the Everyone group is + always added when not providing any access permission members + in the configuration. + #> + $resourceCurrentState.ReadAccess | Should -HaveCount 1 + $resourceCurrentState.ReadAccess | Should -Contain 'Everyone' + } + + It 'Should return $true when Test-DscConfiguration is run' { + Test-DscConfiguration -Verbose | Should -BeTrue + } + } + + $configurationName = "$($script:dscResourceName)_CreateShare2_Config" + + Context ('When using configuration {0}' -f $configurationName) { + It 'Should compile and apply the MOF without throwing' { + { + $configurationParameters = @{ + OutputPath = $TestDrive + ConfigurationData = $ConfigurationData + } + + & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + Start-DscConfiguration @startDscConfigurationParameters + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq $configurationName ` + -and $_.ResourceId -eq "[SmbShare]Integration_Test" + } + + $resourceCurrentState.Ensure | Should -Be 'Present' + $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.ShareName2 + $resourceCurrentState.Path | Should -Be $ConfigurationData.AllNodes.SharePath2 + $resourceCurrentState.Description | Should -BeNullOrEmpty + $resourceCurrentState.EncryptData | Should -BeFalse + $resourceCurrentState.ConcurrentUserLimit | Should -Be 0 + $resourceCurrentState.Description | Should -BeNullOrEmpty + $resourceCurrentState.CachingMode | Should -Be 'Manual' + $resourceCurrentState.ContinuouslyAvailable | Should -BeFalse + $resourceCurrentState.ShareState | Should -Be 'Online' + $resourceCurrentState.ShareType | Should -Be 'FileSystemDirectory' + $resourceCurrentState.ShadowCopy | Should -BeFalse + $resourceCurrentState.Special | Should -BeFalse + $resourceCurrentState.FullAccess | Should -BeNullOrEmpty + $resourceCurrentState.ReadAccess | Should -BeNullOrEmpty + $resourceCurrentState.NoAccess | Should -BeNullOrEmpty + + <# + By design of the cmdlet `New-SmbShare`, the Everyone group is + always added when using `ReadAccess = @()` in the configuration. + #> + $resourceCurrentState.ChangeAccess | Should -HaveCount 1 + $resourceCurrentState.ChangeAccess | Should -Contain $ConfigurationData.AllNodes.UserName1 + } + + It 'Should return $true when Test-DscConfiguration is run' { + Test-DscConfiguration -Verbose | Should -BeTrue + } + } + + $configurationName = "$($script:dscResourceName)_UpdateProperties_Config" + + Context ('When using configuration {0}' -f $configurationName) { + It 'Should compile and apply the MOF without throwing' { + { + $configurationParameters = @{ + OutputPath = $TestDrive + ConfigurationData = $ConfigurationData + } + + & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + Start-DscConfiguration @startDscConfigurationParameters + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq $configurationName ` + -and $_.ResourceId -eq "[SmbShare]Integration_Test" + } + + $resourceCurrentState.Ensure | Should -Be 'Present' + $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.ShareName1 + $resourceCurrentState.Path | Should -Be $ConfigurationData.AllNodes.SharePath1 + $resourceCurrentState.Description | Should -Be 'A new description' + #$resourceCurrentState.EncryptData | Should -BeTrue + $resourceCurrentState.ConcurrentUserLimit | Should -Be 20 + #$resourceCurrentState.FolderEnumerationMode | Should -Be 'AccessBased' + #$resourceCurrentState.CachingMode | Should -Be 'None' + #$resourceCurrentState.ContinuouslyAvailable | Should -BeTrue + $resourceCurrentState.ShareState | Should -Be 'Online' + $resourceCurrentState.ShareType | Should -Be 'FileSystemDirectory' + $resourceCurrentState.ShadowCopy | Should -BeFalse + $resourceCurrentState.Special | Should -BeFalse + + $resourceCurrentState.FullAccess | Should -HaveCount 1 + $resourceCurrentState.FullAccess | Should -Contain $ConfigurationData.AllNodes.UserName1 + + $resourceCurrentState.ChangeAccess | Should -HaveCount 1 + $resourceCurrentState.ChangeAccess | Should -Contain $ConfigurationData.AllNodes.UserName2 + + $resourceCurrentState.ReadAccess | Should -HaveCount 1 + $resourceCurrentState.ReadAccess | Should -Contain $ConfigurationData.AllNodes.UserName3 + + $resourceCurrentState.NoAccess | Should -HaveCount 1 + $resourceCurrentState.NoAccess | Should -Contain $ConfigurationData.AllNodes.UserName4 + } + + It 'Should return $true when Test-DscConfiguration is run' { + Test-DscConfiguration -Verbose | Should -BeTrue + } + } + + $configurationName = "$($script:dscResourceName)_RemovePermission_Config" + + Context ('When using configuration {0}' -f $configurationName) { + It 'Should compile and apply the MOF without throwing' { + { + $configurationParameters = @{ + OutputPath = $TestDrive + ConfigurationData = $ConfigurationData + } + + & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + Start-DscConfiguration @startDscConfigurationParameters + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq $configurationName ` + -and $_.ResourceId -eq "[SmbShare]Integration_Test" + } + + $resourceCurrentState.Ensure | Should -Be 'Present' + $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.ShareName1 + $resourceCurrentState.FullAccess | Should -BeNullOrEmpty + $resourceCurrentState.ChangeAccess | Should -BeNullOrEmpty + $resourceCurrentState.NoAccess | Should -BeNullOrEmpty + + $resourceCurrentState.ReadAccess | Should -HaveCount 1 + $resourceCurrentState.ReadAccess | Should -Contain 'Everyone' + } + + It 'Should return $true when Test-DscConfiguration is run' { + Test-DscConfiguration -Verbose | Should -BeTrue + } + } + + $configurationName = "$($script:dscResourceName)_RecreateShare1_Config" + + Context ('When using configuration {0}' -f $configurationName) { + It 'Should compile and apply the MOF without throwing' { + { + $configurationParameters = @{ + OutputPath = $TestDrive + ConfigurationData = $ConfigurationData + } + + & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + Start-DscConfiguration @startDscConfigurationParameters + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq $configurationName ` + -and $_.ResourceId -eq "[SmbShare]Integration_Test" + } + + $resourceCurrentState.Ensure | Should -Be 'Present' + $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.ShareName1 + $resourceCurrentState.Path | Should -Be $ConfigurationData.AllNodes.SharePath2 + } + + It 'Should return $true when Test-DscConfiguration is run' { + Test-DscConfiguration -Verbose | Should -BeTrue + } + } + + + $configurationName = "$($script:dscResourceName)_RemoveShare1_Config" + + Context ('When using configuration {0}' -f $configurationName) { + It 'Should compile and apply the MOF without throwing' { + { + $configurationParameters = @{ + OutputPath = $TestDrive + ConfigurationData = $ConfigurationData + } + + & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + Start-DscConfiguration @startDscConfigurationParameters + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq $configurationName ` + -and $_.ResourceId -eq "[SmbShare]Integration_Test" + } + + $resourceCurrentState.Ensure | Should -Be 'Absent' + $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.ShareName1 + } + + It 'Should return $true when Test-DscConfiguration is run' { + Test-DscConfiguration -Verbose | Should -BeTrue + } + } + + $configurationName = "$($script:dscResourceName)_RemoveShare2_Config" + + Context ('When using configuration {0}' -f $configurationName) { + It 'Should compile and apply the MOF without throwing' { + { + $configurationParameters = @{ + OutputPath = $TestDrive + ConfigurationData = $ConfigurationData + } + + & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + Start-DscConfiguration @startDscConfigurationParameters + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq $configurationName ` + -and $_.ResourceId -eq "[SmbShare]Integration_Test" + } + + $resourceCurrentState.Ensure | Should -Be 'Absent' + $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.ShareName2 + } + + It 'Should return $true when Test-DscConfiguration is run' { + Test-DscConfiguration -Verbose | Should -BeTrue + } + } + + $configurationName = "$($script:dscResourceName)_Cleanup_Config" + + Context ('When using configuration {0}' -f $configurationName) { + It 'Should compile and apply the MOF without throwing' { + { + $configurationParameters = @{ + OutputPath = $TestDrive + ConfigurationData = $ConfigurationData + } + + & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + Start-DscConfiguration @startDscConfigurationParameters + } | Should -Not -Throw + } + } + } +} +finally +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} diff --git a/Tests/Integration/MSFT_SmbShare.config.ps1 b/tests/Integration/DSC_SmbShare.config.ps1 similarity index 94% rename from Tests/Integration/MSFT_SmbShare.config.ps1 rename to tests/Integration/DSC_SmbShare.config.ps1 index a3a359ff..1b06f48f 100644 --- a/Tests/Integration/MSFT_SmbShare.config.ps1 +++ b/tests/Integration/DSC_SmbShare.config.ps1 @@ -6,7 +6,7 @@ $configFile = [System.IO.Path]::ChangeExtension($MyInvocation.MyCommand.Path, 'j if (Test-Path -Path $configFile) { <# - Allows reading the configuration data from a JSON file + Allows reading the Configuration data from a JSON file for real testing scenarios outside of the CI. #> $ConfigurationData = Get-Content -Path $configFile | ConvertFrom-Json @@ -40,7 +40,7 @@ else Creates the prerequisites for the other tests. This creates a folder that will be shared. #> -Configuration MSFT_SmbShare_Prerequisites_Config +Configuration DSC_SmbShare_Prerequisites_Config { Import-DscResource -ModuleName 'PSDesiredStateConfiguration' @@ -114,7 +114,7 @@ Configuration MSFT_SmbShare_Prerequisites_Config .SYNOPSIS Create the SMB share with default values, and no permissions. #> -Configuration MSFT_SmbShare_CreateShare1_Config +Configuration DSC_SmbShare_CreateShare1_Config { Import-DscResource -ModuleName 'ComputerManagementDsc' @@ -132,7 +132,7 @@ Configuration MSFT_SmbShare_CreateShare1_Config .SYNOPSIS Create the SMB share with default values, and no permissions. #> -Configuration MSFT_SmbShare_CreateShare2_Config +Configuration DSC_SmbShare_CreateShare2_Config { Import-DscResource -ModuleName 'ComputerManagementDsc' @@ -166,7 +166,7 @@ Configuration MSFT_SmbShare_CreateShare2_Config existing file share as the file share is not a cluster share. #> -Configuration MSFT_SmbShare_UpdateProperties_Config +Configuration DSC_SmbShare_UpdateProperties_Config { Import-DscResource -ModuleName 'ComputerManagementDsc' @@ -194,7 +194,7 @@ Configuration MSFT_SmbShare_UpdateProperties_Config .SYNOPSIS Remove permission, and no other properties should be changed. #> -Configuration MSFT_SmbShare_RemovePermission_Config +Configuration DSC_SmbShare_RemovePermission_Config { Import-DscResource -ModuleName 'ComputerManagementDsc' @@ -216,7 +216,7 @@ Configuration MSFT_SmbShare_RemovePermission_Config .SYNOPSIS Drop and recreate share 1 on a new path. #> -Configuration MSFT_SmbShare_RecreateShare1_Config +Configuration DSC_SmbShare_RecreateShare1_Config { Import-DscResource -ModuleName 'ComputerManagementDsc' @@ -237,7 +237,7 @@ Configuration MSFT_SmbShare_RecreateShare1_Config .SYNOPSIS Remove the share 1. #> -Configuration MSFT_SmbShare_RemoveShare1_Config +Configuration DSC_SmbShare_RemoveShare1_Config { Import-DscResource -ModuleName 'ComputerManagementDsc' @@ -256,7 +256,7 @@ Configuration MSFT_SmbShare_RemoveShare1_Config .SYNOPSIS Remove the share 2. #> -Configuration MSFT_SmbShare_RemoveShare2_Config +Configuration DSC_SmbShare_RemoveShare2_Config { Import-DscResource -ModuleName 'ComputerManagementDsc' @@ -275,7 +275,7 @@ Configuration MSFT_SmbShare_RemoveShare2_Config .SYNOPSIS Clean up the prerequisites. #> -Configuration MSFT_SmbShare_Cleanup_Config +Configuration DSC_SmbShare_Cleanup_Config { Import-DscResource -ModuleName 'PSDesiredStateConfiguration' diff --git a/tests/Integration/DSC_SystemLocale.Integration.Tests.ps1 b/tests/Integration/DSC_SystemLocale.Integration.Tests.ps1 new file mode 100644 index 00000000..ef7ae931 --- /dev/null +++ b/tests/Integration/DSC_SystemLocale.Integration.Tests.ps1 @@ -0,0 +1,86 @@ +$script:dscModuleName = 'ComputerManagementDsc' +$script:dscResourceName = 'DSC_SystemLocale' + +try +{ + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' +} +catch [System.IO.FileNotFoundException] +{ + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' +} + +$script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Integration' + +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') + +# Store the test machine system locale +$currentSystemLocale = (Get-WinSystemLocale).Name + +# Change the current system locale so that a complete test occurs. +Set-WinSystemLocale -SystemLocale 'kl-GL' + +# Begin Testing +try +{ + Describe 'SystemLocale Integration Tests' { + $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1" + . $configFile -Verbose -ErrorAction Stop + + Describe "$($script:DSCResourceName)_Integration" { + Context 'When settting System Locale to fr-FR' { + $configData = @{ + AllNodes = @( + @{ + NodeName = 'localhost' + SystemLocale = 'fr-FR' + IsSingleInstance = 'Yes' + } + ) + } + + It 'Should compile and apply the MOF without throwing' { + { + & "$($script:DSCResourceName)_Config" ` + -OutputPath $TestDrive ` + -ConfigurationData $configData + + Start-DscConfiguration ` + -Path $TestDrive ` + -ComputerName localhost ` + -Wait ` + -Verbose ` + -Force ` + -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $current = Get-DscConfiguration | Where-Object { + $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" + } + <# + A reboot would need to occur before this node can be bought into alignment. + Therefore a test for the new SystemLocale can not be automated. + #> + $current.IsSingleInstance | Should -Be $configData.AllNodes[0].IsSingleInstance + } + } + } + } +} +finally +{ + # Restore the test machine system locale + Set-WinSystemLocale -SystemLocale $currentSystemLocale + + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} diff --git a/Tests/Integration/MSFT_SystemLocale.config.ps1 b/tests/Integration/DSC_SystemLocale.config.ps1 similarity index 85% rename from Tests/Integration/MSFT_SystemLocale.config.ps1 rename to tests/Integration/DSC_SystemLocale.config.ps1 index 2e861bf0..b322c4e2 100644 --- a/Tests/Integration/MSFT_SystemLocale.config.ps1 +++ b/tests/Integration/DSC_SystemLocale.config.ps1 @@ -1,4 +1,4 @@ -configuration MSFT_SystemLocale_Config { +Configuration DSC_SystemLocale_Config { Import-DscResource -ModuleName ComputerManagementDsc node localhost { diff --git a/tests/Integration/DSC_TimeZone.Integration.Tests.ps1 b/tests/Integration/DSC_TimeZone.Integration.Tests.ps1 new file mode 100644 index 00000000..fe6e9d93 --- /dev/null +++ b/tests/Integration/DSC_TimeZone.Integration.Tests.ps1 @@ -0,0 +1,82 @@ +$script:dscModuleName = 'ComputerManagementDsc' +$script:dscResourceName = 'DSC_TimeZone' + +try +{ + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' +} +catch [System.IO.FileNotFoundException] +{ + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' +} + +$script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Integration' + +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') + +# Store the test machine timezone +$currentTimeZone = & tzutil.exe /g + +# Change the current timezone so that a complete test occurs. +tzutil.exe /s 'Eastern Standard Time' + +# Begin Testing +try +{ + Describe 'TimeZone Integration Tests' { + #region Integration Tests + $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" + . $configFile -Verbose -ErrorAction Stop + + Describe "$($script:dscResourceName)_Integration" { + $configData = @{ + AllNodes = @( + @{ + NodeName = 'localhost' + TimeZone = 'Pacific Standard Time' + IsSingleInstance = 'Yes' + } + ) + } + + It 'Should compile and apply the MOF without throwing' { + { + & "$($script:dscResourceName)_Config" ` + -OutputPath $TestDrive ` + -ConfigurationData $configData + + Start-DscConfiguration ` + -Path $TestDrive ` + -ComputerName localhost ` + -Wait ` + -Verbose ` + -Force ` + -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should have set the configuration and all the parameters should match' { + $current = Get-DscConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq "$($script:dscResourceName)_Config" + } + $current.TimeZone | Should -Be $configData.AllNodes[0].TimeZone + $current.IsSingleInstance | Should -Be $configData.AllNodes[0].IsSingleInstance + } + } + } +} +finally +{ + # Restore the test machine timezone + & tzutil.exe /s $CurrentTimeZone + + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} diff --git a/Tests/Integration/MSFT_TimeZone.config.ps1 b/tests/Integration/DSC_TimeZone.config.ps1 similarity index 62% rename from Tests/Integration/MSFT_TimeZone.config.ps1 rename to tests/Integration/DSC_TimeZone.config.ps1 index ff6d9bd0..f5e00075 100644 --- a/Tests/Integration/MSFT_TimeZone.config.ps1 +++ b/tests/Integration/DSC_TimeZone.config.ps1 @@ -1,8 +1,10 @@ -configuration MSFT_TimeZone_Config { +Configuration DSC_TimeZone_Config { Import-DscResource -ModuleName ComputerManagementDsc - node localhost { - TimeZone Integration_Test { + node localhost + { + TimeZone Integration_Test + { TimeZone = $Node.TimeZone IsSingleInstance = $Node.IsSingleInstance } diff --git a/tests/Integration/DSC_VirtualMemory.Integration.Tests.ps1 b/tests/Integration/DSC_VirtualMemory.Integration.Tests.ps1 new file mode 100644 index 00000000..1dd75844 --- /dev/null +++ b/tests/Integration/DSC_VirtualMemory.Integration.Tests.ps1 @@ -0,0 +1,123 @@ +$script:dscModuleName = 'ComputerManagementDsc' +$script:dscResourceName = 'DSC_VirtualMemory' + +try +{ + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' +} +catch [System.IO.FileNotFoundException] +{ + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' +} + +$script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Integration' + +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') + +# Begin Testing +try +{ + Describe 'VirtualMemory Integration Tests' { + $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" + . $configFile + + Describe "$($script:dscResourceName)_Integration" { + + Context 'Set page file to automatically managed' { + $CurrentConfig = 'setToAuto' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file without error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue + } + } + + Context 'Set page file to custom size' { + $CurrentConfig = 'setToCustom' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file without error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue + } + } + + Context 'Set page file to system managed' { + $CurrentConfig = 'setToSystemManaged' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file without error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue + } + } + + Context 'Set page file to none' { + $CurrentConfig = 'setToNone' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file without error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue + } + } + } + } +} +finally +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} diff --git a/Tests/Integration/MSFT_VirtualMemory.Config.ps1 b/tests/Integration/DSC_VirtualMemory.config.ps1 similarity index 70% rename from Tests/Integration/MSFT_VirtualMemory.Config.ps1 rename to tests/Integration/DSC_VirtualMemory.config.ps1 index f1c00c4e..5671e2ff 100644 --- a/Tests/Integration/MSFT_VirtualMemory.Config.ps1 +++ b/tests/Integration/DSC_VirtualMemory.config.ps1 @@ -1,10 +1,11 @@ Configuration setToAuto { Import-DscResource -ModuleName ComputerManagementDsc - node "localhost" { + node 'localhost' + { VirtualMemory vMem { - Type = 'AutoManagePagingFile' + Type = 'AutoManagePagingFile' Drive = 'C' } } @@ -13,11 +14,13 @@ Configuration setToAuto Configuration setToCustom { Import-DscResource -ModuleName ComputerManagementDsc - node "localhost" { + + node 'localhost' + { VirtualMemory vMem { - Type = 'CustomSize' - Drive = 'C' + Type = 'CustomSize' + Drive = 'C' InitialSize = 128 MaximumSize = 1024 } @@ -27,10 +30,12 @@ Configuration setToCustom Configuration setToSystemManaged { Import-DscResource -ModuleName ComputerManagementDsc - node "localhost" { + + node 'localhost' + { VirtualMemory vMem { - Type = 'SystemManagedSize' + Type = 'SystemManagedSize' Drive = 'C' } } @@ -39,10 +44,12 @@ Configuration setToSystemManaged Configuration setToNone { Import-DscResource -ModuleName ComputerManagementDsc - node "localhost" { + + node 'localhost' + { VirtualMemory vMem { - Type = 'NoPagingFile' + Type = 'NoPagingFile' Drive = 'C' } } diff --git a/tests/Integration/DSC_WindowsCapability.Integration.Tests.ps1 b/tests/Integration/DSC_WindowsCapability.Integration.Tests.ps1 new file mode 100644 index 00000000..5252dd70 --- /dev/null +++ b/tests/Integration/DSC_WindowsCapability.Integration.Tests.ps1 @@ -0,0 +1,145 @@ +$script:dscModuleName = 'ComputerManagementDsc' +$script:dscResourceName = 'DSC_WindowsCapability' + +try +{ + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' +} +catch [System.IO.FileNotFoundException] +{ + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' +} + +$script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Integration' + +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') + +# Begin Testing +try +{ + Describe 'WindowsCapability Integration Tests' { + # Ensure that the tests can be performed on this computer + $sourceAvailable = Test-WindowsCapabilitySourceAvailable -Verbose + + Describe 'Windows capability source files' { + It 'Should be available' { + if (-not $sourceAvailable) + { + Set-ItResult -Inconclusive -Because 'Windows capability source files are not available' + } + } + } + + if (-not $sourceAvailable) + { + break + } + + $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).Config.ps1" + . $configFile + + Describe "$($script:dscResourceName)_Integration" { + Context 'When adding a Windows Capability' { + $configData = @{ + AllNodes = @( + @{ + NodeName = 'localhost' + Name = 'XPS.Viewer~~~~0.0.1.0' + LogLevel = 'Errors' + LogPath = Join-Path -Path $ENV:Temp -ChildPath 'Logfile.log' + Ensure = 'Present' + } + ) + } + + It 'Should compile and apply the MOF without throwing' { + { + & "$($script:dscResourceName)_Config" ` + -OutputPath $TestDrive ` + -ConfigurationData $configData + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + Start-DscConfiguration @startDscConfigurationParameters + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { + Get-DscConfiguration -Verbose -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $current = Get-DscConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq "$($script:dscResourceName)_Config" + } + $current.Name | Should -Be $configData.AllNodes[0].Name + $current.Ensure | Should -Be $configData.AllNodes[0].Ensure + } + } + + Context 'When removing a Windows Capability' { + $configData = @{ + AllNodes = @( + @{ + NodeName = 'localhost' + Name = 'XPS.Viewer~~~~0.0.1.0' + LogLevel = 'Errors' + LogPath = Join-Path -Path $ENV:Temp -ChildPath 'Logfile.log' + Ensure = 'Absent' + } + ) + } + + It 'Should compile and apply the MOF without throwing' { + { + & "$($script:dscResourceName)_Config" ` + -OutputPath $TestDrive ` + -ConfigurationData $configData + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + Start-DscConfiguration @startDscConfigurationParameters + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { + Get-DscConfiguration -Verbose -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $current = Get-DscConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq "$($script:dscResourceName)_Config" + } + $current.Name | Should -Be $configData.AllNodes[0].Name + $current.Ensure | Should -Be $configData.AllNodes[0].Ensure + } + } + } + } +} +finally +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} diff --git a/Tests/Integration/MSFT_WindowsCapability.Config.ps1 b/tests/Integration/DSC_WindowsCapability.config.ps1 similarity index 80% rename from Tests/Integration/MSFT_WindowsCapability.Config.ps1 rename to tests/Integration/DSC_WindowsCapability.config.ps1 index 1e04ef4e..1083ef78 100644 --- a/Tests/Integration/MSFT_WindowsCapability.Config.ps1 +++ b/tests/Integration/DSC_WindowsCapability.config.ps1 @@ -1,9 +1,10 @@ # Integration Test Config Template Version: 1.0.0 -configuration MSFT_WindowsCapability_Config +Configuration DSC_WindowsCapability_Config { Import-DscResource -ModuleName ComputerManagementDsc - node $AllNodes.NodeName { + node $AllNodes.NodeName + { WindowsCapability TestInstallation { Name = $Node.Name diff --git a/tests/Integration/DSC_WindowsEventLog.Integration.Tests.ps1 b/tests/Integration/DSC_WindowsEventLog.Integration.Tests.ps1 new file mode 100644 index 00000000..2efe7e87 --- /dev/null +++ b/tests/Integration/DSC_WindowsEventLog.Integration.Tests.ps1 @@ -0,0 +1,295 @@ +$script:dscModuleName = 'ComputerManagementDsc' +$script:dscResourceName = 'DSC_WindowsEventLog' + +try +{ + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' +} +catch [System.IO.FileNotFoundException] +{ + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' +} + +$script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Integration' + +Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') + +# Begin Testing +try +{ + Describe 'WindowsEventLog Integration Tests' { + $configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" + . $configFile + + Describe "$($script:dscResourceName)_Integration" { + + Context 'Set Windows Event Log to Logmode Retain' { + $CurrentConfig = 'DSC_WindowsEventLog_RetainSize' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file without error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue + } + } + + Context 'Set Windows Event Log to Logmode AutoBackup with LogRetentionDays of 30 days' { + $CurrentConfig = 'DSC_WindowsEventLog_AutobackupLogRetention' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file without error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue + } + } + + Context 'Set Windows Event Log to Logmode Circular, MaximumSizeInBytes 20971520, LogFilePath C:\temp\Application.evtx' { + $CurrentConfig = 'DSC_WindowsEventLog_CircularLogPath' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file without error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue + } + } + + Context 'Set Windows Event Log to Default' { + $CurrentConfig = 'DSC_WindowsEventLog_Default' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file without error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue + } + } + + Context 'Enable a Logfile other than Application Eventlog' { + $CurrentConfig = 'DSC_WindowsEventLog_EnableLog' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file without error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue + } + } + + Context 'Disable a Logfile other than Application Windows Event Log' { + $CurrentConfig = 'DSC_WindowsEventLog_DisableLog' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file without error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue + } + } + + Context 'Set Eventlog to Logmode Circular with a SecurityDescriptor' { + $CurrentConfig = 'DSC_WindowsEventLog_CircularSecurityDescriptor' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file without error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue + } + } + + Context 'Enable a Logfile other than Application Windows Event Log with Retention' { + $CurrentConfig = 'DSC_WindowsEventLog_EnableBackupLog' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should not apply the MOF' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should return a incompliant state' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeFalse + } + } + + Context 'Disable a Logfile other than Application Eventlog with retention' { + $CurrentConfig = 'DSC_WindowsEventLog_DisableBackupLog' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file without error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue + } + } + + Context 'Set Windows Event Log back to the default configuration' { + $CurrentConfig = 'DSC_WindowsEventLog_Default' + $ConfigDir = (Join-Path -Path $TestDrive -ChildPath $CurrentConfig) + $ConfigMof = (Join-Path -Path $ConfigDir -ChildPath 'localhost.mof') + + It 'Should compile a MOF file without error' { + { + . $CurrentConfig -OutputPath $ConfigDir + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should apply the MOF correctly' { + { + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force + } | Should -Not -Throw + } + + It 'Should return a compliant state after being applied' { + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof -Verbose).InDesiredState | Should -BeTrue + } + } + } + } +} +finally +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} diff --git a/Tests/Integration/MSFT_WindowsEventLog.config.ps1 b/tests/Integration/DSC_WindowsEventLog.config.ps1 similarity index 73% rename from Tests/Integration/MSFT_WindowsEventLog.config.ps1 rename to tests/Integration/DSC_WindowsEventLog.config.ps1 index 82c19df0..6e090a97 100644 --- a/Tests/Integration/MSFT_WindowsEventLog.config.ps1 +++ b/tests/Integration/DSC_WindowsEventLog.config.ps1 @@ -1,5 +1,5 @@ # Integration Test Config Template Version: 1.0.0 -configuration MSFT_WindowsEventLog_Default +Configuration DSC_WindowsEventLog_Default { Import-DscResource -ModuleName ComputerManagementDsc node 'localhost' @@ -16,7 +16,7 @@ configuration MSFT_WindowsEventLog_Default } } -configuration MSFT_WindowsEventLog_RetainSize +Configuration DSC_WindowsEventLog_RetainSize { Import-DscResource -ModuleName ComputerManagementDsc node 'localhost' @@ -31,22 +31,22 @@ configuration MSFT_WindowsEventLog_RetainSize } } -configuration MSFT_WindowsEventLog_AutobackupLogRetention +Configuration DSC_WindowsEventLog_AutobackupLogRetention { Import-DscResource -ModuleName ComputerManagementDsc node 'localhost' { WindowsEventLog Integration_Test { - LogName = 'Application' - IsEnabled = $true - LogMode = 'AutoBackup' - LogRetentionDays = '30' + LogName = 'Application' + IsEnabled = $true + LogMode = 'AutoBackup' + LogRetentionDays = '30' } } } -configuration MSFT_WindowsEventLog_CircularLogPath +Configuration DSC_WindowsEventLog_CircularLogPath { Import-DscResource -ModuleName ComputerManagementDsc node 'localhost' @@ -62,7 +62,7 @@ configuration MSFT_WindowsEventLog_CircularLogPath } } -configuration MSFT_WindowsEventLog_EnableLog +Configuration DSC_WindowsEventLog_EnableLog { Import-DscResource -ModuleName ComputerManagementDsc node 'localhost' @@ -77,20 +77,20 @@ configuration MSFT_WindowsEventLog_EnableLog } } -configuration MSFT_WindowsEventLog_DisableLog +Configuration DSC_WindowsEventLog_DisableLog { Import-DscResource -ModuleName ComputerManagementDsc node 'localhost' { WindowsEventLog Integration_Test { - LogName = 'Microsoft-Windows-CAPI2/Operational' - IsEnabled = $false + LogName = 'Microsoft-Windows-CAPI2/Operational' + IsEnabled = $false } } } -configuration MSFT_WindowsEventLog_CircularSecurityDescriptor +Configuration DSC_WindowsEventLog_CircularSecurityDescriptor { Import-DscResource -ModuleName ComputerManagementDsc node 'localhost' @@ -106,30 +106,30 @@ configuration MSFT_WindowsEventLog_CircularSecurityDescriptor } } -configuration MSFT_WindowsEventLog_EnableBackupLog +Configuration DSC_WindowsEventLog_EnableBackupLog { Import-DscResource -ModuleName ComputerManagementDsc node 'localhost' { WindowsEventLog Integration_Test { - LogName = 'Microsoft-Windows-Backup' - IsEnabled = $true - LogMode = 'AutoBackup' - LogRetentionDays = '30' + LogName = 'Microsoft-Windows-Backup' + IsEnabled = $true + LogMode = 'AutoBackup' + LogRetentionDays = '30' } } } -configuration MSFT_WindowsEventLog_DisableBackupLog +Configuration DSC_WindowsEventLog_DisableBackupLog { Import-DscResource -ModuleName ComputerManagementDsc node 'localhost' { WindowsEventLog Integration_Test { - LogName = 'Microsoft-Windows-Backup' - IsEnabled = $false + LogName = 'Microsoft-Windows-Backup' + IsEnabled = $false } } } diff --git a/Tests/TestHelpers/CommonTestHelper.psm1 b/tests/TestHelpers/CommonTestHelper.psm1 similarity index 79% rename from Tests/TestHelpers/CommonTestHelper.psm1 rename to tests/TestHelpers/CommonTestHelper.psm1 index a99e3db7..64600a49 100644 --- a/Tests/TestHelpers/CommonTestHelper.psm1 +++ b/tests/TestHelpers/CommonTestHelper.psm1 @@ -81,6 +81,33 @@ function Get-InvalidOperationRecord return New-Object @newObjectParams } +<# + .SYNOPSIS + Test if the source files are available for Windows Capability. + If the source files are not available Get-WindowsCapability + will throw an exception. +#> +function Test-WindowsCapabilitySourceAvailable +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param () + + $sourceAvailable = $true + + try + { + Get-WindowsCapability -Online -ErrorAction Stop + } + catch + { + $sourceAvailable = $false + } + + return $sourceAvailable +} + Export-ModuleMember -Function ` Get-InvalidArgumentRecord, ` - Get-InvalidOperationRecord + Get-InvalidOperationRecord, ` + Test-WindowsCapabilitySourceAvailable diff --git a/tests/Unit/ComputerManagementDsc.Common.Tests.ps1 b/tests/Unit/ComputerManagementDsc.Common.Tests.ps1 new file mode 100644 index 00000000..3a16ab5c --- /dev/null +++ b/tests/Unit/ComputerManagementDsc.Common.Tests.ps1 @@ -0,0 +1,1780 @@ +#region HEADER +$script:projectPath = "$PSScriptRoot\..\.." | Convert-Path +$script:projectName = (Get-ChildItem -Path "$script:projectPath\*\*.psd1" | Where-Object -FilterScript { + ($_.Directory.Name -match 'source|src' -or $_.Directory.Name -eq $_.BaseName) -and + $(try + { + Test-ModuleManifest -Path $_.FullName -ErrorAction Stop + } + catch + { + $false + }) + }).BaseName + +$script:parentModule = Get-Module -Name $script:projectName -ListAvailable | Select-Object -First 1 +$script:subModulesFolder = Join-Path -Path $script:parentModule.ModuleBase -ChildPath 'Modules' +Remove-Module -Name $script:parentModule -Force -ErrorAction 'SilentlyContinue' + +$script:subModuleName = (Split-Path -Path $PSCommandPath -Leaf) -replace '\.Tests.ps1' +$script:subModuleFile = Join-Path -Path $script:subModulesFolder -ChildPath "$($script:subModuleName)/$($script:subModuleName).psm1" + +Import-Module $script:subModuleFile -Force -ErrorAction Stop +#endregion HEADER + +InModuleScope $script:subModuleName { + Describe 'ComputerManagementDsc.Common\Remove-CommonParameter' { + $removeCommonParameter = @{ + Parameter1 = 'value1' + Parameter2 = 'value2' + Verbose = $true + Debug = $true + ErrorAction = 'Stop' + WarningAction = 'Stop' + InformationAction = 'Stop' + ErrorVariable = 'errorVariable' + WarningVariable = 'warningVariable' + OutVariable = 'outVariable' + OutBuffer = 'outBuffer' + PipelineVariable = 'pipelineVariable' + InformationVariable = 'informationVariable' + WhatIf = $true + Confirm = $true + UseTransaction = $true + } + + Context 'Hashtable contains all common parameters' { + It 'Should not throw exception' { + { $script:result = Remove-CommonParameter -Hashtable $removeCommonParameter -Verbose } | Should -Not -Throw + } + + It 'Should have retained parameters in the hashtable' { + $script:result.Contains('Parameter1') | Should -BeTrue + $script:result.Contains('Parameter2') | Should -BeTrue + } + + It 'Should have removed the common parameters from the hashtable' { + $script:result.Contains('Verbose') | Should -BeFalse + $script:result.Contains('Debug') | Should -BeFalse + $script:result.Contains('ErrorAction') | Should -BeFalse + $script:result.Contains('WarningAction') | Should -BeFalse + $script:result.Contains('InformationAction') | Should -BeFalse + $script:result.Contains('ErrorVariable') | Should -BeFalse + $script:result.Contains('WarningVariable') | Should -BeFalse + $script:result.Contains('OutVariable') | Should -BeFalse + $script:result.Contains('OutBuffer') | Should -BeFalse + $script:result.Contains('PipelineVariable') | Should -BeFalse + $script:result.Contains('InformationVariable') | Should -BeFalse + $script:result.Contains('WhatIf') | Should -BeFalse + $script:result.Contains('Confirm') | Should -BeFalse + $script:result.Contains('UseTransaction') | Should -BeFalse + } + } + } + + Describe 'ComputerManagementDsc.Common\Test-DscParameterState' { + $verbose = $true + + Context 'When testing single values' { + $currentValues = @{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3' + } + } + + Context 'When all values match' { + $desiredValues = [PSObject] @{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3' + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $true' { + $script:result | Should -Be $true + } + } + + Context 'When a string is mismatched' { + $desiredValues = [PSObject] @{ + String = 'different string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3' + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When a boolean is mismatched' { + $desiredValues = [PSObject] @{ + String = 'a string' + Bool = $false + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3' + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When an int is mismatched' { + $desiredValues = [PSObject] @{ + String = 'a string' + Bool = $true + Int = 1 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3' + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When a type is mismatched' { + $desiredValues = [PSObject] @{ + String = 'a string' + Bool = $true + Int = '99' + Array = 'a', 'b', 'c' + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When a type is mismatched but TurnOffTypeChecking is used' { + $desiredValues = [PSObject] @{ + String = 'a string' + Bool = $true + Int = '99' + Array = 'a', 'b', 'c' + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -TurnOffTypeChecking ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $true' { + $script:result | Should -Be $true + } + } + + Context 'When a value is mismatched but valuesToCheck is used to exclude them' { + $desiredValues = [PSObject] @{ + String = 'a string' + Bool = $false + Int = 1 + Array = @( 'a', 'b' ) + } + + $valuesToCheck = @( + 'String' + ) + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -ValuesToCheck $valuesToCheck ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $true' { + $script:result | Should -Be $true + } + } + } + + Context 'When testing array values' { + BeforeAll { + $currentValues = @{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c', 1 + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3' + } + } + } + + Context 'When array is missing a value' { + $desiredValues = [PSObject]@{ + String = 'a string' + Bool = $true + Int = 1 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3' + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When array has an additional value' { + $desiredValues = [PSObject] @{ + String = 'a string' + Bool = $true + Int = 1 + Array = 'a', 'b', 'c', 1, 2 + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When array has a different value' { + $desiredValues = [PSObject] @{ + String = 'a string' + Bool = $true + Int = 1 + Array = 'a', 'x', 'c', 1 + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When array has different order' { + $desiredValues = [PSObject] @{ + String = 'a string' + Bool = $true + Int = 1 + Array = 'c', 'b', 'a', 1 + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When array has different order but SortArrayValues is used' { + $desiredValues = [PSObject] @{ + String = 'a string' + Bool = $true + Int = 1 + Array = 'c', 'b', 'a', 1 + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -SortArrayValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + + Context 'When array has a value with a different type' { + $desiredValues = [PSObject] @{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c', '1' + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When array has a value with a different type but TurnOffTypeChecking is used' { + $desiredValues = [PSObject] @{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c', '1' + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -TurnOffTypeChecking ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $true' { + $script:result | Should -Be $true + } + } + + Context 'When both arrays are empty' { + $currentValues = @{ + String = 'a string' + Bool = $true + Int = 99 + Array = @() + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = @() + } + } + + $desiredValues = [PSObject]@{ + String = 'a string' + Bool = $true + Int = 99 + Array = @() + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = @() + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $true' { + $script:result | Should -Be $true + } + } + } + + Context 'When testing hashtables' { + $currentValues = @{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3', 99 + } + } + + Context 'When hashtable is missing a value' { + $desiredValues = [PSObject]@{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3' + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When hashtable has an additional value' { + $desiredValues = [PSObject]@{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3', 99, 100 + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When hashtable has a different value' { + $desiredValues = [PSObject]@{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'xx', 'v2', 'v3', 99 + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When an array in hashtable has different order' { + $desiredValues = [PSObject]@{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v3', 'v2', 'v1', 99 + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When an array in hashtable has different order but SortArrayValues is used' { + $desiredValues = [PSObject]@{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v3', 'v2', 'v1', 99 + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -SortArrayValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $true' { + $script:result | Should -Be $true + } + } + + + Context 'When hashtable has a value with a different type' { + $desiredValues = [PSObject]@{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3', '99' + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When hashtable has a value with a different type but TurnOffTypeChecking is used' { + $desiredValues = [PSObject]@{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3', 99 + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -TurnOffTypeChecking ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $true' { + $script:result | Should -Be $true + } + } + } + + Context 'When testing CimInstances / hashtables' { + $currentValues = @{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3', 99 + } + CimInstances = [CimInstance[]](ConvertTo-CimInstance -Hashtable @{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a, b, c' + }) + } + + Context 'When everything matches' { + $desiredValues = [PSObject]@{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3', 99 + } + CimInstances = [CimInstance[]](ConvertTo-CimInstance -Hashtable @{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a, b, c' + }) + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $true' { + $script:result | Should -Be $true + } + } + + Context 'When CimInstances missing a value in the desired state (not recognized)' { + $desiredValues = [PSObject]@{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3', 99 + } + CimInstances = @{ + String = 'a string' + Bool = $true + Array = 'a, b, c' + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $true' { + $script:result | Should -Be $true + } + } + + Context 'When CimInstances missing a value in the desired state (recognized using ReverseCheck)' { + $desiredValues = [PSObject]@{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3', 99 + } + CimInstances = @{ + String = 'a string' + Bool = $true + Array = 'a, b, c' + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -ReverseCheck ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When CimInstances have an additional value' { + $desiredValues = [PSObject]@{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3', 99 + } + CimInstances = @{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a, b, c' + Test = 'Some string' + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When CimInstances have a different value' { + $desiredValues = [PSObject]@{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3', 99 + } + CimInstances = @{ + String = 'some other string' + Bool = $true + Int = 99 + Array = 'a, b, c' + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When CimInstances have a value with a different type' { + $desiredValues = [PSObject]@{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3', 99 + } + CimInstances = @{ + String = 'a string' + Bool = $true + Int = '99' + Array = 'a, b, c' + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + + Context 'When CimInstances have a value with a different type but TurnOffTypeChecking is used' { + $desiredValues = [PSObject]@{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c' + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3', 99 + } + CimInstances = @{ + String = 'a string' + Bool = $true + Int = '99' + Array = 'a, b, c' + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -TurnOffTypeChecking ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $true' { + $script:result | Should -Be $true + } + } + } + + Context 'When reverse checking' { + $currentValues = @{ + String = 'a string' + Bool = $true + Int = 99 + Array = 'a', 'b', 'c', 1 + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3' + } + } + + Context 'When even if missing property in the desired state' { + $desiredValues = [PSObject] @{ + Array = 'a', 'b', 'c', 1 + Hashtable = @{ + k1 = 'Test' + k2 = 123 + k3 = 'v1', 'v2', 'v3' + } + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $true' { + $script:result | Should -Be $true + } + } + + Context 'When missing property in the desired state' { + $currentValues = @{ + String = 'a string' + Bool = $true + } + + $desiredValues = [PSObject] @{ + String = 'a string' + } + + It 'Should not throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -ReverseCheck ` + -Verbose:$verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + } + + Context 'When testing parameter types' { + Context 'When desired value is of the wrong type' { + $currentValues = @{ + String = 'a string' + } + + $desiredValues = 1, 2, 3 + + It 'Should throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Throw + } + } + + Context 'When current value is of the wrong type' { + $currentValues = 1, 2, 3 + + $desiredValues = @{ + String = 'a string' + } + + It 'Should throw exception' { + { $script:result = Test-DscParameterState ` + -CurrentValues $currentValues ` + -DesiredValues $desiredValues ` + -Verbose:$verbose } | Should -Throw + } + } + } + } + + Describe 'ComputerManagementDsc.Common\Test-DscObjectHasProperty' { + # Use the Get-Verb cmdlet to just get a simple object fast + $testDscObject = (Get-Verb)[0] + + Context 'When the object contains the expected property' { + It 'Should not throw exception' { + { $script:result = Test-DscObjectHasProperty -Object $testDscObject -PropertyName 'Verb' -Verbose } | Should -Not -Throw + } + + It 'Should return $true' { + $script:result | Should -Be $true + } + } + + Context 'When the object does not contain the expected property' { + It 'Should not throw exception' { + { $script:result = Test-DscObjectHasProperty -Object $testDscObject -PropertyName 'Missing' -Verbose } | Should -Not -Throw + } + + It 'Should return $false' { + $script:result | Should -Be $false + } + } + } + + Describe 'ComputerManagementDsc.Common\ConvertTo-CimInstance' { + $hashtable = @{ + k1 = 'v1' + k2 = 100 + k3 = 1, 2, 3 + } + + Context 'When the array contains the expected record count' { + It 'Should not throw exception' { + { $script:result = [CimInstance[]]($hashtable | ConvertTo-CimInstance) } | Should -Not -Throw + } + + It "Should record count should be $($hashTable.Count)" { + $script:result.Count | Should -Be $hashtable.Count + } + + It 'Should return result of type CimInstance[]' { + $script:result.GetType().Name | Should -Be 'CimInstance[]' + } + + It 'Should return value "k1" in the CimInstance array should be "v1"' { + ($script:result | Where-Object Key -eq k1).Value | Should -Be 'v1' + } + + It 'Should return value "k2" in the CimInstance array should be "100"' { + ($script:result | Where-Object Key -eq k2).Value | Should -Be 100 + } + + It 'Should return value "k3" in the CimInstance array should be "1,2,3"' { + ($script:result | Where-Object Key -eq k3).Value | Should -Be '1,2,3' + } + } + } + + Describe 'ComputerManagementDsc.Common\ConvertTo-HashTable' { + [CimInstance[]]$cimInstances = ConvertTo-CimInstance -Hashtable @{ + k1 = 'v1' + k2 = 100 + k3 = 1, 2, 3 + } + + Context 'When the array contains the expected record count' { + It 'Should not throw exception' { + { $script:result = $cimInstances | ConvertTo-HashTable } | Should -Not -Throw + } + + It "Should return record count of $($cimInstances.Count)" { + $script:result.Count | Should -Be $cimInstances.Count + } + + It 'Should return result of type [System.Collections.Hashtable]' { + $script:result | Should -BeOfType [System.Collections.Hashtable] + } + + It 'Should return value "k1" in the hashtable should be "v1"' { + $script:result.k1 | Should -Be 'v1' + } + + It 'Should return value "k2" in the hashtable should be "100"' { + $script:result.k2 | Should -Be 100 + } + + It 'Should return value "k3" in the hashtable should be "1,2,3"' { + $script:result.k3 | Should -Be '1,2,3' + } + } + } + + Describe 'ComputerManagementDsc.Common\Get-TimeZoneId' { + Context '"Get-TimeZone" not available and current timezone is set to "Pacific Standard Time"' { + Mock ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Get-TimeZone' + } + + Mock -CommandName Get-CimInstance -MockWith { + @{ + StandardName = 'Pacific Standard Time' + } + } + + It 'Returns "Pacific Standard Time"' { + Get-TimeZoneId | Should -Be 'Pacific Standard Time' + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Get-TimeZone' + } -Exactly -Times 1 + + Assert-MockCalled -CommandName Get-CimInstance -Exactly -Times 1 + } + } + + Context '"Get-TimeZone" not available and current timezone is set to "Russia TZ 11 Standard Time"' { + Mock ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Get-TimeZone' + } + + Mock -CommandName Get-CimInstance -MockWith { + @{ + StandardName = 'Russia TZ 11 Standard Time' + } + } + + It 'Returns "Russia Time Zone 11"' { + Get-TimeZoneId | Should -Be 'Russia Time Zone 11' + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Get-TimeZone' + } -Exactly -Times 1 + + Assert-MockCalled -CommandName Get-CimInstance -Exactly -Times 1 + } + } + + Context '"Get-TimeZone" available and current timezone is set to "Pacific Standard Time"' { + function Get-TimeZone + { + } + + Mock ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Get-TimeZone' + } -MockWith { + 'Get-TimeZone' + } + + Mock ` + -CommandName Get-TimeZone ` + -MockWith { + @{ + StandardName = 'Pacific Standard Time' + } + } + + It 'Returns "Pacific Standard Time"' { + Get-TimeZoneId | Should -Be 'Pacific Standard Time' + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Get-TimeZone' + } -Exactly -Times 1 + + Assert-MockCalled -CommandName Get-TimeZone -Exactly -Times 1 + } + } + } + + Describe 'ComputerManagementDsc.Common\Test-TimezoneId' { + Mock -CommandName Get-TimeZoneId -MockWith { + 'Russia Time Zone 11' + } + + Context 'current timezone matches desired timezone' { + It 'Should return $true' { + Test-TimezoneId -TimeZoneId 'Russia Time Zone 11' | Should -BeTrue + } + } + + Context 'current timezone does not match desired timezone' { + It 'Should return $false' { + Test-TimezoneId -TimeZoneId 'GMT Standard Time' | Should -BeFalse + } + } + } + + Describe 'ComputerManagementDsc.Common\Set-TimeZoneId' { + Context '"Set-TimeZone" and "Add-Type" is not available, Tzutil Returns 0' { + Mock ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Add-Type' + } + + Mock ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Set-TimeZone' + } + + Mock -CommandName 'TzUtil.exe' -MockWith { + $global:LASTEXITCODE = 0 + return 'OK' + } + + Mock -CommandName Add-Type + + It 'Should not throw an exception' { + { Set-TimeZoneId -TimezoneId 'Eastern Standard Time' } | Should -Not -Throw + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Add-Type' + } -Exactly -Times 1 + + Assert-MockCalled ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Set-TimeZone' + } -Exactly -Times 1 + + Assert-MockCalled -CommandName TzUtil.exe -Exactly -Times 1 + Assert-MockCalled -CommandName Add-Type -Exactly -Times 0 + } + } + + Context '"Set-TimeZone" is not available but "Add-Type" is available' { + Mock ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Add-Type' + } -MockWith { + 'Add-Type' + } + + Mock ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Set-TimeZone' + } + + Mock -CommandName 'TzUtil.exe' -MockWith { + $global:LASTEXITCODE = 0 + return 'OK' + } + + Mock -CommandName Add-Type + Mock -CommandName Set-TimeZoneUsingDotNet + + It 'Should not throw an exception' { + { Set-TimeZoneId -TimezoneId 'Eastern Standard Time' } | Should -Not -Throw + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Add-Type' + } -Exactly -Times 1 + + Assert-MockCalled ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Set-TimeZone' + } -Exactly -Times 1 + + Assert-MockCalled -CommandName TzUtil.exe -Exactly -Times 0 + Assert-MockCalled -CommandName Add-Type -Exactly -Times 0 + Assert-MockCalled -CommandName Set-TimeZoneUsingDotNet -Exactly -Times 1 + } + } + + Context '"Set-TimeZone" is available' { + function Set-TimeZone + { + param + ( + [System.String] + $id + ) + } + + Mock ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Add-Type' + } + + Mock ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Set-TimeZone' + } -MockWith { + 'Set-TimeZone' + } + + Mock -CommandName Set-TimeZone + + It 'Should not throw an exception' { + { Set-TimeZoneId -TimezoneId 'Eastern Standard Time' } | Should -Not -Throw + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Add-Type' + } -Exactly -Times 0 + + Assert-MockCalled ` + -CommandName Get-Command ` + -ParameterFilter { + $Name -eq 'Set-TimeZone' + } -Exactly -Times 1 + + Assert-MockCalled -CommandName Set-TimeZone -Exactly -Times 1 + } + } + } + + Describe 'ComputerManagementDsc.Common\Get-PowerPlan' { + $mockBalancedPowerPlan = @{ + FriendlyName = 'Balanced' + Guid = [System.Guid]'381b4222-f694-41f0-9685-ff5bb260df2e' + } + + $mockHighPerformancePowerPlan = @{ + 'FriendlyName' = 'High performance' + 'Guid' = [System.Guid]'8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' + } + + $mockPowerSaverPowerPlan = @{ + 'FriendlyName' = 'Power saver' + 'Guid' = [System.Guid]'a1841308-3541-4fab-bc81-f71556f20b4a' + } + + Context 'Only one power plan is available and "PowerPlan" parameter is not specified' { + Mock ` + -CommandName Get-PowerPlanUsingPInvoke ` + -MockWith { + return $mockBalancedPowerPlan + } + + It 'Should not throw an exception' { + { Get-PowerPlan } | Should -Not -Throw + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-PowerPlanUsingPInvoke ` + -Exactly -Times 1 + } + + It 'Should return exactly one hashtable' { + $result = Get-PowerPlan + $result | Should -BeOfType [System.Collections.Hashtable] + $result | Should -HaveCount 1 + } + + } + + Context 'Only one power plan is available and "PowerPlan" parameter is specified as Guid of the available plan' { + Mock ` + -CommandName Get-PowerPlanUsingPInvoke ` + -MockWith { + return $mockBalancedPowerPlan + } + + It 'Should not throw an exception' { + { Get-PowerPlan -PowerPlan '381b4222-f694-41f0-9685-ff5bb260df2e' } | Should -Not -Throw + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-PowerPlanUsingPInvoke ` + -Exactly -Times 1 + } + + It 'Should return a hashtable with the name and guid fo the power plan' { + $result = Get-PowerPlan -PowerPlan '381b4222-f694-41f0-9685-ff5bb260df2e' + $result | Should -BeOfType [System.Collections.Hashtable] + $result | Should -HaveCount 1 + $result.FriendlyName | Should -Be 'Balanced' + $result.guid | Should -Be '381b4222-f694-41f0-9685-ff5bb260df2e' + } + } + + Context 'Only one power plan is available and "PowerPlan" parameter is specified as Guid of a not available plan' { + Mock ` + -CommandName Get-PowerPlanUsingPInvoke ` + -MockWith { + return $mockBalancedPowerPlan + } + + It 'Should not throw an exception' { + { Get-PowerPlan -PowerPlan '8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' } | Should -Not -Throw + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-PowerPlanUsingPInvoke ` + -Exactly -Times 1 + } + + It 'Should return nothing' { + $result = Get-PowerPlan -PowerPlan '8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' + $result | Should -BeNullOrEmpty + } + } + + Context 'Only one power plan is available and "PowerPlan" parameter is specified as name of the available plan' { + Mock ` + -CommandName Get-PowerPlanUsingPInvoke ` + -MockWith { + return $mockBalancedPowerPlan + } + + It 'Should not throw an exception' { + { Get-PowerPlan -PowerPlan 'Balanced' } | Should -Not -Throw + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-PowerPlanUsingPInvoke ` + -Exactly -Times 1 + } + + It 'Should return a hashtable with the name and guid fo the power plan' { + $result = Get-PowerPlan -PowerPlan 'Balanced' + $result | Should -BeOfType [System.Collections.Hashtable] + $result | Should -HaveCount 1 + $result.FriendlyName | Should -Be 'Balanced' + $result.guid | Should -Be '381b4222-f694-41f0-9685-ff5bb260df2e' + } + } + + Context 'Only one power plan is available and "PowerPlan" parameter is specified as name of a not available plan' { + Mock ` + -CommandName Get-PowerPlanUsingPInvoke ` + -MockWith { + return $mockBalancedPowerPlan + } + + It 'Should not throw an exception' { + { Get-PowerPlan -PowerPlan 'High performance' } | Should -Not -Throw + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-PowerPlanUsingPInvoke ` + -Exactly -Times 1 + } + + It 'Should return nothing' { + $result = Get-PowerPlan -PowerPlan 'High performance' + $result | Should -BeNullOrEmpty + } + } + + Context 'Multiple power plans are available and "PowerPlan" parameter is not specified' { + Mock ` + -CommandName Get-PowerPlanUsingPInvoke ` + -MockWith { + return @( + $mockBalancedPowerPlan + $mockHighPerformancePowerPlan + $mockPowerSaverPowerPlan + ) + } + + It 'Should not throw an exception' { + { Get-PowerPlan } | Should -Not -Throw + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-PowerPlanUsingPInvoke ` + -Exactly -Times 1 + } + + It 'Should return an array with all available plans' { + $result = Get-PowerPlan + $result | Should -HaveCount 3 + } + } + + Context 'Multiple power plans are available and "PowerPlan" parameter is specified as Guid of an available plan' { + Mock ` + -CommandName Get-PowerPlanUsingPInvoke ` + -MockWith { + return @( + $mockBalancedPowerPlan + $mockHighPerformancePowerPlan + $mockPowerSaverPowerPlan + ) + } + + It 'Should not throw an exception' { + { Get-PowerPlan -PowerPlan '381b4222-f694-41f0-9685-ff5bb260df2e' } | Should -Not -Throw + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-PowerPlanUsingPInvoke ` + -Exactly -Times 1 + } + + It 'Should return a hashtable with the name and guid fo the power plan' { + $result = Get-PowerPlan -PowerPlan '381b4222-f694-41f0-9685-ff5bb260df2e' + $result | Should -BeOfType [System.Collections.Hashtable] + $result | Should -HaveCount 1 + $result.FriendlyName | Should -Be 'Balanced' + $result.guid | Should -Be '381b4222-f694-41f0-9685-ff5bb260df2e' + } + } + + Context 'Multiple power plans are available and "PowerPlan" parameter is specified as Guid of a not available plan' { + Mock ` + -CommandName Get-PowerPlanUsingPInvoke ` + -MockWith { + return @( + $mockBalancedPowerPlan + $mockHighPerformancePowerPlan + $mockPowerSaverPowerPlan + ) + } + + It 'Should not throw an exception' { + { Get-PowerPlan -PowerPlan '9c5e7fda-e8bf-4a96-9a85-a7e23a8c635c' } | Should -Not -Throw + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-PowerPlanUsingPInvoke ` + -Exactly -Times 1 + } + + It 'Should return nothing' { + $result = Get-PowerPlan -PowerPlan '9c5e7fda-e8bf-4a96-9a85-a7e23a8c635c' + $result | Should -BeNullOrEmpty + } + } + + Context 'Multiple power plans are available and "PowerPlan" parameter is specified as name of an available plan' { + Mock ` + -CommandName Get-PowerPlanUsingPInvoke ` + -MockWith { + return @( + $mockBalancedPowerPlan + $mockHighPerformancePowerPlan + $mockPowerSaverPowerPlan + ) + } + + It 'Should not throw an exception' { + { Get-PowerPlan -PowerPlan 'High performance' } | Should -Not -Throw + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-PowerPlanUsingPInvoke ` + -Exactly -Times 1 + } + + It 'Should return a hashtable with the name and guid fo the power plan' { + $result = Get-PowerPlan -PowerPlan 'High performance' + $result | Should -BeOfType [System.Collections.Hashtable] + $result | Should -HaveCount 1 + $result.FriendlyName | Should -Be 'High performance' + $result.guid | Should -Be '8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' + } + } + + Context 'Multiple power plans are available and "PowerPlan" parameter is specified as name of a not available plan' { + Mock ` + -CommandName Get-PowerPlanUsingPInvoke ` + -MockWith { + return @( + $mockBalancedPowerPlan + $mockHighPerformancePowerPlan + $mockPowerSaverPowerPlan + ) + } + + It 'Should not throw an exception' { + { Get-PowerPlan -PowerPlan 'Some unavailable plan' } | Should -Not -Throw + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-PowerPlanUsingPInvoke ` + -Exactly -Times 1 + } + + It 'Should return nothing' { + $result = Get-PowerPlan -PowerPlan 'Some unavailable plan' + $result | Should -BeNullOrEmpty + } + } + } + + Describe 'DscResource.LocalizationHelper\Get-LocalizedData' { + $mockTestPath = { + return $mockTestPathReturnValue + } + + $mockImportLocalizedData = { + $BaseDirectory | Should -Be $mockExpectedLanguagePath + } + + BeforeEach { + Mock -CommandName Test-Path -MockWith $mockTestPath -Verifiable + Mock -CommandName Import-LocalizedData -MockWith $mockImportLocalizedData -Verifiable + } + + Context 'When loading localized data for Swedish' { + $mockExpectedLanguagePath = 'sv-SE' + $mockTestPathReturnValue = $true + + It 'Should call Import-LocalizedData with sv-SE language' { + Mock -CommandName Join-Path -MockWith { + return 'sv-SE' + } -Verifiable + + { Get-LocalizedData -ResourceName 'DummyResource' } | Should -Not -Throw + + Assert-MockCalled -CommandName Join-Path -Exactly -Times 3 -Scope It + Assert-MockCalled -CommandName Test-Path -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Import-LocalizedData -Exactly -Times 1 -Scope It + } + + $mockExpectedLanguagePath = 'en-US' + $mockTestPathReturnValue = $false + + It 'Should call Import-LocalizedData and fallback to en-US if sv-SE language does not exist' { + Mock -CommandName Join-Path -MockWith { + return $ChildPath + } -Verifiable + + { Get-LocalizedData -ResourceName 'DummyResource' } | Should -Not -Throw + + Assert-MockCalled -CommandName Join-Path -Exactly -Times 4 -Scope It + Assert-MockCalled -CommandName Test-Path -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Import-LocalizedData -Exactly -Times 1 -Scope It + } + + Context 'When $ScriptRoot is set to a path' { + $mockExpectedLanguagePath = 'sv-SE' + $mockTestPathReturnValue = $true + + It 'Should call Import-LocalizedData with sv-SE language' { + Mock -CommandName Join-Path -MockWith { + return 'sv-SE' + } -Verifiable + + { Get-LocalizedData -ResourceName 'DummyResource' -ScriptRoot '.' } | Should -Not -Throw + + Assert-MockCalled -CommandName Join-Path -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Test-Path -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Import-LocalizedData -Exactly -Times 1 -Scope It + } + + $mockExpectedLanguagePath = 'en-US' + $mockTestPathReturnValue = $false + + It 'Should call Import-LocalizedData and fallback to en-US if sv-SE language does not exist' { + Mock -CommandName Join-Path -MockWith { + return $ChildPath + } -Verifiable + + { Get-LocalizedData -ResourceName 'DummyResource' -ScriptRoot '.' } | Should -Not -Throw + + Assert-MockCalled -CommandName Join-Path -Exactly -Times 2 -Scope It + Assert-MockCalled -CommandName Test-Path -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Import-LocalizedData -Exactly -Times 1 -Scope It + } + } + } + + Context 'When loading localized data for English' { + Mock -CommandName Join-Path -MockWith { + return 'en-US' + } -Verifiable + + $mockExpectedLanguagePath = 'en-US' + $mockTestPathReturnValue = $true + + It 'Should call Import-LocalizedData with en-US language' { + { Get-LocalizedData -ResourceName 'DummyResource' } | Should -Not -Throw + } + } + + Assert-VerifiableMock + } + + Describe 'DscResource.LocalizationHelper\New-InvalidOperationException' { + Context 'When calling with Message parameter only' { + It 'Should throw the correct error' { + $mockErrorMessage = 'Mocked error' + + { New-InvalidOperationException -Message $mockErrorMessage } | Should -Throw $mockErrorMessage + } + } + + Context 'When calling with both the Message and ErrorRecord parameter' { + It 'Should throw the correct error' { + $mockErrorMessage = 'Mocked error' + $mockExceptionErrorMessage = 'Mocked exception error message' + + $mockException = New-Object -TypeName System.Exception -ArgumentList $mockExceptionErrorMessage + $mockErrorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord -ArgumentList $mockException, $null, 'InvalidResult', $null + + { New-InvalidOperationException -Message $mockErrorMessage -ErrorRecord $mockErrorRecord } | Should -Throw ('System.InvalidOperationException: {0} ---> System.Exception: {1}' -f $mockErrorMessage, $mockExceptionErrorMessage) + } + } + + Assert-VerifiableMock + } + + Describe 'DscResource.LocalizationHelper\New-InvalidArgumentException' { + Context 'When calling with both the Message and ArgumentName parameter' { + It 'Should throw the correct error' { + $mockErrorMessage = 'Mocked error' + $mockArgumentName = 'MockArgument' + + { New-InvalidArgumentException -Message $mockErrorMessage -ArgumentName $mockArgumentName } | Should -Throw ('Parameter name: {0}' -f $mockArgumentName) + } + } + + Assert-VerifiableMock + } + + Describe 'DscResource.LocalizationHelper\Test-IsNanoServer' { + Context 'When the cmdlet Get-ComputerInfo does not exist' { + BeforeAll { + Mock -CommandName Test-Command { + return $false + } + } + + Test-IsNanoServer | Should -BeFalse + } + + Context 'When the current computer is a Nano server' { + BeforeAll { + Mock -CommandName Test-Command { + return $true + } + + Mock -CommandName Get-ComputerInfo { + return @{ + OsProductType = 'Server' + OsServerLevel = 'NanoServer' + } + } + } + + Test-IsNanoServer | Should -BeTrue + } + + Context 'When the current computer is not a Nano server' { + BeforeAll { + Mock -CommandName Test-Command { + return $true + } + + Mock -CommandName Get-ComputerInfo { + return @{ + OsProductType = 'Server' + OsServerLevel = 'FullServer' + } + } + } + + Test-IsNanoServer | Should -BeFalse + } + } +} diff --git a/Tests/Unit/MSFT_Computer.Tests.ps1 b/tests/Unit/DSC_Computer.Tests.ps1 similarity index 96% rename from Tests/Unit/MSFT_Computer.Tests.ps1 rename to tests/Unit/DSC_Computer.Tests.ps1 index aac5566e..97d7c5f6 100644 --- a/Tests/Unit/MSFT_Computer.Tests.ps1 +++ b/tests/Unit/DSC_Computer.Tests.ps1 @@ -1,35 +1,38 @@ -#region HEADER $script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_Computer' +$script:dscResourceName = 'DSC_Computer' -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global - -# Unit Test Template Version: 1.2.4 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +function Invoke-TestSetup { - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') } -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -ResourceType 'Mof' ` - -TestType Unit -#endregion HEADER +Invoke-TestSetup # Begin Testing try { - #region Pester Tests - InModuleScope $script:dscResourceName { - $script:dscResourceName = 'MSFT_Computer' - - Describe $script:dscResourceName { + Describe 'DSC_Computer' { # A real password isn't needed here - use this next line to avoid triggering PSSA rule $securePassword = New-Object -Type SecureString $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'USER', $securePassword @@ -42,7 +45,7 @@ try 'name' } - Context "$($script:dscResourceName)\Test-TargetResource" { + Context 'DSC_Computer\Test-TargetResource' { Mock -CommandName Get-WMIObject -MockWith { [PSCustomObject] @{ DomainName = 'ContosoLtd' @@ -444,7 +447,7 @@ try } } - Context "$($script:dscResourceName)\Get-TargetResource" { + Context 'DSC_Computer\Get-TargetResource' { It 'should not throw' { { Get-TargetResource ` @@ -479,7 +482,7 @@ try } } - Context "$($script:dscResourceName)\Set-TargetResource" { + Context 'DSC_Computer\Set-TargetResource' { Mock -CommandName Rename-Computer Mock -CommandName Set-CimInstance @@ -739,10 +742,10 @@ try } { Set-TargetResource ` - -Name $notComputerName ` - -DomainName 'Contoso.com' ` - -JoinOU 'OU=Computers,DC=contoso,DC=com' ` - -Credential $credential + -Name $notComputerName ` + -DomainName 'Contoso.com' ` + -JoinOU 'OU=Computers,DC=contoso,DC=com' ` + -Credential $credential } | Should -Throw $error Assert-MockCalled -CommandName Rename-Computer -Exactly -Times 0 -Scope It @@ -782,7 +785,7 @@ try Assert-MockCalled -CommandName Rename-Computer -Exactly -Times 0 -Scope It Assert-MockCalled -CommandName Add-Computer -Exactly -Times 1 -Scope It -ParameterFilter { $DomainName -and $NewName } Assert-MockCalled -CommandName Add-Computer -Exactly -Times 0 -Scope It -ParameterFilter { $WorkGroupName } - } + } It 'Changes ComputerName and changes Workgroup to new Workgroup' { Mock -CommandName Get-WMIObject -MockWith { @@ -1089,7 +1092,7 @@ try } } - Context "$($script:dscResourceName)\Get-ComputerDomain" { + Context 'DSC_Computer\Get-ComputerDomain' { It 'Returns domain netbios or DNS name if domain member' { Mock -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'Win32_ComputerSystem' } -MockWith { [PSCustomObject] @{ @@ -1171,18 +1174,15 @@ try } } - Context "$($script:dscResourceName)\Get-LogonServer" { + Context 'DSC_Computer\Get-LogonServer' { It 'Should return a non-empty string' { Get-LogonServer | Should -Not -BeNullOrEmpty } } } - } #end InModuleScope $DSCResourceName - #endregion + } } finally { - #region FOOTER - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion + Invoke-TestCleanup } diff --git a/Tests/Unit/MSFT_OfflineDomainJoin.Tests.ps1 b/tests/Unit/DSC_OfflineDomainJoin.Tests.ps1 similarity index 75% rename from Tests/Unit/MSFT_OfflineDomainJoin.Tests.ps1 rename to tests/Unit/DSC_OfflineDomainJoin.Tests.ps1 index a241c79d..f4503b88 100644 --- a/Tests/Unit/MSFT_OfflineDomainJoin.Tests.ps1 +++ b/tests/Unit/DSC_OfflineDomainJoin.Tests.ps1 @@ -1,50 +1,54 @@ -#region HEADER $script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_OfflineDomainJoin' +$script:dscResourceName = 'DSC_OfflineDomainJoin' -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global - -# Unit Test Template Version: 1.2.4 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +function Invoke-TestSetup { - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') } -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -ResourceType 'Mof' ` - -TestType Unit -#endregion HEADER +Invoke-TestSetup # Begin Testing try { - #region Pester Tests InModuleScope $script:dscResourceName { - $script:dscResourceName = 'MSFT_OfflineDomainJoin' - $testOfflineDomainJoin = @{ IsSingleInstance = 'Yes' RequestFile = 'C:\ODJRequest.txt' Verbose = $true } - Describe "$($script:dscResourceName)\Get-TargetResource" { + Describe 'DSC_OfflineDomainJoin\Get-TargetResource' { It 'Should return the correct values' { $result = Get-TargetResource ` @TestOfflineDomainJoin - $result.IsSingleInstance | Should -Be $testOfflineDomainJoin.IsSingleInstance - $result.RequestFile | Should -Be '' + $result.IsSingleInstance | Should -Be $testOfflineDomainJoin.IsSingleInstance + $result.RequestFile | Should -Be '' } } - Describe "$($script:dscResourceName)\Set-TargetResource" { + Describe 'DSC_OfflineDomainJoin\Set-TargetResource' { Context 'Domain is not joined' { Mock -CommandName Test-Path -MockWith { return $true @@ -84,7 +88,7 @@ try } } - Describe "$($script:dscResourceName)\Test-TargetResource" { + Describe 'DSC_OfflineDomainJoin\Test-TargetResource' { Context 'Domain is not joined' { Mock -CommandName Test-Path -MockWith { return $true @@ -147,7 +151,7 @@ try } } - Describe "$($script:dscResourceName)\Join-Domain" { + Describe 'DSC_OfflineDomainJoin\Join-Domain' { Context 'Domain Join successful' { Mock -CommandName djoin.exe -MockWith { $script:LASTEXITCODE = 0 @@ -181,12 +185,9 @@ try } } } - } #end InModuleScope $DSCResourceName - #endregion + } } finally { - #region FOOTER - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion + Invoke-TestCleanup } diff --git a/Tests/Unit/MSFT_PendingReboot.Tests.ps1 b/tests/Unit/DSC_PendingReboot.Tests.ps1 similarity index 89% rename from Tests/Unit/MSFT_PendingReboot.Tests.ps1 rename to tests/Unit/DSC_PendingReboot.Tests.ps1 index 99fc6801..dc55587a 100644 --- a/Tests/Unit/MSFT_PendingReboot.Tests.ps1 +++ b/tests/Unit/DSC_PendingReboot.Tests.ps1 @@ -1,30 +1,36 @@ -#region HEADER $script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_PendingReboot' +$script:dscResourceName = 'DSC_PendingReboot' -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global - -# Unit Test Template Version: 1.2.4 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +function Invoke-TestSetup { - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') } -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -ResourceType 'Mof' ` - -TestType Unit -#endregion HEADER +Invoke-TestSetup # Begin Testing try { - #region Pester Tests InModuleScope $script:dscResourceName { $script:testResourceName = 'Test' @@ -72,11 +78,11 @@ try } } - Describe 'MSFT_PendingReboot\Get-TargetResource' { + Describe 'DSC_PendingReboot\Get-TargetResource' { Context 'When all reboots are required' { Mock -CommandName Get-PendingRebootState ` -MockWith $getPendingRebootStateAllRebootsTrue ` - -ModuleName 'MSFT_PendingReboot' ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable It 'Should not throw an exception' { @@ -108,7 +114,7 @@ try Context 'When no reboots are required' { Mock -CommandName Get-PendingRebootState ` -MockWith $getPendingRebootStateAllRebootsFalse ` - -ModuleName 'MSFT_PendingReboot' ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable It 'Should not throw an exception' { @@ -138,13 +144,13 @@ try } } - Describe 'MSFT_PendingReboot\Set-TargetResource' { + Describe 'DSC_PendingReboot\Set-TargetResource' { Context 'When a reboot is not required' { $global:DSCMachineStatus = 0 Mock -CommandName Get-PendingRebootState ` -MockWith $getPendingRebootStateAllRebootsTrue ` - -ModuleName 'MSFT_PendingReboot' ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable It 'Should not throw an exception' { @@ -163,7 +169,7 @@ try Mock -CommandName Get-PendingRebootState ` -MockWith $getPendingRebootStateAllRebootsFalse ` - -ModuleName 'MSFT_PendingReboot' ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable It 'Should not throw an exception' { @@ -178,11 +184,11 @@ try } } - Describe 'MSFT_PendingReboot\Test-TargetResource' { + Describe 'DSC_PendingReboot\Test-TargetResource' { Context 'When a reboot is required' { Mock -CommandName Get-PendingRebootState ` -MockWith $getPendingRebootStateAllRebootsTrue ` - -ModuleName 'MSFT_PendingReboot' ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable It 'Should not throw an exception' { @@ -201,7 +207,7 @@ try Mock -CommandName Get-PendingRebootState ` -MockWith $getPendingRebootStateAllRebootsFalse ` - -ModuleName 'MSFT_PendingReboot' ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable It 'Should not throw an exception' { @@ -216,7 +222,7 @@ try } } - Describe 'MSFT_PendingReboot\Get-PendingRebootHashTable' { + Describe 'DSC_PendingReboot\Get-PendingRebootHashTable' { BeforeAll { $getChildItemComponentBasedServicingMock = { @{ @@ -285,36 +291,36 @@ try Mock -CommandName Get-ChildItem ` -MockWith $getChildItemComponentBasedServicingMock ` -ParameterFilter $getChildItemComponentBasedServicingParameterFilter ` - -ModuleName 'MSFT_PendingReboot' ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable Mock -CommandName Get-ChildItem ` -MockWith $getChildItemAutoUpdateMock ` -ParameterFilter $getChildItemAutoUpdateParameterFilter ` - -ModuleName 'MSFT_PendingReboot' ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable Mock -CommandName Get-ItemProperty ` -MockWith $getItemPropertyFileRenameMock ` -ParameterFilter $getItemPropertyFileRenameParameterFilter ` - -ModuleName 'MSFT_PendingReboot' ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable Mock -CommandName Get-ItemProperty ` -MockWith $getItemPropertyActiveComputerNameMock ` -ParameterFilter $getItemPropertyActiveComputerNameFilter ` - -ModuleName 'MSFT_PendingReboot' ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable Mock -CommandName Get-ItemProperty ` -MockWith $getItemPropertyComputerNameMock ` -ParameterFilter $getItemPropertyComputerNameFilter ` - -ModuleName 'MSFT_PendingReboot' ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable Mock -CommandName Invoke-CimMethod ` -MockWith $invokeCimMethodRebootPendingMock ` - -ModuleName 'MSFT_PendingReboot' + -ModuleName 'DSC_PendingReboot' } Context 'When SkipCcmClientSdk is set to False' { @@ -378,12 +384,12 @@ try BeforeAll { Mock -CommandName Get-ChildItem ` -ParameterFilter $getChildItemComponentBasedServicingParameterFilter ` - -ModuleName 'MSFT_PendingReboot' ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable Mock -CommandName Get-ChildItem ` -ParameterFilter $getChildItemAutoUpdateParameterFilter ` - -ModuleName 'MSFT_PendingReboot' ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable Mock -CommandName Get-ItemProperty ` @@ -392,7 +398,7 @@ try PendingFileRenameOperations = @() } } ` - -ModuleName 'MSFT_PendingReboot' ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable Mock -CommandName Get-ItemProperty ` @@ -400,7 +406,7 @@ try @{ } } ` -ParameterFilter $getItemPropertyActiveComputerNameFilter ` - -ModuleName 'MSFT_PendingReboot' ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable Mock -CommandName Get-ItemProperty ` @@ -408,12 +414,12 @@ try @{ } } ` -ParameterFilter $getItemPropertyComputerNameFilter ` - -ModuleName 'MSFT_PendingReboot' ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable Mock -CommandName Invoke-CimMethod ` -MockWith $invokeCimMethodRebootNotPendingMock ` - -ModuleName 'MSFT_PendingReboot' + -ModuleName 'DSC_PendingReboot' } Context 'When SkipCcmClientSdk is set to False' { @@ -472,7 +478,7 @@ try } } - Describe 'MSFT_PendingReboot\Get-PendingRebootState' { + Describe 'DSC_PendingReboot\Get-PendingRebootState' { $getPendingRebootStateObject = @{ Name = $script:testResourceName SkipComponentBasedServicing = $false @@ -510,9 +516,9 @@ try Mock -CommandName Get-PendingRebootHashTable ` -MockWith { - $getPendingRebootStateMock - } ` - -ModuleName 'MSFT_PendingReboot' ` + $getPendingRebootStateMock + } ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable } @@ -543,9 +549,9 @@ try Mock -CommandName Get-PendingRebootHashTable ` -MockWith { - $getPendingRebootStateMock - } ` - -ModuleName 'MSFT_PendingReboot' ` + $getPendingRebootStateMock + } ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable } @@ -573,9 +579,9 @@ try Mock -CommandName Get-PendingRebootHashTable ` -MockWith { - $getPendingRebootStateMock - } ` - -ModuleName 'MSFT_PendingReboot' ` + $getPendingRebootStateMock + } ` + -ModuleName 'DSC_PendingReboot' ` -Verifiable } @@ -600,12 +606,9 @@ try } } } - } #end InModuleScope $DSCResourceName - #endregion + } } finally { - #region FOOTER - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion + Invoke-TestCleanup } diff --git a/tests/Unit/DSC_PowerPlan.Tests.ps1 b/tests/Unit/DSC_PowerPlan.Tests.ps1 new file mode 100644 index 00000000..9c6e9fc4 --- /dev/null +++ b/tests/Unit/DSC_PowerPlan.Tests.ps1 @@ -0,0 +1,287 @@ +$script:dscModuleName = 'ComputerManagementDsc' +$script:dscResourceName = 'DSC_PowerPlan' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + $testCases = @( + # Power plan as name specified + @{ + Type = 'Name' + Name = 'High performance' + }, + + # Power plan as Guid specified + @{ + Type = 'Guid' + Name = '8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' + } + ) + + Describe 'DSC_PowerPlan\Get-TargetResource' { + Context 'When the system is in the desired present state' { + BeforeEach { + Mock ` + -CommandName Get-PowerPlan ` + -MockWith { + return @{ + FriendlyName = 'High performance' + Guid = [System.Guid]'8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' + } + } ` + -Verifiable + + Mock ` + -CommandName Get-ActivePowerPlan ` + -MockWith { + return [System.Guid]'8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' + } ` + -Verifiable + } + + It 'Should return the same values as passed as parameters (power plan specified as )' -TestCases $testCases { + param + ( + [System.String] + $Name + ) + + $result = Get-TargetResource -Name $Name -IsSingleInstance 'Yes' -Verbose + $result.IsSingleInstance | Should -Be 'Yes' + $result.Name | Should -Be $Name + $result.IsActive | Should -BeTrue + } + } + + Context 'When the system is not in the desired present state' { + BeforeEach { + Mock ` + -CommandName Get-PowerPlan ` + -MockWith { + return @{ + FriendlyName = 'High performance' + Guid = [System.Guid]'8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' + } + } ` + -Verifiable + + Mock ` + -CommandName Get-ActivePowerPlan ` + -MockWith { + return [System.Guid]'381b4222-f694-41f0-9685-ff5bb260df2e' + } ` + -Verifiable + } + + It 'Should return an inactive plan (power plan specified as )' -TestCases $testCases { + + param + ( + [System.String] + $Name + ) + + $result = Get-TargetResource -Name $Name -IsSingleInstance 'Yes' -Verbose + $result.IsSingleInstance | Should -Be 'Yes' + $result.Name | Should -Be $Name + $result.IsActive | Should -BeFalse + } + } + + Context 'When the preferred plan does not exist' { + BeforeEach { + Mock ` + -CommandName Get-PowerPlan ` + -Verifiable + } + + It 'Should throw the expected error (power plan specified as )' -TestCases $testCases { + + param + ( + [System.String] + $Name + ) + + $errorRecord = Get-InvalidOperationRecord ` + -Message ($script:localizedData.PowerPlanNotFound -f $Name) + + { Get-TargetResource -Name $Name -IsSingleInstance 'Yes' -Verbose } | Should -Throw $errorRecord + } + + Assert-VerifiableMock + } + } + + Describe 'DSC_PowerPlan\Set-TargetReource' { + BeforeEach { + Mock ` + -CommandName Get-PowerPlan ` + -MockWith { + return @{ + FriendlyName = 'High performance' + Guid = [System.Guid]'8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' + } + } ` + -Verifiable + + Mock ` + -CommandName Set-ActivePowerPlan ` + -Verifiable + } + + Context 'When the system is not in the desired present state' { + It 'Should call Get-PowerPlan once (power plan specified as )' -TestCases $testCases { + param + ( + [System.String] + $Name + ) + + Set-TargetResource -Name $Name -IsSingleInstance 'Yes' -Verbose + + Assert-MockCalled -CommandName Get-PowerPlan -Exactly -Times 1 -Scope It + } + + It 'Should call Set-ActivePowerPlan once (power plan specified as )' -TestCases $testCases { + param + ( + [System.String] + $Name + ) + + Set-TargetResource -Name $Name -IsSingleInstance 'Yes' -Verbose + + Assert-MockCalled ` + -CommandName Set-ActivePowerPlan ` + -Exactly ` + -Times 1 ` + -Scope It ` + -ParameterFilter { $PowerPlanGuid -eq '8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' } + } + } + + Context 'When the preferred plan does not exist' { + BeforeEach { + Mock ` + -CommandName Get-PowerPlan ` + -Verifiable + } + + It 'Should throw the expected error (power plan specified as )' -TestCases $testCases { + param + ( + [System.String] + $Name + ) + + $errorRecord = Get-InvalidOperationRecord ` + -Message ($script:localizedData.PowerPlanNotFound -f $Name) + + { Set-TargetResource -Name $Name -IsSingleInstance 'Yes' -Verbose } | Should -Throw $errorRecord + } + } + + Assert-VerifiableMock + } + + Describe 'DSC_PowerPlan\Test-TargetResource' { + Context 'When the system is in the desired present state' { + BeforeEach { + Mock ` + -CommandName Get-PowerPlan ` + -MockWith { + return @{ + FriendlyName = 'High performance' + Guid = [System.Guid]'8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' + } + } ` + -Verifiable + + Mock ` + -CommandName Get-ActivePowerPlan ` + -MockWith { + return [System.Guid]'8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' + } ` + -Verifiable + } + + + It 'Should return the the state as present ($true) (power plan specified as )' -TestCases $testCases { + param + ( + [System.String] + $Name + ) + + Test-TargetResource -Name $Name -IsSingleInstance 'Yes' -Verbose | Should -BeTrue + } + } + + Context 'When the system is not in the desired state' { + BeforeEach { + Mock ` + -CommandName Get-PowerPlan ` + -MockWith { + return @{ + FriendlyName = 'High performance' + Guid = [System.Guid]'8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' + } + } ` + -Verifiable + + Mock ` + -CommandName Get-ActivePowerPlan ` + -MockWith { + return [System.Guid]'381b4222-f694-41f0-9685-ff5bb260df2e' + } ` + -Verifiable + } + + It 'Should return the the state as absent ($false) (power plan specified as )' -TestCases $testCases { + param + ( + [System.String] + $Name + ) + + Test-TargetResource -Name $Name -IsSingleInstance 'Yes' -Verbose | Should -BeFalse + } + } + + Assert-VerifiableMock + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/Tests/Unit/MSFT_PowerShellExecutionpolicy.Tests.ps1 b/tests/Unit/DSC_PowerShellExecutionpolicy.Tests.ps1 similarity index 65% rename from Tests/Unit/MSFT_PowerShellExecutionpolicy.Tests.ps1 rename to tests/Unit/DSC_PowerShellExecutionpolicy.Tests.ps1 index f3c16ca3..75a1421b 100644 --- a/Tests/Unit/MSFT_PowerShellExecutionpolicy.Tests.ps1 +++ b/tests/Unit/DSC_PowerShellExecutionpolicy.Tests.ps1 @@ -1,60 +1,49 @@ -#region HEADER $script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_PowershellExecutionPolicy' +$script:dscResourceName = 'DSC_PowershellExecutionPolicy' -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' -# Unit Test Template Version: 1.2.4 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) + Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') +} + +function Invoke-TestCleanup { - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force - -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -ResourceType 'Mof' ` - -TestType Unit -#endregion HEADER - -$Script:invalidPolicyThrowMessage = @" -Cannot validate argument on parameter 'ExecutionPolicy'. The argument `"badParam`" does -not belong to the set `"Bypass,Restricted,AllSigned,RemoteSigned,Unrestricted`" -specified by the ValidateSet attribute. Supply an argument that is in the set and then -try the command again. -"@ - -$Script:invalidPolicyExecutionPolicyScopeThrowMessage = @" -Cannot validate argument on parameter 'ExecutionPolicyScope'. The argument `"badParam`" -does not belong to the set `"CurrentUser,LocalMachine,MachinePolicy,Process,UserPolicy`" -specified by the ValidateSet attribute. Supply an argument that is in the set and then -try the command again. -"@ +Invoke-TestSetup # Begin Testing try { - <# - The InModuleScope command allows you to perform white-box unit testing on the internal - (non-exported) code of a Script Module. - #> InModuleScope $script:dscResourceName { - $script:dscResourceName = 'MSFT_PowershellExecutionPolicy' + $Script:invalidPolicyThrowMessage = "Cannot validate argument on parameter 'ExecutionPolicy'. The argument `"badParam`" does not belong to the set `"Bypass,Restricted,AllSigned,RemoteSigned,Unrestricted`" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again." - #region Function Get-TargetResource - Describe "$($script:dscResourceName)\Get-TargetResource" { + $Script:invalidPolicyExecutionPolicyScopeThrowMessage = "Cannot validate argument on parameter 'ExecutionPolicyScope'. The argument `"badParam`" does not belong to the set `"CurrentUser,LocalMachine,MachinePolicy,Process,UserPolicy`" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again." + Describe 'DSC_PowershellExecutionPolicy\Get-TargetResource' { It 'Throws when passed an invalid execution policy' { { Get-TargetResource -ExecutionPolicy 'badParam' -Scope 'LocalMachine' } | Should -Throw $Script:invalidPolicyThrowMessage } It 'Returns correct execution policy' { Mock Get-ExecutionPolicy { 'Unrestricted' } - $result = Get-TargetResource -ExecutionPolicy $(Get-ExecutionPolicy ) -ExecutionPolicyScope 'LocalMachine' + $result = Get-TargetResource -ExecutionPolicy $(Get-ExecutionPolicy) -ExecutionPolicyScope 'LocalMachine' $result.ExecutionPolicy | Should -Be $(Get-ExecutionPolicy) } @@ -68,11 +57,8 @@ try $result.ExecutionPolicyScope | Should -Be 'LocalMachine' } } - #endregion - - #region Function Test-TargetResource - Describe "$($script:dscResourceName)\Test-TargetResource" { + Describe 'DSC_PowershellExecutionPolicy\Test-TargetResource' { It 'Throws when passed an invalid execution policy' { { Test-TargetResource -ExecutionPolicy 'badParam' -Scope 'LocalMachine' } | Should -Throw $Script:invalidPolicyThrowMessage } @@ -100,11 +86,8 @@ try Test-TargetResource -ExecutionPolicy 'Bypass' -ExecutionPolicyScope 'LocalMachine' | Should -BeFalse } } - #endregion - - #region Function Set-TargetResource - Describe "$script:dscResourceName\Set-TargetResource" { + Describe 'DSC_PowershellExecutionPolicy\Set-TargetResource' { It 'Throws when passed an invalid execution policy' { { Set-TargetResource -ExecutionPolicy 'badParam' -Scope 'LocalMachine' } | Should -Throw $Script:invalidPolicyThrowMessage } @@ -136,10 +119,9 @@ try Assert-MockCalled -CommandName Set-ExecutionPolicy -Exactly 1 -Scope It } } - #endregion } } finally { - Restore-TestEnvironment -TestEnvironment $TestEnvironment + Invoke-TestCleanup } diff --git a/Tests/Unit/MSFT_RemoteDesktopAdmin.Tests.ps1 b/tests/Unit/DSC_RemoteDesktopAdmin.Tests.ps1 similarity index 83% rename from Tests/Unit/MSFT_RemoteDesktopAdmin.Tests.ps1 rename to tests/Unit/DSC_RemoteDesktopAdmin.Tests.ps1 index 14aa5776..e56251b7 100644 --- a/Tests/Unit/MSFT_RemoteDesktopAdmin.Tests.ps1 +++ b/tests/Unit/DSC_RemoteDesktopAdmin.Tests.ps1 @@ -1,41 +1,37 @@ -#region HEADER $script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_RemoteDesktopAdmin' +$script:dscResourceName = 'DSC_RemoteDesktopAdmin' -# Unit Test Template Version: 1.2.4 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +function Invoke-TestSetup { - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force - -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -ResourceType 'Mof' ` - -TestType Unit + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } -#endregion HEADER + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' -function Invoke-TestSetup -{ + Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') } function Invoke-TestCleanup { - Restore-TestEnvironment -TestEnvironment $TestEnvironment + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } +Invoke-TestSetup + # Begin Testing try { - Invoke-TestSetup - InModuleScope $script:dscResourceName { - $mockGetTargetResourcePresentSecure = @{ IsSingleInstance = 'Yes' Ensure = 'Present' @@ -54,16 +50,16 @@ try UserAuthentication = 'NonSecure' } - Describe 'MSFT_RemoteDesktopAdmin\Get-TargetResource' { + Describe 'DSC_RemoteDesktopAdmin\Get-TargetResource' { Context 'When Remote Desktop Admin settings exist' { It 'Should return the correct values when Ensure is Present' { Mock -CommandName Get-ItemProperty ` -ParameterFilter { $Name -eq 'fDenyTSConnections' } ` - -MockWith { @{fDenyTSConnections = 0} } + -MockWith { @{fDenyTSConnections = 0 } } Mock -CommandName Get-ItemProperty ` -ParameterFilter { $Name -eq 'UserAuthentication' } ` - -MockWith { @{UserAuthentication = 0} } + -MockWith { @{UserAuthentication = 0 } } $targetResource = Get-TargetResource -IsSingleInstance 'Yes' $targetResource.Ensure | Should -Be 'Present' @@ -72,11 +68,11 @@ try It 'Should return the correct values when Ensure is Absent' { Mock -CommandName Get-ItemProperty ` -ParameterFilter { $Name -eq 'fDenyTSConnections' } ` - -MockWith { @{fDenyTSConnections = 1} } + -MockWith { @{fDenyTSConnections = 1 } } Mock -CommandName Get-ItemProperty ` -ParameterFilter { $Name -eq 'UserAuthentication' } ` - -MockWith { @{UserAuthentication = 0} } + -MockWith { @{UserAuthentication = 0 } } $targetResource = Get-TargetResource -IsSingleInstance 'Yes' $targetResource.Ensure | Should -Be 'Absent' @@ -85,11 +81,11 @@ try It 'Should return the correct values when UserAuthentication is NonSecure' { Mock -CommandName Get-ItemProperty ` -ParameterFilter { $Name -eq 'fDenyTSConnections' } ` - -MockWith { @{fDenyTSConnections = 0} } + -MockWith { @{fDenyTSConnections = 0 } } Mock -CommandName Get-ItemProperty ` -ParameterFilter { $Name -eq 'UserAuthentication' } ` - -MockWith { @{UserAuthentication = 0} } ` + -MockWith { @{UserAuthentication = 0 } } ` $result = Get-TargetResource -IsSingleInstance 'Yes' $result.UserAuthentication | Should -Be 'NonSecure' @@ -98,11 +94,11 @@ try It 'Should return the correct values when UserAuthentication is Secure' { Mock -CommandName Get-ItemProperty ` -ParameterFilter { $Name -eq 'fDenyTSConnections' } ` - -MockWith { @{fDenyTSConnections = 0} } + -MockWith { @{fDenyTSConnections = 0 } } Mock -CommandName Get-ItemProperty ` -ParameterFilter { $Name -eq 'UserAuthentication' } ` - -MockWith { @{UserAuthentication = 1} } ` + -MockWith { @{UserAuthentication = 1 } } ` $result = Get-TargetResource -IsSingleInstance 'Yes' $result.UserAuthentication | Should -Be 'Secure' @@ -110,7 +106,7 @@ try } } - Describe 'MSFT_RemoteDesktopAdmin\Test-TargetResource' { + Describe 'DSC_RemoteDesktopAdmin\Test-TargetResource' { Context 'When the system is in the desired state' { It 'Should return true when Ensure is present' { Mock -CommandName Get-TargetResource ` @@ -184,7 +180,7 @@ try } } - Describe 'MSFT_RemoteDesktopAdmin\Set-TargetResource' { + Describe 'DSC_RemoteDesktopAdmin\Set-TargetResource' { Context 'When the state needs to be changed' { BeforeEach { Mock -CommandName Set-ItemProperty diff --git a/Tests/Unit/MSFT_ScheduledTask.Tests.ps1 b/tests/Unit/DSC_ScheduledTask.Tests.ps1 similarity index 93% rename from Tests/Unit/MSFT_ScheduledTask.Tests.ps1 rename to tests/Unit/DSC_ScheduledTask.Tests.ps1 index dd974827..f2c6d5ff 100644 --- a/Tests/Unit/MSFT_ScheduledTask.Tests.ps1 +++ b/tests/Unit/DSC_ScheduledTask.Tests.ps1 @@ -3,39 +3,41 @@ param ( ) -#region HEADER $script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_ScheduledTask' +$script:dscResourceName = 'DSC_ScheduledTask' -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global - -# Unit Test Template Version: 1.2.4 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +function Invoke-TestSetup { - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force + Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') +} -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -ResourceType 'Mof' ` - -TestType Unit -#endregion HEADER +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global +Invoke-TestSetup -$VerbosePreference = 'Continue' # Begin Testing try { - #region Pester Tests - - InModuleScope $script:dscResourceName { - $script:dscResourceName = 'MSFT_ScheduledTask' + InModuleScope $script:DSCResourceName { + $VerbosePreference = 'Continue' # Function to allow mocking pipeline input function Register-ScheduledTask @@ -89,15 +91,15 @@ try ) } - Describe $script:dscResourceName { + Describe 'DSC_ScheduledTask' { BeforeAll { Mock -CommandName Register-ScheduledTask Mock -CommandName Set-ScheduledTask Mock -CommandName Unregister-ScheduledTask $getTargetResourceParameters = @{ - TaskName = 'Test task' - TaskPath = '\Test\' + TaskName = 'Test task' + TaskPath = '\Test\' } } @@ -174,8 +176,8 @@ try Context 'A built-in scheduled task exists and is enabled, but it should be disabled' { $testParameters = $getTargetResourceParameters + @{ - Enable = $false - Verbose = $true + Enable = $false + Verbose = $true } Mock -CommandName Get-ScheduledTask -MockWith { @@ -217,8 +219,8 @@ try Context 'A built-in scheduled task exists, but it should be absent' { $testParameters = $getTargetResourceParameters + @{ - Ensure = 'Absent' - Verbose = $true + Ensure = 'Absent' + Verbose = $true } Mock -CommandName Get-ScheduledTask -MockWith { @@ -979,8 +981,8 @@ try Settings = [pscustomobject] @{ Enabled = $true IdleSettings = @{ - WaitTimeout = "PT$([System.TimeSpan]::Parse($testParameters.IdleWaitTimeout).TotalMinutes)M" - IdleDuration = "PT$([System.TimeSpan]::Parse($testParameters.IdleDuration).TotalMinutes)M" + WaitTimeout = "PT$([System.TimeSpan]::Parse($testParameters.IdleWaitTimeout).TotalMinutes)M" + IdleDuration = "PT$([System.TimeSpan]::Parse($testParameters.IdleDuration).TotalMinutes)M" } ExecutionTimeLimit = "PT$([System.TimeSpan]::Parse($testParameters.ExecutionTimeLimit).TotalMinutes)M" RestartInterval = "PT$([System.TimeSpan]::Parse($testParameters.RestartInterval).TotalMinutes)M" @@ -1157,23 +1159,23 @@ try Context 'A scheduled task path is root or custom' -Fixture { It 'Should return backslash' { - ConvertTo-NormalizedTaskPath -TaskPath '\'| Should -Be '\' + ConvertTo-NormalizedTaskPath -TaskPath '\' | Should -Be '\' } It 'Should add backslash at the end' { - ConvertTo-NormalizedTaskPath -TaskPath '\Test'| Should -Be '\Test\' + ConvertTo-NormalizedTaskPath -TaskPath '\Test' | Should -Be '\Test\' } It 'Should add backslash at the beginning' { - ConvertTo-NormalizedTaskPath -TaskPath 'Test\'| Should -Be '\Test\' + ConvertTo-NormalizedTaskPath -TaskPath 'Test\' | Should -Be '\Test\' } It 'Should add backslash at the beginning and at the end' { - ConvertTo-NormalizedTaskPath -TaskPath 'Test'| Should -Be '\Test\' + ConvertTo-NormalizedTaskPath -TaskPath 'Test' | Should -Be '\Test\' } It 'Should not add backslash' { - ConvertTo-NormalizedTaskPath -TaskPath '\Test\'| Should -Be '\Test\' + ConvertTo-NormalizedTaskPath -TaskPath '\Test\' | Should -Be '\Test\' } } @@ -1215,8 +1217,8 @@ try ) Settings = [pscustomobject] @{ IdleSettings = @{ - WaitTimeout = "PT$([System.TimeSpan]::Parse($testParameters.IdleWaitTimeout).TotalMinutes)M" - IdleDuration = "PT$([System.TimeSpan]::Parse($testParameters.IdleDuration).TotalMinutes)M" + WaitTimeout = "PT$([System.TimeSpan]::Parse($testParameters.IdleWaitTimeout).TotalMinutes)M" + IdleDuration = "PT$([System.TimeSpan]::Parse($testParameters.IdleDuration).TotalMinutes)M" } ExecutionTimeLimit = "PT$([System.TimeSpan]::Parse($testParameters.ExecutionTimeLimit).TotalMinutes)M" RestartInterval = "PT$([System.TimeSpan]::Parse($testParameters.RestartInterval).TotalMinutes)M" @@ -1280,8 +1282,8 @@ try ) Settings = [pscustomobject] @{ IdleSettings = @{ - WaitTimeout = "PT$([System.TimeSpan]::Parse($testParameters.IdleWaitTimeout).TotalMinutes + 1)M" - IdleDuration = "PT$([System.TimeSpan]::Parse($testParameters.IdleDuration).TotalMinutes + 1)M" + WaitTimeout = "PT$([System.TimeSpan]::Parse($testParameters.IdleWaitTimeout).TotalMinutes + 1)M" + IdleDuration = "PT$([System.TimeSpan]::Parse($testParameters.IdleDuration).TotalMinutes + 1)M" } ExecutionTimeLimit = "PT$([System.TimeSpan]::Parse($testParameters.ExecutionTimeLimit).TotalMinutes)M" RestartInterval = "PT$([System.TimeSpan]::Parse($testParameters.RestartInterval).TotalMinutes)M" @@ -1457,8 +1459,8 @@ try Context 'When a built-in scheduled task exists and is enabled, but it should be disabled and the trigger type is not recognized' { $testParameters = $getTargetResourceParameters + @{ - Enable = $false - Verbose = $true + Enable = $false + Verbose = $true } Mock -CommandName Get-ScheduledTask -MockWith { @@ -1518,9 +1520,9 @@ try Execute = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' } Triggers = [pscustomobject] @{ - Delay = 'PT1M' + Delay = 'PT1M' Subscription = $testParameters.EventSubscription - CimClass = @{ + CimClass = @{ CimClassName = 'MSFT_TaskEventTrigger' } } @@ -1589,9 +1591,9 @@ try Execute = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' } Triggers = [pscustomobject] @{ - Delay = 'PT1M' + Delay = 'PT1M' Subscription = '' - CimClass = @{ + CimClass = @{ CimClassName = 'MSFT_TaskEventTrigger' } } @@ -1642,9 +1644,9 @@ try Execute = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' } Triggers = [pscustomobject] @{ - Delay = 'PT1M' + Delay = 'PT1M' Subscription = $testParameters.EventSubscription - CimClass = @{ + CimClass = @{ CimClassName = 'MSFT_TaskEventTrigger' } } @@ -1721,7 +1723,7 @@ try } ) Principal = [pscustomobject] @{ - UserId = $testParameters.BuiltInAccount + UserId = $testParameters.BuiltInAccount LogonType = 'ServiceAccount' } } @@ -1759,7 +1761,7 @@ try It 'Should call Register-ScheduledTask with the name of the Group Managed Service Account' { Set-TargetResource @testParameters Assert-MockCalled -CommandName Register-ScheduledTask -Times 1 -Scope It -ParameterFilter { - $User -eq $null -and $Inputobject.Principal.UserId -eq $testParameters.ExecuteAsGMSA + $User -eq $null -and $Inputobject.Principal.UserId -eq $testParameters.ExecuteAsGMSA } } @@ -1809,12 +1811,12 @@ try Context 'When a scheduled task Group Managed Service Account is changed' { $testParameters = $getTargetResourceParameters + @{ - ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' - ScheduleType = 'Once' - RepeatInterval = (New-TimeSpan -Minutes 15).ToString() - RepetitionDuration = (New-TimeSpan -Hours 8).ToString() - ExecuteAsGMSA = 'DOMAIN\gMSA$' - Verbose = $true + ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' + ScheduleType = 'Once' + RepeatInterval = (New-TimeSpan -Minutes 15).ToString() + RepetitionDuration = (New-TimeSpan -Hours 8).ToString() + ExecuteAsGMSA = 'DOMAIN\gMSA$' + Verbose = $true } Mock -CommandName Get-ScheduledTask -MockWith { @@ -1863,7 +1865,7 @@ try } Context 'When a scheduled task is created and synchronize across time zone is disabled' { - $startTimeString = '2018-10-01T01:00:00' + $startTimeString = '2018-10-01T01:00:00' $startTimeStringWithOffset = '2018-10-01T01:00:00' + (Get-Date -Format 'zzz') $testParameters = $getTargetResourceParameters + @{ ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' @@ -1875,14 +1877,14 @@ try Mock -CommandName Get-ScheduledTask -MockWith { @{ - TaskName = $testParameters.TaskName - TaskPath = $testParameters.TaskPath - Actions = @( + TaskName = $testParameters.TaskName + TaskPath = $testParameters.TaskPath + Actions = @( [pscustomobject] @{ Execute = $testParameters.ActionExecutable } ) - Triggers = @( + Triggers = @( [pscustomobject] @{ StartBoundary = $startTimeString CimClass = @{ @@ -1905,14 +1907,14 @@ try Mock -CommandName Get-ScheduledTask -MockWith { @{ - TaskName = $testParameters.TaskName - TaskPath = $testParameters.TaskPath - Actions = @( + TaskName = $testParameters.TaskName + TaskPath = $testParameters.TaskPath + Actions = @( [pscustomobject] @{ Execute = $testParameters.ActionExecutable } ) - Triggers = @( + Triggers = @( [pscustomobject] @{ StartBoundary = $startTimeStringWithOffset CimClass = @{ @@ -1937,7 +1939,7 @@ try } Context 'When a scheduled task is created and synchronize across time zone is enabled' { - $startTimeString = '2018-10-01T01:00:00' + $startTimeString = '2018-10-01T01:00:00' $startTimeStringWithOffset = '2018-10-01T01:00:00' + (Get-Date -Format 'zzz') $testParameters = $getTargetResourceParameters + @{ ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' @@ -1949,14 +1951,14 @@ try Mock -CommandName Get-ScheduledTask -MockWith { @{ - TaskName = $testParameters.TaskName - TaskPath = $testParameters.TaskPath - Actions = @( + TaskName = $testParameters.TaskName + TaskPath = $testParameters.TaskPath + Actions = @( [pscustomobject] @{ Execute = $testParameters.ActionExecutable } ) - Triggers = @( + Triggers = @( [pscustomobject] @{ StartBoundary = $startTimeStringWithOffset CimClass = @{ @@ -1979,14 +1981,14 @@ try Mock -CommandName Get-ScheduledTask -MockWith { @{ - TaskName = $testParameters.TaskName - TaskPath = $testParameters.TaskPath - Actions = @( + TaskName = $testParameters.TaskName + TaskPath = $testParameters.TaskPath + Actions = @( [pscustomobject] @{ Execute = $testParameters.ActionExecutable } ) - Triggers = @( + Triggers = @( [pscustomobject] @{ StartBoundary = $startTimeString CimClass = @{ @@ -2011,7 +2013,7 @@ try } Context 'When a scheduled task is configured to SynchronizeAcrossTimeZone and the ScheduleType is not Once, Daily or Weekly' { - $startTimeString = '2018-10-01T01:00:00' + $startTimeString = '2018-10-01T01:00:00' $testParameters = $getTargetResourceParameters + @{ ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' StartTime = Get-Date -Date $startTimeString @@ -2028,26 +2030,26 @@ try Context 'When a scheduled task is configured with the ScheduleType AtLogon and is in desired state' { $startTimeString = '2018-10-01T01:00:00' $testParameters = $getTargetResourceParameters + @{ - ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' - StartTime = Get-Date -Date $startTimeString - ScheduleType = 'AtLogon' - Delay = '00:01:00' - Enable = $true - Verbose = $true + ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' + StartTime = Get-Date -Date $startTimeString + ScheduleType = 'AtLogon' + Delay = '00:01:00' + Enable = $true + Verbose = $true } Mock -CommandName Get-ScheduledTask -MockWith { @{ - TaskName = $testParameters.TaskName - TaskPath = $testParameters.TaskPath - Actions = @( + TaskName = $testParameters.TaskName + TaskPath = $testParameters.TaskPath + Actions = @( [pscustomobject] @{ Execute = $testParameters.ActionExecutable } ) - Triggers = @( + Triggers = @( [pscustomobject] @{ - Delay = 'PT1M' + Delay = 'PT1M' StartBoundary = $startTimeString CimClass = @{ CimClassName = 'MSFT_TaskLogonTrigger' @@ -2076,25 +2078,25 @@ try Context 'When a scheduled task is configured with the ScheduleType AtStartup and is in desired state' { $testParameters = $getTargetResourceParameters + @{ - ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' - ScheduleType = 'AtStartup' - Delay = '00:01:00' - Enable = $true - Verbose = $true + ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' + ScheduleType = 'AtStartup' + Delay = '00:01:00' + Enable = $true + Verbose = $true } Mock -CommandName Get-ScheduledTask -MockWith { @{ - TaskName = $testParameters.TaskName - TaskPath = $testParameters.TaskPath - Actions = @( + TaskName = $testParameters.TaskName + TaskPath = $testParameters.TaskPath + Actions = @( [pscustomobject] @{ Execute = $testParameters.ActionExecutable } ) - Triggers = @( + Triggers = @( [pscustomobject] @{ - Delay = 'PT1M' + Delay = 'PT1M' StartBoundary = '' CimClass = @{ CimClassName = 'MSFT_TaskBootTrigger' @@ -2123,15 +2125,15 @@ try Context 'When a scheduled task is configured with a description that contains various forms of whitespace but is in the desired state' { <# This test verifies issue #258: - https://github.com/PowerShell/ComputerManagementDsc/issues/258 + https://github.com/dsccommunity/ComputerManagementDsc/issues/258 #> $testParameters = $getTargetResourceParameters + @{ - ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' - Description = "`t`n`r test description `t`n`r" - ScheduleType = 'AtStartup' - Delay = '00:01:00' - Enable = $true - Verbose = $true + ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' + Description = "`t`n`r test description `t`n`r" + ScheduleType = 'AtStartup' + Delay = '00:01:00' + Enable = $true + Verbose = $true } Mock -CommandName Get-ScheduledTask -MockWith { @@ -2139,21 +2141,21 @@ try TaskName = $testParameters.TaskName TaskPath = $testParameters.TaskPath Description = 'test description' - Actions = @( + Actions = @( [pscustomobject] @{ Execute = $testParameters.ActionExecutable } ) - Triggers = @( + Triggers = @( [pscustomobject] @{ - Delay = 'PT1M' + Delay = 'PT1M' StartBoundary = '' CimClass = @{ CimClassName = 'MSFT_TaskBootTrigger' } } ) - Settings = [pscustomobject] @{ + Settings = [pscustomobject] @{ Enabled = $testParameters.Enable } } @@ -2174,7 +2176,7 @@ try } } - Describe 'MSFT_ScheduledTask\Test-DateStringContainsTimeZone' { + Describe 'DSC_ScheduledTask\Test-DateStringContainsTimeZone' { Context 'When the date string contains a date without a timezone' { It 'Should return $false' { Test-DateStringContainsTimeZone -DateString '2018-10-01T01:00:00' | Should -BeFalse @@ -2188,11 +2190,8 @@ try } } } - #endregion } finally { - #region FOOTER - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion + Invoke-TestCleanup } diff --git a/Tests/Unit/MSFT_SmbServerConfiguration.Tests.ps1 b/tests/Unit/DSC_SmbServerConfiguration.Tests.ps1 similarity index 91% rename from Tests/Unit/MSFT_SmbServerConfiguration.Tests.ps1 rename to tests/Unit/DSC_SmbServerConfiguration.Tests.ps1 index 572ca376..0361ecc6 100644 --- a/Tests/Unit/MSFT_SmbServerConfiguration.Tests.ps1 +++ b/tests/Unit/DSC_SmbServerConfiguration.Tests.ps1 @@ -1,41 +1,37 @@ -#region HEADER $script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_SmbServerConfiguration' +$script:dscResourceName = 'DSC_SmbServerConfiguration' -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global - -# Unit Test Template Version: 1.2.4 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +function Invoke-TestSetup { - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -ResourceType 'Mof' ` - -TestType Unit -#endregion HEADER + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' -function Invoke-TestSetup -{ + Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') } function Invoke-TestCleanup { - Restore-TestEnvironment -TestEnvironment $TestEnvironment + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } +Invoke-TestSetup + +# Begin Testing try { - Invoke-TestSetup - InModuleScope $script:DSCResourceName { - $testCases = @( @{ smbSetting = 'AnnounceComment' @@ -300,7 +296,7 @@ try ValidateTargetName = $true } - Describe 'MSFT_SmbServerConfiguration\Get-TargetResource' -Tag 'Get' { + Describe 'DSC_SmbServerConfiguration\Get-TargetResource' -Tag 'Get' { Context 'When getting the Target Resource information' { It 'Should get the current SMB server configuration state' { $SmbServerConfiguration = Get-TargetResource -IsSingleInstance Yes @@ -346,12 +342,12 @@ try $SmbServerConfiguration.ValidateAliasNotCircular | Should -Not -BeNullOrEmpty $SmbServerConfiguration.ValidateShareScope | Should -Not -BeNullOrEmpty $SmbServerConfiguration.ValidateShareScopeNotAliased | Should -Not -BeNullOrEmpty - $SmbServerConfiguration.ValidateTargetName| Should -Not -BeNullOrEmpty + $SmbServerConfiguration.ValidateTargetName | Should -Not -BeNullOrEmpty } } } - Describe 'MSFT_SmbServerConfiguration\Test-TargetResource' -Tag 'Test' { + Describe 'DSC_SmbServerConfiguration\Test-TargetResource' -Tag 'Test' { Context 'When the SMB Server is in the desired state' { It 'Test-TargetResource should return true' { Mock -CommandName Get-SmbServerConfiguration { return $mocks.DefaultSettings } @@ -378,7 +374,7 @@ try } } - Describe 'MSFT_SmbServerConfiguration\Set-TargetResource' -Tag 'Set' { + Describe 'DSC_SmbServerConfiguration\Set-TargetResource' -Tag 'Set' { Context 'When configuration is required' { It 'Runs the Set-SmbServerConfiguration cmdlet when the needs to be changed' -TestCases $testCases { param ($smbSetting, $newValue) diff --git a/Tests/Unit/MSFT_SmbShare.Tests.ps1 b/tests/Unit/DSC_SmbShare.Tests.ps1 similarity index 95% rename from Tests/Unit/MSFT_SmbShare.Tests.ps1 rename to tests/Unit/DSC_SmbShare.Tests.ps1 index e1df49fb..af2fbd01 100644 --- a/Tests/Unit/MSFT_SmbShare.Tests.ps1 +++ b/tests/Unit/DSC_SmbShare.Tests.ps1 @@ -1,40 +1,37 @@ -#region HEADER $script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_SmbShare' +$script:dscResourceName = 'DSC_SmbShare' -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global - -# Unit Test Template Version: 1.2.4 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +function Invoke-TestSetup { - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -ResourceType 'Mof' ` - -TestType Unit -#endregion HEADER + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' -function Invoke-TestSetup -{ + Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') } function Invoke-TestCleanup { - Restore-TestEnvironment -TestEnvironment $TestEnvironment + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } +Invoke-TestSetup + +# Begin Testing try { - Invoke-TestSetup - - InModuleScope $script:DSCResourceName { + InModuleScope $script:dscResourceName { $mockShareName = 'TestShare' $mockChangePermissionUserName = @('User1') $mockReadPermissionUserName = @('User2') @@ -103,7 +100,7 @@ try ) ) - Describe 'MSFT_SmbShare\Get-TargetResource' -Tag 'Get' { + Describe 'DSC_SmbShare\Get-TargetResource' -Tag 'Get' { Context 'When the system is in the desired state' { BeforeAll { Mock -CommandName Get-SmbShare -MockWith { @@ -179,7 +176,7 @@ try } } - Describe 'MSFT_SmbShare\Set-TargetResource' -Tag 'Set' { + Describe 'DSC_SmbShare\Set-TargetResource' -Tag 'Set' { Context 'When the system is not in the desired state' { BeforeAll { Mock -CommandName New-SmbShare @@ -346,8 +343,8 @@ try Context 'When the share exists, but on the wrong path and recreate is allowed' { Mock -CommandName Get-TargetResource -MockWith { return @{ - Name = $mockSmbShare.Name - Path = $mockSmbShare.Path + Name = $mockSmbShare.Name + Path = $mockSmbShare.Path Ensure = 'Present' } } @@ -368,8 +365,8 @@ try Context 'When the share exists, but on the wrong path and recreate is not allowed' { Mock -CommandName Get-TargetResource -MockWith { return @{ - Name = $mockSmbShare.Name - Path = $mockSmbShare.Path + Name = $mockSmbShare.Name + Path = $mockSmbShare.Path Ensure = 'Present' } } @@ -391,18 +388,18 @@ try Context 'When the share exists, but on the wrong scope and recreate is allowed' { Mock -CommandName Get-TargetResource -MockWith { return @{ - Name = $mockSmbShare.Name - Path = $mockSmbShare.Path + Name = $mockSmbShare.Name + Path = $mockSmbShare.Path ScopeName = $mockSmbShare.ScopeName - Ensure = 'Present' + Ensure = 'Present' } } $setTargetResourceParameters = @{ - Name = $mockSmbShare.Name - Path = $mockSmbShare.Path + Name = $mockSmbShare.Name + Path = $mockSmbShare.Path ScopeName = 'clustergroup1' - Force = $true + Force = $true } It 'Should drop and recreate the share' { @@ -415,18 +412,18 @@ try Context 'When the share exists, but on the wrong scope and recreate is not allowed' { Mock -CommandName Get-TargetResource -MockWith { return @{ - Name = $mockSmbShare.Name - Path = $mockSmbShare.Path + Name = $mockSmbShare.Name + Path = $mockSmbShare.Path ScopeName = $mockSmbShare.ScopeName - Ensure = 'Present' + Ensure = 'Present' } } $setTargetResourceParameters = @{ - Name = $mockSmbShare.Name - Path = $mockSmbShare.Path + Name = $mockSmbShare.Name + Path = $mockSmbShare.Path ScopeName = 'clustergroup1' - Force = $false + Force = $false } It 'Should display a warning with the message the share cannot be updated' { @@ -439,19 +436,19 @@ try } } - Describe 'MSFT_SmbShare\Test-TargetResource' -Tag 'Test' { + Describe 'DSC_SmbShare\Test-TargetResource' -Tag 'Test' { Context 'When the system is not in the desired state' { Context 'When no member are provided in any of the access permission collections' { BeforeAll { $testTargetResourceParameters = @{ - Name = $mockShareName - Path = 'TestDrive:\Temp' - FullAccess = @() - ChangeAccess = @() - ReadAccess = @() - NoAccess = @() - Ensure = 'Present' - Verbose = $true + Name = $mockShareName + Path = 'TestDrive:\Temp' + FullAccess = @() + ChangeAccess = @() + ReadAccess = @() + NoAccess = @() + Ensure = 'Present' + Verbose = $true } } @@ -731,7 +728,7 @@ try } } - Describe 'MSFT_SmbShare\Add-SmbShareAccessPermission' -Tag 'Helper' { + Describe 'DSC_SmbShare\Add-SmbShareAccessPermission' -Tag 'Helper' { BeforeAll { Mock -CommandName Grant-SmbShareAccess Mock -CommandName Block-SmbShareAccess @@ -914,7 +911,7 @@ try } } - Describe 'MSFT_SmbShare\Remove-SmbShareAccessPermission' -Tag 'Helper' { + Describe 'DSC_SmbShare\Remove-SmbShareAccessPermission' -Tag 'Helper' { BeforeAll { Mock -CommandName Revoke-SmbShareAccess Mock -CommandName Unblock-SmbShareAccess @@ -1120,7 +1117,7 @@ try } } - Describe 'MSFT_SmbShare\Assert-AccessPermissionParameters' -Tag 'Helper' { + Describe 'DSC_SmbShare\Assert-AccessPermissionParameters' -Tag 'Helper' { Context 'When asserting correct provided access permissions parameters' { Context 'When providing at least one member in one of the access permission collections' { BeforeAll { diff --git a/Tests/Unit/MSFT_SystemLocale.Tests.ps1 b/tests/Unit/DSC_SystemLocale.Tests.ps1 similarity index 74% rename from Tests/Unit/MSFT_SystemLocale.Tests.ps1 rename to tests/Unit/DSC_SystemLocale.Tests.ps1 index 22997225..b4736c76 100644 --- a/Tests/Unit/MSFT_SystemLocale.Tests.ps1 +++ b/tests/Unit/DSC_SystemLocale.Tests.ps1 @@ -1,33 +1,42 @@ -$script:DSCModuleName = 'ComputerManagementDsc' -$script:DSCResourceName = 'MSFT_SystemLocale' +$script:dscModuleName = 'ComputerManagementDsc' +$script:dscResourceName = 'DSC_SystemLocale' -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') +} -#region HEADER -# Unit Test Template Version: 1.1.0 -[String] $moduleRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path)) -if ( (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +function Invoke-TestCleanup { - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\')) + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } -Import-Module (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:DSCModuleName ` - -DSCResourceName $script:DSCResourceName ` - -TestType Unit -#endregion HEADER +Invoke-TestSetup # Begin Testing try { - InModuleScope $script:DSCResourceName { + InModuleScope $script:dscResourceName { $script:testSystemLocale = 'en-US' $script:testAltSystemLocale = 'en-AU' $script:badSystemLocale = 'zzz-ZZZ' - Describe 'MSFT_SystemLocale\Get-TargetResource' { + Describe 'DSC_SystemLocale\Get-TargetResource' { Mock -CommandName Get-WinSystemLocale ` -MockWith { @{ LCID = '1033' @@ -50,7 +59,7 @@ try } } - Describe 'MSFT_SystemLocale\Set-TargetResource' { + Describe 'DSC_SystemLocale\Set-TargetResource' { Mock -CommandName Get-WinSystemLocale ` -MockWith { @{ LCID = '1033' @@ -93,7 +102,7 @@ try } } - Describe 'MSFT_SystemLocale\Test-TargetResource' { + Describe 'DSC_SystemLocale\Test-TargetResource' { Mock -CommandName Get-WinSystemLocale ` -MockWith { @{ LCID = '1033' @@ -123,7 +132,7 @@ try -IsSingleInstance 'Yes' | Should -BeFalse } - Describe 'MSFT_SystemLocale\Test-SystemLocaleValue' { + Describe 'DSC_SystemLocale\Test-SystemLocaleValue' { It 'Should return true when a valid System Locale is passed' { Test-SystemLocaleValue ` -SystemLocale $script:testSystemLocale | Should -BeTrue @@ -135,11 +144,9 @@ try } } } - } #end InModuleScope $DSCResourceName + } } finally { - #region FOOTER - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion + Invoke-TestCleanup } diff --git a/Tests/Unit/MSFT_TimeZone.Tests.ps1 b/tests/Unit/DSC_TimeZone.Tests.ps1 similarity index 67% rename from Tests/Unit/MSFT_TimeZone.Tests.ps1 rename to tests/Unit/DSC_TimeZone.Tests.ps1 index b8b2d13d..2ab309b4 100644 --- a/Tests/Unit/MSFT_TimeZone.Tests.ps1 +++ b/tests/Unit/DSC_TimeZone.Tests.ps1 @@ -1,34 +1,38 @@ -#region HEADER $script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_TimeZone' +$script:dscResourceName = 'DSC_TimeZone' -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global - -# Unit Test Template Version: 1.2.4 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +function Invoke-TestSetup { - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') } -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -ResourceType 'Mof' ` - -TestType Unit -#endregion HEADER +Invoke-TestSetup # Begin Testing try { - #region Pester Tests InModuleScope $script:dscResourceName { - $script:dscResourceName = 'MSFT_TimeZone' - - Describe "$($script:dscResourceName) MOF single instance schema" { + Describe 'DSC_TimeZone MOF single instance schema' { It 'Should have mandatory IsSingleInstance parameter and one other parameter' { $timeZoneResource = Get-DscResource -Name TimeZone @@ -42,7 +46,7 @@ try } } - Describe "$($script:dscResourceName)\Get-TargetResource" { + Describe 'DSC_TimeZone\Get-TargetResource' { Mock ` -CommandName Get-TimeZoneId ` -MockWith { 'Pacific Standard Time' } @@ -61,7 +65,7 @@ try } } - Describe "$($script:dscResourceName)\Set-TargetResource" { + Describe 'DSC_TimeZone\Set-TargetResource' { Mock ` -CommandName Set-TimeZoneId @@ -98,7 +102,7 @@ try } } - Describe "$($script:dscResourceName)\Test-TargetResource" { + Describe 'DSC_TimeZone\Test-TargetResource' { Mock ` -ModuleName ComputerManagementDsc.Common ` -CommandName Get-TimeZoneId ` @@ -118,12 +122,9 @@ try -Verbose | Should -BeFalse } } - } #end InModuleScope $DSCResourceName - #endregion + } } finally { - #region FOOTER - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion + Invoke-TestCleanup } diff --git a/Tests/Unit/MSFT_VirtualMemory.Tests.ps1 b/tests/Unit/DSC_VirtualMemory.Tests.ps1 similarity index 96% rename from Tests/Unit/MSFT_VirtualMemory.Tests.ps1 rename to tests/Unit/DSC_VirtualMemory.Tests.ps1 index 137ef40d..2dcbd138 100644 --- a/Tests/Unit/MSFT_VirtualMemory.Tests.ps1 +++ b/tests/Unit/DSC_VirtualMemory.Tests.ps1 @@ -1,41 +1,37 @@ -#region HEADER $script:dscModuleName = 'ComputerManagementDsc' -$script:dscResourceName = 'MSFT_VirtualMemory' +$script:dscResourceName = 'DSC_VirtualMemory' -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global - -# Unit Test Template Version: 1.2.4 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +function Invoke-TestSetup { - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:dscModuleName ` - -DSCResourceName $script:dscResourceName ` - -ResourceType 'Mof' ` - -TestType Unit -#endregion HEADER + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' -function Invoke-TestSetup -{ + Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') } function Invoke-TestCleanup { - Restore-TestEnvironment -TestEnvironment $TestEnvironment + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } +Invoke-TestSetup + # Begin Testing try { - Invoke-TestSetup - - InModuleScope 'MSFT_VirtualMemory' { + InModuleScope $script:dscResourceName { <# Remove-CimInstance overridden to enable PSObject to be passed to mocked version. @@ -119,7 +115,7 @@ try $Filter -eq "SettingID='pagefile.sys @ $testDrive'" } - Describe 'MSFT_VirtualMemory\Get-TargetResource' { + Describe 'DSC_VirtualMemory\Get-TargetResource' { BeforeEach { $testParameters = @{ Drive = $testDrive @@ -248,7 +244,7 @@ try } } - Describe 'MSFT_VirtualMemory\Set-TargetResource' { + Describe 'DSC_VirtualMemory\Set-TargetResource' { BeforeEach { <# These mocks are to handle when disk drive @@ -680,7 +676,7 @@ try } } - Describe 'MSFT_VirtualMemory\Test-TargetResource' { + Describe 'DSC_VirtualMemory\Test-TargetResource' { Context 'In desired state' { Context 'When automatic managed page file is enabled' { Mock ` @@ -1033,7 +1029,7 @@ try } } - Describe 'MSFT_VirtualMemory\Get-PageFileSetting' { + Describe 'DSC_VirtualMemory\Get-PageFileSetting' { Context "Page file defined on drive $testDrive" { Mock ` -CommandName Get-CimInstance ` @@ -1062,7 +1058,7 @@ try } } - Describe 'MSFT_VirtualMemory\Set-PageFileSetting' { + Describe 'DSC_VirtualMemory\Set-PageFileSetting' { Context "Set page file settings on drive $testDrive" { Mock ` -CommandName Set-CimInstance ` @@ -1087,7 +1083,7 @@ try } } - Describe 'MSFT_VirtualMemory\Set-AutoManagePaging' { + Describe 'DSC_VirtualMemory\Set-AutoManagePaging' { Context "Enable auto managed page file" { Mock ` -CommandName Set-CimInstance ` @@ -1123,7 +1119,7 @@ try } } - Describe 'MSFT_VirtualMemory\New-PageFile' { + Describe 'DSC_VirtualMemory\New-PageFile' { Context "Create a new page file" { Mock ` -CommandName New-CimInstance ` diff --git a/tests/Unit/DSC_WindowsCapability.Tests.ps1 b/tests/Unit/DSC_WindowsCapability.Tests.ps1 new file mode 100644 index 00000000..019c62b5 --- /dev/null +++ b/tests/Unit/DSC_WindowsCapability.Tests.ps1 @@ -0,0 +1,463 @@ +$script:dscModuleName = 'ComputerManagementDsc' +$script:dscResourceName = 'DSC_WindowsCapability' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + $script:testCapabilityName = 'Test' + + $script:testAndSetTargetResourceParametersPresent = @{ + Name = $script:testCapabilityName + Ensure = 'Present' + Verbose = $true + } + + $script:testAndSetTargetResourceParametersAbsent = @{ + Name = $script:testCapabilityName + Ensure = 'Absent' + Verbose = $true + } + + $script:getWindowsCapabilityDoesNotExist = { + @{ + Name = '' + State = '' + LogLevel = 'Errors' + LogPath = 'LogPath' + } + } + + $script:getWindowsCapabilityIsInstalled = { + @{ + Name = $script:testCapabilityName + State = 'Installed' + LogLevel = 'Errors' + LogPath = 'LogPath' + } + } + + $script:getWindowsCapabilityIsNotInstalled = { + @{ + Name = $script:testCapabilityName + State = 'NotPresent' + LogLevel = 'Errors' + LogPath = 'LogPath' + } + } + + function Get-WindowsCapability + { + [CmdletBinding()] + param + ( + [Parameter()] + [System.String] + $Name, + + [Parameter()] + [Switch] + $Online = $true + ) + } + + function Add-WindowsCapability + { + [CmdletBinding()] + param + ( + [Parameter()] + [System.String] + $Name, + + [Parameter()] + [Switch] + $Online = $true + ) + } + + function Remove-WindowsCapability + { + [CmdletBinding()] + param + ( + [Parameter()] + [System.String] + $Name, + + [Parameter()] + [Switch] + $Online = $true + ) + } + + Describe 'DSC_WindowsCapability\Get-TargetResource' { + Context 'When a Windows Capability is installed' { + Mock -CommandName Get-WindowsCapability ` + -MockWith $script:getWindowsCapabilityIsInstalled + + It 'Should not throw an exception' { + { + $script:getTargetResourceResult = Get-TargetResource ` + -Name $script:testCapabilityName -Verbose + } | Should -Not -Throw + } + + It 'Should return expected result' { + $script:getTargetResourceResult.Name | Should -Be $script:testCapabilityName + $script:getTargetResourceResult.Ensure | Should -Be 'Present' + $script:getTargetResourceResult.LogLevel | Should -Be 'Errors' + $script:getTargetResourceResult.LogPath | Should -Be 'LogPath' + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-WindowsCapability ` + -ParameterFilter { + $Name -eq $script:testCapabilityName -and ` + $Online -eq $true + } ` + -Exactly ` + -Times 1 + } + } + + Context 'When a Windows Capability is not installed' { + Mock -CommandName Get-WindowsCapability ` + -MockWith $script:getWindowsCapabilityIsNotInstalled + + It 'Should not throw an exception' { + { + $script:getTargetResourceResult = Get-TargetResource ` + -Name $script:testCapabilityName -Verbose + } | Should -Not -Throw + } + + It 'Should return expected result' { + $script:getTargetResourceResult.Name | Should -Be $script:testCapabilityName + $script:getTargetResourceResult.Ensure | Should -Be 'Absent' + $script:getTargetResourceResult.LogLevel | Should -Be 'Errors' + $script:getTargetResourceResult.LogPath | Should -Be 'LogPath' + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-WindowsCapability ` + -ParameterFilter { + $Name -eq $script:testCapabilityName -and ` + $Online -eq $true + } ` + -Exactly ` + -Times 1 + } + } + + Context 'When a Windows Capability does not exist' { + Mock -CommandName Get-WindowsCapability ` + -MockWith $script:getWindowsCapabilityDoesNotExist + + $errorRecord = Get-InvalidArgumentRecord ` + -Message ($script:localizedData.CapabilityNameNotFound -f $script:testCapabilityName) ` + -ArgumentName 'Name' + + It 'Should throw expected exception' { + { + $script:getTargetResourceResult = Get-TargetResource ` + -Name $script:testCapabilityName -Verbose + } | Should -Throw $errorRecord + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-WindowsCapability ` + -ParameterFilter { + $Name -eq $script:testCapabilityName -and ` + $Online -eq $true + } ` + -Exactly ` + -Times 1 + } + } + } + + Describe 'DSC_WindowsCapability\Test-TargetResource' { + Context 'When a Windows Capability is installed and should be' { + Mock -CommandName Get-WindowsCapability ` + -MockWith $script:getWindowsCapabilityIsInstalled + + It 'Should not throw an exception' { + { + $script:testTargetResourceResult = Test-TargetResource @script:testAndSetTargetResourceParametersPresent + } | Should -Not -Throw + } + + It 'Should return true' { + $script:testTargetResourceResult | Should -BeTrue + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-WindowsCapability ` + -ParameterFilter { + $Name -eq $script:testCapabilityName -and ` + $Online -eq $true + } ` + -Exactly ` + -Times 1 + } + } + + Context 'When a Windows Capability is not installed and should be' { + Mock -CommandName Get-WindowsCapability ` + -MockWith $script:getWindowsCapabilityIsNotInstalled + + It 'Should not throw an exception' { + { + $script:testTargetResourceResult = Test-TargetResource @script:testAndSetTargetResourceParametersPresent + } | Should -Not -Throw + } + + It 'Should return false' { + $script:testTargetResourceResult | Should -BeFalse + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-WindowsCapability ` + -ParameterFilter { + $Name -eq $script:testCapabilityName -and ` + $Online -eq $true + } ` + -Exactly ` + -Times 1 + } + } + + Context 'When a Windows Capability is installed and should not be' { + Mock -CommandName Get-WindowsCapability ` + -MockWith $script:getWindowsCapabilityIsInstalled + + It 'Should not throw an exception' { + { + $script:testTargetResourceResult = Test-TargetResource @script:testAndSetTargetResourceParametersAbsent + } | Should -Not -Throw + } + + It 'Should return false' { + $script:testTargetResourceResult | Should -BeFalse + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-WindowsCapability ` + -ParameterFilter { + $Name -eq $script:testCapabilityName -and ` + $Online -eq $true + } ` + -Exactly ` + -Times 1 + } + } + + Context 'When a Windows Capability is not installed and should not be' { + Mock -CommandName Get-WindowsCapability ` + -MockWith $script:getWindowsCapabilityIsNotInstalled + + It 'Should not throw an exception' { + { + $script:testTargetResourceResult = Test-TargetResource @script:testAndSetTargetResourceParametersAbsent + } | Should -Not -Throw + } + + It 'Should return true' { + $script:testTargetResourceResult | Should -BeTrue + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-WindowsCapability ` + -ParameterFilter { + $Name -eq $script:testCapabilityName -and ` + $Online -eq $true + } ` + -Exactly ` + -Times 1 + } + } + } + + Describe 'DSC_WindowsCapability\Set-TargetResource' { + BeforeAll { + Mock -CommandName Add-WindowsCapability + Mock -CommandName Remove-WindowsCapability + } + + Context 'When a Windows Capability is installed and should be' { + Mock -CommandName Get-WindowsCapability ` + -MockWith $script:getWindowsCapabilityIsNotInstalled + + It 'Should not throw an exception' { + { + Set-TargetResource @script:testAndSetTargetResourceParametersAbsent + } | Should -Not -Throw + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-WindowsCapability ` + -ParameterFilter { + $Name -eq $script:testCapabilityName -and ` + $Online -eq $true + } ` + -Exactly ` + -Times 1 + + Assert-MockCalled ` + -CommandName Add-WindowsCapability ` + -Exactly ` + -Times 0 + + Assert-MockCalled ` + -CommandName Remove-WindowsCapability ` + -Exactly ` + -Times 0 + } + } + + Context 'When a Windows Capability is not installed and should be' { + Mock -CommandName Get-WindowsCapability ` + -MockWith $script:getWindowsCapabilityIsNotInstalled + + It 'Should not throw an exception' { + { + Set-TargetResource @script:testAndSetTargetResourceParametersPresent + } | Should -Not -Throw + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-WindowsCapability ` + -ParameterFilter { + $Name -eq $script:testCapabilityName -and ` + $Online -eq $true + } ` + -Exactly ` + -Times 1 + + Assert-MockCalled ` + -CommandName Add-WindowsCapability ` + -ParameterFilter { + $Name -eq $script:testCapabilityName -and ` + $Online -eq $true + } ` + -Exactly ` + -Times 1 + + Assert-MockCalled ` + -CommandName Remove-WindowsCapability ` + -Exactly ` + -Times 0 + } + } + + Context 'When a Windows Capability is installed and should not be' { + Mock -CommandName Get-WindowsCapability ` + -MockWith $script:getWindowsCapabilityIsInstalled + + It 'Should not throw an exception' { + { + Set-TargetResource @script:testAndSetTargetResourceParametersAbsent + } | Should -Not -Throw + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-WindowsCapability ` + -ParameterFilter { + $Name -eq $script:testCapabilityName -and ` + $Online -eq $true + } ` + -Exactly ` + -Times 1 + + Assert-MockCalled ` + -CommandName Add-WindowsCapability ` + -Exactly ` + -Times 0 + + Assert-MockCalled ` + -CommandName Remove-WindowsCapability ` + -ParameterFilter { + $Name -eq $script:testCapabilityName -and ` + $Online -eq $true + } ` + -Exactly ` + -Times 1 + } + } + + Context 'When a Windows Capability is not installed and should not be' { + Mock -CommandName Get-WindowsCapability ` + -MockWith $script:getWindowsCapabilityIsNotInstalled + + It 'Should not throw an exception' { + { + Set-TargetResource @script:testAndSetTargetResourceParametersAbsent + } | Should -Not -Throw + } + + It 'Should call expected mocks' { + Assert-MockCalled ` + -CommandName Get-WindowsCapability ` + -ParameterFilter { + $Name -eq $script:testCapabilityName -and ` + $Online -eq $true + } ` + -Exactly ` + -Times 1 + + Assert-MockCalled ` + -CommandName Add-WindowsCapability ` + -Exactly ` + -Times 0 + + Assert-MockCalled ` + -CommandName Remove-WindowsCapability ` + -Exactly ` + -Times 0 + } + } + } + } +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/DSC_WindowsEventLog.Tests.ps1 b/tests/Unit/DSC_WindowsEventLog.Tests.ps1 new file mode 100644 index 00000000..ddcf4b64 --- /dev/null +++ b/tests/Unit/DSC_WindowsEventLog.Tests.ps1 @@ -0,0 +1,396 @@ +$script:dscModuleName = 'ComputerManagementDsc' +$script:dscResourceName = 'DSC_WindowsEventLog' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +# Begin Testing +try +{ + InModuleScope $script:dscResourceName { + Describe 'DSC_WindowsEventLog\Get-TargetResource' -Tag 'Get' { + + Mock -CommandName Get-WindowsEventLog -MockWith { + $properties = @{ + MaximumSizeInBytes = 4096kb + IsEnabled = $true + LogMode = 'Circular' + LogFilePath = '%SystemRoot%\System32\Winevt\Logs\Application.evtx' + SecurityDescriptor = 'TestDescriptor' + LogRetentionDays = '0' + LogName = 'Application' + } + + return (New-Object -TypeName PSObject -Property $properties) + } + + $results = Get-TargetResource -LogName 'Application' -IsEnabled $true + + It 'Should return an hashtable' { + $results.GetType().Name | Should -Be 'Hashtable' + } + + It 'Should return a Logname Application' { + $results.LogName = 'Application' + } + + It 'Should return a MaximumSizeInBytes of 4096kb' { + $results.MaximumSizeInBytes | Should -Be 4096kb + } + + It 'Should return IsEnabled is true' { + $results.IsEnabled | Should -BeTrue + } + + It 'Should return a LogMode is Circular' { + $results.LogMode | Should -Be 'Circular' + } + + It 'Should return a LogRetentionDays of 0' { + $results.LogRetentionDays | Should -Be 0 + } + + It 'Should return a LogFilePath of %SystemRoot%\System32\Winevt\Logs\Application.evtx' { + $results.LogFilePath | Should -Be "%SystemRoot%\System32\Winevt\Logs\Application.evtx" + } + + It 'Should return SecurityDescriptor with a value TestDescriptor' { + $results.SecurityDescriptor | Should -Be 'TestDescriptor' + } + } + + Describe 'DSC_WindowsEventLog\Test-TargetResource' -Tag 'Test' { + + Mock -CommandName Get-WindowsEventLog -MockWith { + $properties = @{ + MaximumSizeInBytes = 1028kb + IsEnabled = $true + LogMode = 'Circular' + LogFilePath = '%SystemRoot%\System32\Winevt\Logs\Application.evtx' + SecurityDescriptor = 'TestDescriptor' + LogRetentionDays = '7' + LogName = 'Application' + } + + return (New-Object -TypeName PSObject -Property $properties) + } + + Mock -CommandName Get-EventLog -MockWith { + $params = @{ + MinimumRetentionDays = '7' + Log = 'Application' + } + + return (New-Object -TypeName PSObject -Property $params) + } + + It 'Should not throw when passed an valid Logname' { + { Test-TargetResource -LogName 'Application' -IsEnabled $true -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should throw when passed an invalid LogMode' { + { Test-TargetResource -LogName 'Application' -LogMode 'BadLogmode' -IsEnabled $true -ErrorAction Stop } | Should -Throw + } + + It 'Should not throw when passed an valid LogMode' { + { Test-TargetResource -LogName 'Application' -LogMode 'Circular' -IsEnabled $true -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should return $true if Logmode is in desired state' { + Test-TargetResource -LogName 'Application' -LogMode 'Circular' -IsEnabled $true | Should -BeTrue + } + + It 'Should return $false if Logmode is not in desired state' { + Test-TargetResource -LogName 'Application' -LogMode 'AutoBackup' -IsEnabled $false | Should -BeFalse + } + + It 'Should throw when passed an invalid MaximumSizeInBytes below 1028kb' { + { Test-TargetResource -LogName 'Application' -LogMode 'Circular' -IsEnabled $true -MaximumSizeInBytes 1027kb -ErrorAction Stop } | Should -Throw + } + + It 'Shoudl throw when passed an invalid MaximumSizeInBytes above 18014398509481983kb' { + { Test-TargetResource -LogName 'Application' -LogMode 'Circular' -IsEnabled $true -MaximumSizeInBytes 18014398509481983kb -ErrorAction Stop } | Should -Throw + } + + It 'Should return $true if MaximumSizeInBytes is in desired state' { + Test-TargetResource -MaximumSizeInBytes 1028kb -LogName 'Application' -IsEnabled $true | Should -BeTrue + } + + It 'Should return $false if MaximumSizeInBytes is not in desired state' { + Test-TargetResource -MaximumSizeInBytes 2048kb -LogName 'Application' -IsEnabled $true | Should -BeFalse + } + + It 'Should not throw when passed an valid MaximumSizeInBytes' { + { Test-TargetResource -LogName 'Application' -MaximumSizeInBytes 1028kb -IsEnabled $true -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should throw when passed an invalid LogRetentionDays below 1 day' { + { Test-TargetResource -LogName 'Application' -LogMode 'AutoBackup' -IsEnabled $true -LogRetentionDays 0 -ErrorAction Stop } | Should -Throw + } + + It 'Should throw when passed an invalid LogRetentionDays above 365 days' { + { Test-TargetResource -LogName 'Application' -LogMode 'AutoBackup' -IsEnabled $true -LogRetentionDays 366 -ErrorAction Stop } | Should -Throw + } + + It 'Should not throw when passed an valid LogRetentionDays' { + { Test-TargetResource -LogName 'Application' -LogMode 'AutoBackup' -LogRetentionDays 30 -IsEnabled $true -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should return $false if LogRetentionDays is not in desired state' { + Test-TargetResource -LogName 'Application' -IsEnabled $true -LogRetentionDays 13 -LogMode 'AutoBackup' | Should -BeFalse + } + + It 'Should return $true if LogRetentionDays is in desired state' { + Mock -CommandName Get-WindowsEventLog -MockWith { + $properties = @{ + MaximumSizeInBytes = 1028kb + IsEnabled = $true + LogMode = 'AutoBackup' + LogFilePath = '%SystemRoot%\System32\Winevt\Logs\Application.evtx' + SecurityDescriptor = 'TestDescriptor' + LogRetentionDays = '7' + LogName = 'Application' + } + + return (New-Object -TypeName PSObject -Property $properties) + } + + Test-TargetResource -LogName 'Application' -IsEnabled $true -LogRetentionDays 7 -LogMode 'AutoBackup' | Should -BeTrue + } + + It 'Should not throw when passed an invalid LogRetentionDays' { + { Test-TargetResource -LogName 'WrongLog' -LogMode 'AutoBackup' -LogRetentionDays 30 -IsEnabled $true -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should not throw when passed an invalid LogMode with LogRetention' { + { Test-TargetResource -LogName 'Application' -LogMode 'Circular' -LogRetentionDays 30 -IsEnabled $true -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should not throw when passed an valid LogFilePath' { + { Test-TargetResource -LogName 'Application' -IsEnabled $true -LogFilePath '%SystemRoot%\System32\Winevt\Logs\Application.evtx' -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should return $true if LogFilePath is in desired state' { + Test-TargetResource -LogName 'Application' -LogFilePath '%SystemRoot%\System32\Winevt\Logs\Application.evtx' -IsEnabled $true | Should -BeTrue + } + + It 'Should return $false if LogFilePath is not in desired state' { + Test-TargetResource -LogName 'Application' -LogFilePath '%SystemRoot%\System32\Winevt\OtherLogs\Application.evtx' -IsEnabled $true | Should -BeFalse + } + + It 'Should not throw when passed an valid SecurityDescriptor' { + { Test-TargetResource -LogName 'Application' -SecurityDescriptor 'TestDescriptor' -IsEnabled $true -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should return $true if SecurityDescriptor is in desired state' { + Test-TargetResource -LogName 'Application' -SecurityDescriptor 'TestDescriptor' -IsEnabled $true | Should -BeTrue + } + + It 'Should return $false if SecurityDescriptor is not in desired state' { + Test-TargetResource -LogName 'Application' -SecurityDescriptor 'TestTestDescriptor' -IsEnabled $true | Should -BeFalse + } + + It 'Should return $true if IsEnabled is in desired state' { + Test-TargetResource -LogName 'Application' -IsEnabled $true | Should -BeTrue + } + + It 'Should return $false if IsEnabled is not in desired state' { + Test-TargetResource -LogName 'Application' -IsEnabled $false | Should -BeFalse + } + + It 'Should return $false if IsEnabled is not in desired state' { + Mock -CommandName Get-WindowsEventLog -MockWith { + $properties = @{ + MaximumSizeInBytes = 1028kb + IsEnabled = $false + LogName = 'Application' + } + + return (New-Object -TypeName PSObject -Property $properties) + } + + Test-TargetResource -LogName 'Application' -IsEnabled $true | Should -BeFalse + } + + It 'Should return $true if IsEnabled is not in desired state' { + Mock -CommandName Get-WindowsEventLog -MockWith { + $properties = @{ + MaximumSizeInBytes = 1028kb + IsEnabled = $true + LogName = 'Application' + } + + return (New-Object -TypeName PSObject -Property $properties) + } + + Test-TargetResource -LogName 'Application' -IsEnabled $true | Should -BeTrue + } + } + + Describe 'DSC_WindowsEventLog\Set-TargetResource' -Tag 'Set' { + Mock -CommandName Get-WindowsEventLog -MockWith { + $properties = @{ + MaximumSizeInBytes = 5000kb + IsEnabled = $true + LogMode = 'AutoBackup' + LogFilePath = 'c:\logs\test.evtx' + SecurityDescriptor = 'TestDescriptor' + LogRetentionDays = '7' + LogName = 'TestLog' + } + + return (New-Object -TypeName PSObject -Property $properties) + } + + Mock -CommandName Get-EventLog -MockWith { + $params = @{ + MinimumRetentionDays = '7' + Log = 'TestLog' + } + + return (New-Object -TypeName PSObject -Property $params) + } + + It 'Should set MaximumSizeInBytes to 1028kb' { + Mock -CommandName Save-LogFile + Set-TargetResource -MaximumSizeInBytes 1028kb -IsEnabled $true -LogName 'TestLog' + Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 1 -Scope It + } + + It 'MaximumSizeInBytes is in desired state' { + Mock -CommandName Save-LogFile + Set-TargetResource -MaximumSizeInBytes 5000kb -IsEnabled $true -LogName 'TestLog' + Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 0 -Scope It + } + + It 'Should set SecurityDescriptor to OtherTestDescriptor' { + Mock -CommandName Save-LogFile + Set-TargetResource -IsEnabled $true -LogName 'TestLog' -SecurityDescriptor 'OtherTestDescriptor' + Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 1 -Scope It + } + + It 'SecurityDescriptor is in desired state' { + Mock -CommandName Save-LogFile + Set-TargetResource -IsEnabled $true -LogName 'TestLog' -SecurityDescriptor 'TestDescriptor' + Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 0 -Scope It + } + + It 'Should set LogFilePath to default path' { + Mock -CommandName Save-LogFile + Set-TargetResource -IsEnabled $true -LogName 'TestLog' -LogFilePath '%SystemRoot%\System32\Winevt\Logs\Application.evtx' + Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 1 -Scope It + } + + It 'LogFilePath is in desired state' { + Mock -CommandName Save-LogFile + Set-TargetResource -IsEnabled $true -LogName 'TestLog' -LogFilePath 'c:\logs\test.evtx' + Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 0 -Scope It + } + + It 'Should set LogRetentionDays to 14 days' { + Mock -CommandName Set-LogRetentionDays + Set-TargetResource -LogRetentionDays '14' -IsEnabled $true -LogName 'TestLog' -LogMode 'Autobackup' + Assert-MockCalled -CommandName Set-LogRetentionDays -Exactly -Times 1 -Scope It + } + + It 'Should set LogRetentionDays to 32 days, wrong Logmode' { + Mock -CommandName Set-LogRetentionDays + Set-TargetResource -LogRetentionDays '32' -IsEnabled $true -LogName 'TestLog' -LogMode 'Circular' + Assert-MockCalled -CommandName Set-LogRetentionDays -Exactly -Times 0 -Scope It + } + + It 'Should set LogRetentionDays is in desired state' { + Mock -CommandName Set-LogRetentionDays + Set-TargetResource -LogRetentionDays '7' -IsEnabled $true -LogName 'TestLog' -LogMode 'Autobackup' + Assert-MockCalled -CommandName Set-LogRetentionDays -Exactly -Times 0 -Scope It + } + + It 'Should set IsEnabled to false' { + Mock -CommandName Save-LogFile + Set-TargetResource -IsEnabled $false -LogName 'TestLog' + Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 1 -Scope It + } + + It 'IsEnabled is in desired state' { + Mock -CommandName Save-LogFile + Set-TargetResource -IsEnabled $true -LogName 'TestLog' + Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 0 -Scope It + } + + It 'IsEnabled is not in desired state' { + Mock -CommandName Save-LogFile + Set-TargetResource -IsEnabled $false -LogName 'TestLog' + Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 1 -Scope It + } + + It 'Should throw if IsEnabled is not in desired state' { + Mock -CommandName Save-LogFile + Mock -CommandName Get-WindowsEventLog -MockWith { throw } + { Set-TargetResource -LogName 'SomeLog' -IsEnabled $false } | Should -Throw + } + + It 'IsEnabled is not in desired state' { + Mock -CommandName Get-WindowsEventLog -MockWith { + $properties = @{ + MaximumSizeInBytes = 5000kb + IsEnabled = $false + LogMode = 'AutoBackup' + LogFilePath = 'c:\logs\test.evtx' + SecurityDescriptor = 'TestDescriptor' + LogRetentionDays = '7' + LogName = 'TestLog' + } + + return (New-Object -TypeName PSObject -Property $properties) + } + + Set-TargetResource -IsEnabled $true -LogName 'TestLog' + Assert-MockCalled -CommandName Save-LogFile -Exactly -Times 1 -Scope It + } + + Describe 'DSC_WindowsEventLog\Save-LogFile' -Tag 'Helper' { + Mock -CommandName Limit-Eventlog -MockWith { throw } + + It 'Should throw if we are unable to get a log' { + { Limit-Eventlog -LogName 'Application' -OverflowAction 'OverwriteOlder' -RetentionDays 30 } | Should -Throw + } + } + + Describe 'DSC_WindowsEventLog\Set-LogRetentionDays' -Tag 'Helper' { + Mock -CommandName Limit-Eventlog -MockWith { throw } + + It 'Should throw if we are unable to get a log' { + { Limit-Eventlog -LogName 'Application' -OverflowAction 'OverwriteOlder' -RetentionDays 30 } | Should -Throw + } + } + } + } +} +finally +{ + Invoke-TestCleanup +}