├── .MetaTestOptIn.json ├── .codecov.yml ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── General.md │ ├── Problem_with_resource.md │ └── Resource_proposal.md ├── PULL_REQUEST_TEMPLATE.md └── stale.yml ├── .gitignore ├── .vscode ├── analyzersettings.psd1 └── settings.json ├── CHANGELOG.md ├── DscResources ├── CommonResourceHelper.psm1 ├── GroupSet │ ├── GroupSet.psd1 │ └── GroupSet.schema.psm1 ├── MSFT_Archive │ ├── MSFT_Archive.psm1 │ ├── MSFT_Archive.schema.mof │ └── en-US │ │ ├── MSFT_Archive.schema.mfl │ │ └── MSFT_Archive.strings.psd1 ├── MSFT_EnvironmentResource │ ├── MSFT_EnvironmentResource.psm1 │ ├── MSFT_EnvironmentResource.schema.mof │ └── en-US │ │ ├── MSFT_EnvironmentResource.schema.mfl │ │ └── MSFT_EnvironmentResource.strings.psd1 ├── MSFT_GroupResource │ ├── MSFT_GroupResource.psm1 │ ├── MSFT_GroupResource.schema.mof │ └── en-US │ │ ├── MSFT_GroupResource.schema.mfl │ │ └── MSFT_GroupResource.strings.psd1 ├── MSFT_MsiPackage │ ├── MSFT_MsiPackage.psm1 │ ├── MSFT_MsiPackage.schema.mof │ └── en-US │ │ ├── MSFT_MsiPackage.schema.mfl │ │ └── MSFT_MsiPackage.strings.psd1 ├── MSFT_RegistryResource │ ├── MSFT_RegistryResource.psm1 │ ├── MSFT_RegistryResource.schema.mof │ └── en-US │ │ ├── MSFT_RegistryResource.schema.mfl │ │ └── MSFT_RegistryResource.strings.psd1 ├── MSFT_ScriptResource │ ├── MSFT_ScriptResource.psm1 │ ├── MSFT_ScriptResource.schema.mof │ └── en-US │ │ ├── MSFT_ScriptResource.schema.mfl │ │ └── MSFT_ScriptResource.strings.psd1 ├── MSFT_ServiceResource │ ├── MSFT_ServiceResource.psm1 │ ├── MSFT_ServiceResource.schema.mof │ └── en-US │ │ ├── MSFT_ServiceResource.schema.mfl │ │ └── MSFT_ServiceResource.strings.psd1 ├── MSFT_UserResource │ ├── MSFT_UserResource.psm1 │ ├── MSFT_UserResource.schema.mof │ └── en-US │ │ ├── MSFT_UserResource.schema.mfl │ │ └── MSFT_UserResource.strings.psd1 ├── MSFT_WindowsFeature │ ├── MSFT_WindowsFeature.psm1 │ ├── MSFT_WindowsFeature.schema.mof │ └── en-US │ │ ├── MSFT_WindowsFeature.schema.mfl │ │ └── MSFT_WindowsFeature.strings.psd1 ├── MSFT_WindowsOptionalFeature │ ├── MSFT_WindowsOptionalFeature.psm1 │ ├── MSFT_WindowsOptionalFeature.schema.mof │ └── en-US │ │ ├── MSFT_WindowsOptionalFeature.schema.mfl │ │ └── MSFT_WindowsOptionalFeature.strings.psd1 ├── MSFT_WindowsPackageCab │ ├── MSFT_WindowsPackageCab.psm1 │ ├── MSFT_WindowsPackageCab.schema.mof │ └── en-US │ │ ├── MSFT_WindowsPackageCab.schema.mfl │ │ └── MSFT_WindowsPackageCab.strings.psd1 ├── MSFT_WindowsProcess │ ├── MSFT_WindowsProcess.psm1 │ ├── MSFT_WindowsProcess.schema.mof │ └── en-US │ │ ├── MSFT_WindowsProcess.schema.mfl │ │ └── MSFT_WindowsProcess.strings.psd1 ├── ProcessSet │ ├── ProcessSet.psd1 │ └── ProcessSet.schema.psm1 ├── ResourceSetHelper.psm1 ├── ServiceSet │ ├── ServiceSet.psd1 │ └── ServiceSet.schema.psm1 ├── WindowsFeatureSet │ ├── WindowsFeatureSet.psd1 │ └── WindowsFeatureSet.schema.psm1 └── WindowsOptionalFeatureSet │ ├── WindowsOptionalFeatureSet.psd1 │ └── WindowsOptionalFeatureSet.schema.psm1 ├── Examples ├── Sample_Archive_ExpandArchiveChecksumAndForce.ps1 ├── Sample_Archive_ExpandArchiveDefaultValidationAndForce.ps1 ├── Sample_Archive_ExpandArchiveNoValidation.ps1 ├── Sample_Archive_ExpandArchiveNoValidationCredential.ps1 ├── Sample_Archive_RemoveArchiveChecksum.ps1 ├── Sample_Archive_RemoveArchiveNoValidation.ps1 ├── Sample_Environment_CreateNonPathVariable.ps1 ├── Sample_Environment_CreatePathVariable.ps1 ├── Sample_Environment_Remove.ps1 ├── Sample_GroupSet_AddMembers.ps1 ├── Sample_Group_RemoveMembers.ps1 ├── Sample_Group_SetMembers.ps1 ├── Sample_MsiPackage_InstallPackageFromFile.ps1 ├── Sample_MsiPackage_InstallPackageFromHttp.ps1 ├── Sample_MsiPackage_UninstallPackageFromFile.ps1 ├── Sample_MsiPackage_UnstallPackageFromHttps.ps1 ├── Sample_ProcessSet_Start.ps1 ├── Sample_ProcessSet_Stop.ps1 ├── Sample_RegistryResource_AddKey.ps1 ├── Sample_RegistryResource_AddOrModifyValue.ps1 ├── Sample_RegistryResource_RemoveKey.ps1 ├── Sample_RegistryResource_RemoveValue.ps1 ├── Sample_Script.ps1 ├── Sample_ServiceSet_BuiltInAccount.ps1 ├── Sample_ServiceSet_StartServices.ps1 ├── Sample_Service_CreateService.ps1 ├── Sample_Service_DeleteService.ps1 ├── Sample_Service_UpdateStartupTypeIgnoreState.ps1 ├── Sample_User_CreateUser.ps1 ├── Sample_User_Generic.ps1 ├── Sample_WindowsFeature.ps1 ├── Sample_WindowsFeatureSet_Install.ps1 ├── Sample_WindowsFeatureSet_Uninstall.ps1 ├── Sample_WindowsOptionalFeature.ps1 ├── Sample_WindowsOptionalFeatureSet_Disable.ps1 ├── Sample_WindowsOptionalFeatureSet_Enable.ps1 ├── Sample_WindowsPackageCab.ps1 ├── Sample_WindowsProcess_Start.ps1 ├── Sample_WindowsProcess_StartUnderUser.ps1 ├── Sample_WindowsProcess_Stop.ps1 └── Sample_WindowsProcess_StopUnderUser.ps1 ├── LICENSE ├── PSDscResources.psd1 ├── README.md ├── Tests ├── Integration │ ├── GroupSet.Integration.Tests.ps1 │ ├── GroupSet.config.ps1 │ ├── MSFT_Archive.EndToEnd.Tests.ps1 │ ├── MSFT_Archive.Integration.Tests.ps1 │ ├── MSFT_Archive_CredentialOnly.config.ps1 │ ├── MSFT_Archive_ValidateAndChecksum.config.ps1 │ ├── MSFT_Archive_ValidateOnly.config.ps1 │ ├── MSFT_EnvironmentResource.EndToEnd.Tests.ps1 │ ├── MSFT_EnvironmentResource.Integration.Tests.ps1 │ ├── MSFT_EnvironmentResource.config.ps1 │ ├── MSFT_GroupResource.Integration.Tests.ps1 │ ├── MSFT_GroupResource_Members.config.ps1 │ ├── MSFT_GroupResource_MembersToIncludeExclude.config.ps1 │ ├── MSFT_GroupResource_NoMembers.config.ps1 │ ├── MSFT_MsiPackage.EndToEnd.Tests.ps1 │ ├── MSFT_MsiPackage.Integration.Tests.ps1 │ ├── MSFT_MsiPackage_LogPath.ps1 │ ├── MSFT_MsiPackage_NoOptionalParameters.ps1 │ ├── MSFT_RegistryResource.EndToEnd.Tests.ps1 │ ├── MSFT_RegistryResource.Integration.Tests.ps1 │ ├── MSFT_RegistryResource_KeyAndNameOnly.config.ps1 │ ├── MSFT_RegistryResource_WithDataAndType.config.ps1 │ ├── MSFT_ScriptResource.Integration.Tests.ps1 │ ├── MSFT_ScriptResource_NoCredential.config.ps1 │ ├── MSFT_ScriptResource_WithCredential.config.ps1 │ ├── MSFT_ServiceResource.Integration.Tests.ps1 │ ├── MSFT_ServiceResource_AllExceptCredential.config.ps1 │ ├── MSFT_ServiceResource_CredentialOnly.config.ps1 │ ├── MSFT_UserResource.Integration.Tests.ps1 │ ├── MSFT_UserResource.config.ps1 │ ├── MSFT_WindowsFeature.Integration.Tests.ps1 │ ├── MSFT_WindowsFeature.config.ps1 │ ├── MSFT_WindowsOptionalFeature.Integration.Tests.ps1 │ ├── MSFT_WindowsOptionalFeature.config.ps1 │ ├── MSFT_WindowsPackageCab.Integration.Tests.ps1 │ ├── MSFT_WindowsPackageCab.config.ps1 │ ├── MSFT_WindowsProcess.Integration.Tests.ps1 │ ├── MSFT_WindowsProcess_NoCredential.config.ps1 │ ├── MSFT_WindowsProcess_WithCredential.config.ps1 │ ├── ProcessSet.Integration.Tests.ps1 │ ├── ProcessSet.config.ps1 │ ├── ServiceSet.Integration.Tests.ps1 │ ├── ServiceSet_AllExceptBuiltInAccount.config.ps1 │ ├── ServiceSet_BuiltInAccountOnly.config.ps1 │ ├── WindowsFeatureSet.Integration.Tests.ps1 │ ├── WindowsFeatureSet.config.ps1 │ ├── WindowsOptionalFeatureSet.Integration.Tests.ps1 │ └── WindowsOptionalFeatureSet.config.ps1 ├── TestHelpers │ ├── CommonTestHelper.psm1 │ ├── DSCTestService.cs │ ├── DSCTestServiceNew.cs │ ├── MSFT_Archive.TestHelper.psm1 │ ├── MSFT_GroupResource.TestHelper.psm1 │ ├── MSFT_MsiPackageResource.TestHelper.psm1 │ ├── MSFT_RegistryResource.TestHelper.psm1 │ ├── MSFT_ServiceResource.TestHelper.psm1 │ ├── MSFT_UserResource.TestHelper.psm1 │ ├── WMF5Dot1Installation.psm1 │ ├── WindowsProcessTestProcess.cs │ ├── WindowsProcessTestProcess.exe │ └── WindowsProcessTestProcessSet.exe └── Unit │ ├── CommonResourceHelper.Tests.ps1 │ ├── MSFT_Archive.Tests.ps1 │ ├── MSFT_EnvironmentResource.Tests.ps1 │ ├── MSFT_GroupResource.Tests.ps1 │ ├── MSFT_MsiPackage.Tests.ps1 │ ├── MSFT_RegistryResource.Tests.ps1 │ ├── MSFT_ScriptResource.Tests.ps1 │ ├── MSFT_ServiceResource.Tests.ps1 │ ├── MSFT_UserResource.Tests.ps1 │ ├── MSFT_WindowsFeature.Tests.ps1 │ ├── MSFT_WindowsOptionalFeature.Tests.ps1 │ ├── MSFT_WindowsPackageCab.Tests.ps1 │ ├── MSFT_WindowsProcess.Tests.ps1 │ └── ResourceSetHelper.Tests.ps1 └── appveyor.yml /.MetaTestOptIn.json: -------------------------------------------------------------------------------- 1 | [ 2 | "Common Tests - Validate Module Files", 3 | "Common Tests - Validate Script Files", 4 | "Common Tests - Relative Path Length" 5 | ] 6 | -------------------------------------------------------------------------------- /.codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | notify: 3 | require_ci_to_pass: no 4 | 5 | comment: 6 | layout: "reach, diff" 7 | behavior: default 8 | 9 | coverage: 10 | range: 50..80 11 | round: down 12 | precision: 0 13 | 14 | status: 15 | project: 16 | default: 17 | # Set the overall project code coverage requirement to 70% 18 | target: 70 19 | patch: 20 | default: 21 | # Set the pull request requirement to not regress overall coverage by more than 5% 22 | # and let codecov.io set the goal for the code changed in the patch. 23 | target: auto 24 | threshold: 5 25 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text eol=crlf 2 | *.exe binary 3 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/General.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: General question or documentation update 3 | about: If you have a general question or documentation update suggestion around the resource module. 4 | --- 5 | 8 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Problem_with_resource.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Problem with a resource 3 | about: If you have a problem, bug, or enhancement with a resource in this resource module. 4 | --- 5 | 24 | #### Details of the scenario you tried and the problem that is occurring 25 | 26 | #### Verbose logs showing the problem 27 | 28 | #### Suggested solution to the issue 29 | 30 | #### The DSC configuration that is used to reproduce the issue (as detailed as possible) 31 | ```powershell 32 | # insert configuration here 33 | ``` 34 | 35 | #### The operating system the target node is running 36 | 50 | 51 | #### Version and build of PowerShell the target node is running 52 | 56 | 57 | #### Version of the DSC module that was used ('dev' if using current dev branch) 58 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Resource_proposal.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Resource proposals 3 | about: PSDscResources does not accept new resources! Please submit a new resource request to the appropriate DSC resource module repository. 4 | --- 5 | 6 | This resource module does not accept new resources. 7 | Please submit new resource requests to an appropriate DSC resource module 8 | repository found in the [maintainers list](https://github.com/PowerShell/DscResources/blob/master/Maintainers.md) 9 | in the [DSCResources repository](https://github.com/PowerShell/DscResources), 10 | or to the [xPSDesiredStateConfiguration repository](https://github.com/PowerShell/xPSDesiredStateConfiguration). 11 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 16 | #### Pull Request (PR) description 17 | 20 | 21 | #### This Pull Request (PR) fixes the following issues 22 | 29 | 30 | #### Task list 31 | 39 | - [ ] Added an entry under the Unreleased section in the CHANGELOG.md. 40 | Entry should say what was changed, and how that affects users (if applicable). 41 | - [ ] Resource documentation added/updated in README.md. 42 | - [ ] Resource parameter descriptions added/updated in README.md, schema.mof 43 | and comment-based help. 44 | - [ ] Comment-based help added/updated. 45 | - [ ] Localization strings added/updated in all localization files as appropriate. 46 | - [ ] Examples appropriately added/updated. 47 | - [ ] Unit tests added/updated. See [DSC Resource Testing Guidelines](https://github.com/PowerShell/DscResources/blob/master/TestsGuidelines.md). 48 | - [ ] Integration tests added/updated (where possible). See [DSC Resource Testing Guidelines](https://github.com/PowerShell/DscResources/blob/master/TestsGuidelines.md). 49 | - [ ] New/changed code adheres to [DSC Resource Style Guidelines](https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md) and [Best Practices](https://github.com/PowerShell/DscResources/blob/master/BestPractices.md). 50 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-stale - https://github.com/probot/stale 2 | 3 | limitPerRun: 30 4 | 5 | pulls: 6 | daysUntilStale: 14 7 | daysUntilClose: false 8 | exemptProjects: true 9 | exemptMilestones: true 10 | staleLabel: abandoned 11 | exemptLabels: 12 | - needs review 13 | - on hold 14 | - waiting for CLA pass 15 | 16 | markComment: > 17 | Labeling this pull request (PR) as abandoned since it has gone 14 days or more 18 | since the last update. An abandoned PR can be continued by another contributor. 19 | The abandoned label will be removed if work on this PR is taken up again. 20 | 21 | issues: 22 | daysUntilStale: 30 23 | daysUntilClose: 40 24 | exemptProjects: true 25 | exemptMilestones: true 26 | staleLabel: stale 27 | exemptLabels: 28 | - bug 29 | - enhancement 30 | - tests 31 | - documentation 32 | - resource proposal 33 | - on hold 34 | 35 | markComment: > 36 | This issue has been automatically marked as stale because 37 | it has not had activity from the community in the last 30 days. It will be 38 | closed if no further activity occurs within 10 days. If the issue is labelled 39 | with any of the work labels (e.g bug, enhancement, documentation, or tests) 40 | then the issue will not auto-close. 41 | 42 | closeComment: > 43 | This issue has been automatically closed because it is has not had activity 44 | from the community in the last 40 days. 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | DSCResource.Tests 2 | -------------------------------------------------------------------------------- /.vscode/analyzersettings.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | <# 3 | For the custom rules to work, the DscResource.Tests repo must be 4 | cloned. It is automatically clone as soon as any unit or 5 | integration tests are run. 6 | #> 7 | CustomRulePath = '.\DSCResource.Tests\DscResource.AnalyzerRules' 8 | 9 | IncludeRules = @( 10 | # DSC Resource Kit style guideline rules. 11 | 'PSAvoidDefaultValueForMandatoryParameter', 12 | 'PSAvoidDefaultValueSwitchParameter', 13 | 'PSAvoidInvokingEmptyMembers', 14 | 'PSAvoidNullOrEmptyHelpMessageAttribute', 15 | 'PSAvoidUsingCmdletAliases', 16 | 'PSAvoidUsingComputerNameHardcoded', 17 | 'PSAvoidUsingDeprecatedManifestFields', 18 | 'PSAvoidUsingEmptyCatchBlock', 19 | 'PSAvoidUsingInvokeExpression', 20 | 'PSAvoidUsingPositionalParameters', 21 | 'PSAvoidShouldContinueWithoutForce', 22 | 'PSAvoidUsingWMICmdlet', 23 | 'PSAvoidUsingWriteHost', 24 | 'PSDSCReturnCorrectTypesForDSCFunctions', 25 | 'PSDSCStandardDSCFunctionsInResource', 26 | 'PSDSCUseIdenticalMandatoryParametersForDSC', 27 | 'PSDSCUseIdenticalParametersForDSC', 28 | 'PSMisleadingBacktick', 29 | 'PSMissingModuleManifestField', 30 | 'PSPossibleIncorrectComparisonWithNull', 31 | 'PSProvideCommentHelp', 32 | 'PSReservedCmdletChar', 33 | 'PSReservedParams', 34 | 'PSUseApprovedVerbs', 35 | 'PSUseCmdletCorrectly', 36 | 'PSUseOutputTypeCorrectly', 37 | 'PSAvoidGlobalVars', 38 | 'PSAvoidUsingConvertToSecureStringWithPlainText', 39 | 'PSAvoidUsingPlainTextForPassword', 40 | 'PSAvoidUsingUsernameAndPasswordParams', 41 | 'PSDSCUseVerboseMessageInDSCResource', 42 | 'PSShouldProcess', 43 | 'PSUseDeclaredVarsMoreThanAssignments', 44 | 'PSUsePSCredentialType', 45 | 46 | <# 47 | This is to test all the DSC Resource Kit custom rules. 48 | The name of the function-blocks of each custom rule start 49 | with 'Measure*'. 50 | #> 51 | 'Measure-*' 52 | ) 53 | } 54 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "powershell.codeFormatting.openBraceOnSameLine": false, 3 | "powershell.codeFormatting.newLineAfterOpenBrace": false, 4 | "powershell.codeFormatting.newLineAfterCloseBrace": true, 5 | "powershell.codeFormatting.whitespaceBeforeOpenBrace": true, 6 | "powershell.codeFormatting.whitespaceBeforeOpenParen": true, 7 | "powershell.codeFormatting.whitespaceAroundOperator": true, 8 | "powershell.codeFormatting.whitespaceAfterSeparator": true, 9 | "powershell.codeFormatting.ignoreOneLineBlock": false, 10 | "powershell.codeFormatting.preset": "Custom", 11 | "files.trimTrailingWhitespace": true, 12 | "files.insertFinalNewline": true, 13 | "powershell.scriptAnalysis.settingsPath": ".vscode\\analyzersettings.psd1" 14 | } 15 | -------------------------------------------------------------------------------- /DscResources/CommonResourceHelper.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Tests if the current machine is a Nano server. 4 | #> 5 | function Test-IsNanoServer 6 | { 7 | [OutputType([System.Boolean])] 8 | [CmdletBinding()] 9 | param () 10 | 11 | $serverLevelsRegKey = 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Server\ServerLevels' 12 | 13 | if (Test-Path -Path $serverLevelsRegKey) 14 | { 15 | $serverLevels = Get-ItemProperty -Path $serverLevelsRegKey 16 | 17 | if ($serverLevels.NanoServer -eq 1) 18 | { 19 | $isNanoServer = $true 20 | } 21 | else 22 | { 23 | $isNanoServer = $false 24 | } 25 | } 26 | else 27 | { 28 | $isNanoServer = $false 29 | } 30 | 31 | return $isNanoServer 32 | } 33 | 34 | <# 35 | .SYNOPSIS 36 | Tests whether or not the command with the specified name exists. 37 | 38 | .PARAMETER Name 39 | The name of the command to test for. 40 | #> 41 | function Test-CommandExists 42 | { 43 | [OutputType([System.Boolean])] 44 | [CmdletBinding()] 45 | param 46 | ( 47 | [Parameter(Mandatory = $true)] 48 | [ValidateNotNullOrEmpty()] 49 | [System.String] 50 | $Name 51 | ) 52 | 53 | $command = Get-Command -Name $Name -ErrorAction 'SilentlyContinue' 54 | return ($null -ne $command) 55 | } 56 | 57 | <# 58 | .SYNOPSIS 59 | Creates and throws an invalid argument exception. 60 | 61 | .PARAMETER Message 62 | The message explaining why this error is being thrown. 63 | 64 | .PARAMETER ArgumentName 65 | The name of the invalid argument that is causing this error to be thrown. 66 | #> 67 | function New-InvalidArgumentException 68 | { 69 | [CmdletBinding()] 70 | param 71 | ( 72 | [Parameter(Mandatory = $true)] 73 | [ValidateNotNullOrEmpty()] 74 | [System.String] 75 | $Message, 76 | 77 | [Parameter(Mandatory = $true)] 78 | [ValidateNotNullOrEmpty()] 79 | [System.String] 80 | $ArgumentName 81 | ) 82 | 83 | $argumentException = New-Object -TypeName 'ArgumentException' ` 84 | -ArgumentList @($Message, $ArgumentName) 85 | $newObjectParams = @{ 86 | TypeName = 'System.Management.Automation.ErrorRecord' 87 | ArgumentList = @($argumentException, $ArgumentName, 'InvalidArgument', $null) 88 | } 89 | $errorRecord = New-Object @newObjectParams 90 | 91 | throw $errorRecord 92 | } 93 | 94 | <# 95 | .SYNOPSIS 96 | Creates and throws an invalid operation exception. 97 | 98 | .PARAMETER Message 99 | The message explaining why this error is being thrown. 100 | 101 | .PARAMETER ErrorRecord 102 | The error record containing the exception that is causing this terminating 103 | error. 104 | #> 105 | function New-InvalidOperationException 106 | { 107 | [CmdletBinding()] 108 | param 109 | ( 110 | [Parameter()] 111 | [ValidateNotNullOrEmpty()] 112 | [System.String] 113 | $Message, 114 | 115 | [Parameter()] 116 | [ValidateNotNull()] 117 | [System.Management.Automation.ErrorRecord] 118 | $ErrorRecord 119 | ) 120 | 121 | if ($null -eq $Message) 122 | { 123 | $invalidOperationException = New-Object -TypeName 'InvalidOperationException' 124 | } 125 | elseif ($null -eq $ErrorRecord) 126 | { 127 | $invalidOperationException = New-Object -TypeName 'InvalidOperationException' ` 128 | -ArgumentList @( $Message ) 129 | } 130 | else 131 | { 132 | $invalidOperationException = New-Object -TypeName 'InvalidOperationException' ` 133 | -ArgumentList @( $Message, $ErrorRecord.Exception ) 134 | } 135 | 136 | $newObjectParams = @{ 137 | TypeName = 'System.Management.Automation.ErrorRecord' 138 | ArgumentList = @( $invalidOperationException.ToString(), 'MachineStateIncorrect', 'InvalidOperation', $null ) 139 | } 140 | 141 | $errorRecordToThrow = New-Object @newObjectParams 142 | throw $errorRecordToThrow 143 | } 144 | 145 | <# 146 | .SYNOPSIS 147 | Retrieves the localized string data based on the machine's culture. 148 | Falls back to en-US strings if the machine's culture is not supported. 149 | 150 | .PARAMETER ResourceName 151 | The name of the resource as it appears before '.strings.psd1' of the localized 152 | string file. 153 | For example: 154 | For WindowsOptionalFeature: MSFT_WindowsOptionalFeature 155 | For Service: MSFT_ServiceResource 156 | For Registry: MSFT_RegistryResource 157 | #> 158 | function Get-LocalizedData 159 | { 160 | [CmdletBinding()] 161 | param 162 | ( 163 | [Parameter(Mandatory = $true)] 164 | [ValidateNotNullOrEmpty()] 165 | [System.String] 166 | $ResourceName 167 | ) 168 | 169 | $resourceDirectory = Join-Path -Path $PSScriptRoot -ChildPath $ResourceName 170 | $localizedStringFileLocation = Join-Path -Path $resourceDirectory -ChildPath $PSUICulture 171 | 172 | if (-not (Test-Path -Path $localizedStringFileLocation)) 173 | { 174 | # Fallback to en-US 175 | $localizedStringFileLocation = Join-Path -Path $resourceDirectory -ChildPath 'en-US' 176 | } 177 | 178 | Import-LocalizedData ` 179 | -BindingVariable 'localizedData' ` 180 | -FileName "$ResourceName.strings.psd1" ` 181 | -BaseDirectory $localizedStringFileLocation 182 | 183 | return $localizedData 184 | } 185 | 186 | Export-ModuleMember -Function @( 'Test-IsNanoServer', 'New-InvalidArgumentException', 187 | 'New-InvalidOperationException', 'Get-LocalizedData' ) 188 | -------------------------------------------------------------------------------- /DscResources/GroupSet/GroupSet.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 3 | # Script module or binary module file associated with this manifest. 4 | RootModule = 'GroupSet.schema.psm1' 5 | 6 | # Version number of this module. 7 | ModuleVersion = '0.1.0.0' 8 | 9 | # ID used to uniquely identify this module 10 | GUID = 'c5e227b5-52dc-4653-b08f-6d94e06bb90b' 11 | 12 | # Author of this module 13 | Author = 'Microsoft Corporation' 14 | 15 | # Company or vendor of this module 16 | CompanyName = 'Microsoft Corporation' 17 | 18 | # Copyright statement for this module 19 | Copyright = '(c) 2016 Microsoft. All rights reserved.' 20 | 21 | # Description of the functionality provided by this module 22 | Description = 'Configures multiple Group resources with common settings but different names.' 23 | 24 | # Minimum version of the Windows PowerShell engine required by this module 25 | PowerShellVersion = '5.1' 26 | 27 | } 28 | -------------------------------------------------------------------------------- /DscResources/GroupSet/GroupSet.schema.psm1: -------------------------------------------------------------------------------- 1 | $errorActionPreference = 'Stop' 2 | Set-StrictMode -Version 'Latest' 3 | 4 | # Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock 5 | $script:dscResourcesFolderFilePath = Split-Path -Path $PSScriptRoot -Parent 6 | $script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'ResourceSetHelper.psm1' 7 | Import-Module -Name $script:resourceSetHelperFilePath 8 | 9 | <# 10 | .SYNOPSIS 11 | A composite DSC resource to configure a set of similar Group resources. 12 | 13 | .DESCRIPTION 14 | Provides a mechanism to manage local groups on the target node. Use this resource when you want to add and/or remove the same list of members to more than one group, remove more than one group, or add more than one group with the same list of members. 15 | 16 | 17 | .PARAMETER GroupName 18 | An array of the names of the groups to configure. 19 | 20 | .PARAMETER Ensure 21 | Specifies whether or not the set of groups should exist. 22 | 23 | Set this property to Present to create or modify a set of groups. 24 | Set this property to Absent to remove a set of groups. 25 | 26 | .PARAMETER MembersToInclude 27 | The members that should be included in each group in the set. 28 | 29 | .PARAMETER MembersToExclude 30 | The members that should be excluded from each group in the set. 31 | 32 | .PARAMETER Credential 33 | The credential to resolve all groups and user accounts. 34 | #> 35 | Configuration GroupSet 36 | { 37 | [CmdletBinding()] 38 | param 39 | ( 40 | [Parameter(Mandatory = $true)] 41 | [ValidateNotNullOrEmpty()] 42 | [System.String[]] 43 | $GroupName, 44 | 45 | [Parameter()] 46 | [ValidateSet('Present', 'Absent')] 47 | [System.String] 48 | $Ensure, 49 | 50 | [Parameter()] 51 | [System.String[]] 52 | $MembersToInclude, 53 | 54 | [Parameter()] 55 | [System.String[]] 56 | $MembersToExclude, 57 | 58 | [Parameter()] 59 | [ValidateNotNullOrEmpty()] 60 | [System.Management.Automation.PSCredential] 61 | [System.Management.Automation.Credential()] 62 | $Credential 63 | ) 64 | 65 | $newResourceSetConfigurationParams = @{ 66 | ResourceName = 'Group' 67 | ModuleName = 'PSDscResources' 68 | KeyParameterName = 'GroupName' 69 | Parameters = $PSBoundParameters 70 | } 71 | 72 | $configurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams 73 | 74 | # This script block must be run directly in this configuration in order to resolve variables 75 | . $configurationScriptBlock 76 | } 77 | -------------------------------------------------------------------------------- /DscResources/MSFT_Archive/MSFT_Archive.schema.mof: -------------------------------------------------------------------------------- 1 | [ClassVersion("1.0.0.0"),FriendlyName("Archive")] 2 | class MSFT_Archive : OMI_BaseResource 3 | { 4 | [Key, Description("The path to the archive file that should be expanded to or removed from the specified destination.")] String Path; 5 | [Key, Description("The path where the specified archive file should be expanded to or removed from.")] String Destination; 6 | [Write, Description("Specifies whether or not the expanded content of the archive file at the specified path should exist at the specified destination. To update the specified destination to have the expanded content of the archive file at the specified path, specify this property as Present. To remove the expanded content of the archive file at the specified path from the specified destination, specify this property as Absent. The default value is Present."), ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure; 7 | [Write, Description("Specifies whether or not to validate that a file at the destination with the same name as a file in the archive actually matches that corresponding file in the archive by the specified checksum method. If the file does not match and Ensure is specified as Present and Force is not specified, the resource will throw an error that the file at the desintation cannot be overwritten. If the file does not match and Ensure is specified as Present and Force is specified, the file at the desintation will be overwritten. If the file does not match and Ensure is specified as Absent, the file at the desintation will not be removed. The default value is false.")] Boolean Validate; 8 | [Write, Description("The Checksum method to use to validate whether or not a file at the destination with the same name as a file in the archive actually matches that corresponding file in the archive. An invalid argument exception will be thrown if Checksum is specified while Validate is specified as false. ModifiedDate will check that the LastWriteTime property of the file at the destination matches the LastWriteTime property of the file in the archive. CreatedDate will check that the CreationTime property of the file at the destination matches the CreationTime property of the file in the archive. SHA-1, SHA-256, and SHA-512 will check that the hash of the file at the destination by the specified SHA method matches the hash of the file in the archive by the specified SHA method. The default value is ModifiedDate.") ,ValueMap{"SHA-1", "SHA-256", "SHA-512", "CreatedDate", "ModifiedDate"}, Values{"SHA-1", "SHA-256", "SHA-512", "CreatedDate", "ModifiedDate"}] String Checksum; 9 | [Write, Description("The credential of a user account with permissions to access the specified archive path and destination if needed.") ,EmbeddedInstance("MSFT_Credential")] String Credential; 10 | [Write, Description("Specifies whether or not any existing files or directories at the destination with the same name as a file or directory in the archive should be overwritten to match the file or directory in the archive. When this property is false, an error will be thrown if an item at the destination needs to be overwritten. The default value is false.")] Boolean Force; 11 | }; 12 | -------------------------------------------------------------------------------- /DscResources/MSFT_Archive/en-US/MSFT_Archive.schema.mfl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowerShell/PSDscResources/7064eda52d939a4a3ce40e1f38756cfe6a09acfd/DscResources/MSFT_Archive/en-US/MSFT_Archive.schema.mfl -------------------------------------------------------------------------------- /DscResources/MSFT_Archive/en-US/MSFT_Archive.strings.psd1: -------------------------------------------------------------------------------- 1 | # Localized MSFT_Archive.strings.psd1 2 | 3 | ConvertFrom-StringData @' 4 | RetrievingArchiveState = Retrieving the state of the archive with path "{0}" and destination "{1}"... 5 | SettingArchiveState = Setting the state of the archive with path "{0}" and destination "{1}"... 6 | ArchiveStateSet = The state of the archive with path "{0}" and destination "{1}" has been set. 7 | TestingArchiveState = Testing whether or not the state of the archive with path "{0}" and destination "{1}" matches the desired state... 8 | 9 | PathAccessiblePSDriveNotNeeded = The path "{0}" is accessible. A new PSDrive is not needed. 10 | CreatingPSDrive = Creating a PSDrive to access the path "{0}" with permissions from the user "{1}"... 11 | RemovingPSDrive = Removing the mounted PSDrive "{0}"... 12 | 13 | DestinationExists = A directory already exists at the destination path "{0}". 14 | DestinationDoesNotExist = A directory does not exist at the destination path "{0}". 15 | CreatingDirectoryAtDestination = Creating the root directory at the destination path "{0}"... 16 | 17 | TestingIfArchiveExistsAtDestination = Testing if the archive at the destination path "{0}" exists... 18 | ArchiveExistsAtDestination = The archive at path "{0}" exists at the destination "{1}". 19 | ArchiveDoesNotExistAtDestination = The archive at path "{0}" does not exist at the destination "{1}". 20 | 21 | OpeningArchive = Opening the archive at path "{0}"... 22 | ClosingArchive = Closing the archive at path "{0}"... 23 | 24 | OpeningArchiveEntry = Opening the archive entry "{0}"... 25 | 26 | ItemWithArchiveEntryNameExists = An item with the same name as the archive entry exists at the destination path "{0}". 27 | ItemWithArchiveEntryNameDoesNotExist = An item with the same name as the archive entry does not exist at the destination path "{0}". 28 | ItemWithArchiveEntryNameIsNotDirectory = The item at the destination path "{0}" has the same name as a directory archive entry but is not a directory. 29 | ItemWithArchiveEntryNameIsNotFile = The item at the destination path "{0}" has the same name as a file archive entry but is not a file. 30 | 31 | TestingIfFileMatchesArchiveEntryByChecksum = Testing if the file at "{0}" matches the archive entry at "{1}" by the checksum method "{2}"... 32 | ComparingHashes = Comparing the hash of the file at "{0}" to the hash of the archive entry at "{1}" with the hash algorithm "{2}"... 33 | FileMatchesArchiveEntryByChecksum = The file at "{0}" matches the archive entry at "{1}" by the checksum method "{2}". 34 | FileDoesNotMatchArchiveEntryByChecksum = The file at "{0}" does not match the archive entry at "{1}" by the checksum method "{2}". 35 | 36 | ExpandingArchiveToDestination = Expanding the archive at "{0}" to the destination "{1}"... 37 | CreatingParentDirectory = Creating an archive entry parent directory at the path "{0}"... 38 | OverwritingItem = Overwriting the item at the path "{0}"... 39 | CreatingArchiveEntryDirectory = Creating an archive entry directory "{0}"... 40 | CopyingArchiveEntryToDestination = Copying the archive entry "{0}" to the destination path "{1}"... 41 | 42 | RemovingArchiveFromDestination = Removing archive from the destination path "{0}"... 43 | RemovingDirectory = Removing the directory at path "{0}"... 44 | RemovingFile = Removing the file at path "{0}"... 45 | CouldNotRemoveItemOfIncorrectType = The file at "{0}" does not match the item type (file, directory, or other) or the archive entry at "{1}", so it will not be removed. 46 | ArchiveRemovedFromDestination = Archive removed from the destination path "{0}". 47 | 48 | ChecksumSpecifiedAndValidateFalse = The Checksum parameter was specified as "{0}" but the Validate parameter is set to false for the archive with path "{1}" and destination "{2}". Please specify the Validate parameter as true to use the Checksum parameter. 49 | PathDoesNotContainValidPSDriveRoot = The path "{0}" cannot be accessed because it does not contain any directories to use as the root of a PSDrive. 50 | ErrorCreatingPSDrive = An error occurred while attempting to create a PSDrive to access the path "{0}" under the user "{1}". 51 | PathDoesNotExistAsLeaf = The path "{0}" does not exist or is not a path leaf. 52 | DestinationExistsAsFile = A file exists at the desintation path "{0}". 53 | ErrorOpeningArchive = An error occurred while attempting to open the archive at path "{0}". 54 | ErrorCopyingFromArchiveToDestination = An error occurred while attempting copy from the archive to the destination path "{0}". 55 | DirectoryIsNotEmpty = The directory at path "{0}" is not empty, so it will not be removed. 56 | ErrorComparingHashes = An error occurred while comparing the hash of the file at "{0}" to the archive entry "{1}" with the hash algorithm "{2}". 57 | ForceNotSpecifiedToOverwriteItem = An item already exists at "{0}" that does not match the item in the archive at "{1}", but the Force parameter has not been specified to overwrite this item. 58 | '@ 59 | -------------------------------------------------------------------------------- /DscResources/MSFT_EnvironmentResource/MSFT_EnvironmentResource.schema.mof: -------------------------------------------------------------------------------- 1 | [ClassVersion("1.0.0"), FriendlyName("Environment")] 2 | class MSFT_EnvironmentResource : OMI_BaseResource 3 | { 4 | [Key, Description("The name of the environment variable for which you want to ensure a specific state.")] String Name; 5 | [Write, Description("The desired value for the environment variable.")] String Value; 6 | [Write, Description("Specifies if the environment varaible should exist."), ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure; 7 | [Write, Description("Indicates whether or not the environment variable is the Path variable.")] Boolean Path; 8 | [Write, Description("Indicates the target where the environment variable should be set."), ValueMap{"Process", "Machine"}, Values{"Process", "Machine"}] String Target[]; 9 | }; 10 | -------------------------------------------------------------------------------- /DscResources/MSFT_EnvironmentResource/en-US/MSFT_EnvironmentResource.schema.mfl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowerShell/PSDscResources/7064eda52d939a4a3ce40e1f38756cfe6a09acfd/DscResources/MSFT_EnvironmentResource/en-US/MSFT_EnvironmentResource.schema.mfl -------------------------------------------------------------------------------- /DscResources/MSFT_EnvironmentResource/en-US/MSFT_EnvironmentResource.strings.psd1: -------------------------------------------------------------------------------- 1 | # Localized resources for MSFT_EnvironmentResource 2 | 3 | ConvertFrom-StringData @' 4 | ArgumentTooLong = Argument is too long. 5 | CannotSetValueToEmpty = Cannot create environment variable with an empty value. Set Ensure = Absent to remove environment variable '{0}'. 6 | EnvVarCreated = Environment variable '{0}' created with value '{1}'. 7 | EnvVarSetError = Failed to set environment variable '{0}' to value '{1}'. 8 | EnvVarPathSetError = Failed to add path '{0}' to environment variable '{1}' holding value '{2}'. 9 | EnvVarRemoveError = Failed to remove environment variable '{0}' holding value '{1}'. 10 | EnvVarPathRemoveError = Failed to remove path '{0}' from variable '{1}' holding value '{2}'. 11 | EnvVarUnchanged = Environment variable '{0}' with value '{1}' was not updated. 12 | EnvVarUpdated = Environment variable '{0}' updated from value '{1}' to value '{2}'. 13 | EnvVarPathUnchanged = Path environment variable '{0}' with value '{1}' was not updated. 14 | EnvVarPathUpdated = Environment variable '{0}' updated from value '{1}' to value '{2}'. 15 | EnvVarNotFound = Environment variable '{0}' does not exist. 16 | EnvVarFound = Environment variable '{0}' with value '{1}' was successfully found. 17 | EnvVarFoundWithMisMatchingValue = Environment variable '{0}' with value '{1}' mismatched the specified value '{2}'. 18 | EnvVarRemoved = Environment variable '{0}' was removed. 19 | GetItemPropertyFailure = Failed to get the item property for variable '{0}' with path '{1}'. 20 | RemoveNonExistentVarError = Environment variable '{0}' cannot be removed because it does not exist. 21 | '@ 22 | -------------------------------------------------------------------------------- /DscResources/MSFT_GroupResource/MSFT_GroupResource.schema.mof: -------------------------------------------------------------------------------- 1 | 2 | [ClassVersion("1.0.0"),FriendlyName("Group")] 3 | class MSFT_GroupResource : OMI_BaseResource 4 | { 5 | [Key, Description("The name of the group to create, modify, or remove.")] String GroupName; 6 | [Write, ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}, Description("Indicates if the group should exist or not.")] String Ensure; 7 | [Write, Description("The description the group should have.")] String Description; 8 | [Write, Description("The members the group should have.")] String Members[]; 9 | [Write, Description("The members the group should include.")] String MembersToInclude[]; 10 | [Write, Description("The members the group should exclude.")] String MembersToExclude[]; 11 | [Write, EmbeddedInstance("MSFT_Credential"), Description("A credential to resolve non-local group members.")] String Credential; 12 | }; 13 | -------------------------------------------------------------------------------- /DscResources/MSFT_GroupResource/en-US/MSFT_GroupResource.schema.mfl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowerShell/PSDscResources/7064eda52d939a4a3ce40e1f38756cfe6a09acfd/DscResources/MSFT_GroupResource/en-US/MSFT_GroupResource.schema.mfl -------------------------------------------------------------------------------- /DscResources/MSFT_GroupResource/en-US/MSFT_GroupResource.strings.psd1: -------------------------------------------------------------------------------- 1 | # Localized resources for MSFT_GroupResource 2 | 3 | ConvertFrom-StringData @' 4 | GroupWithName = Group: {0} 5 | RemoveOperation = Remove 6 | AddOperation = Add 7 | SetOperation = Set 8 | GroupCreated = Group {0} created successfully. 9 | GroupUpdated = Group {0} properties updated successfully. 10 | GroupRemoved = Group {0} removed successfully. 11 | NoConfigurationRequired = Group {0} exists on this node with the desired properties. No action required. 12 | NoConfigurationRequiredGroupDoesNotExist = Group {0} does not exist on this node. No action required. 13 | CouldNotFindPrincipal = Could not find a principal with the provided name {0}. 14 | MembersAndIncludeExcludeConflict = The {0} and {1} parameters conflict. The {0} parameter should not be used in any combination with the {1} parameter. 15 | GroupAndMembersEmpty = Members is empty and group {0} has no members. No change to group members is needed. 16 | MemberIsNotALocalUser = {0} is not a local user. User's principal source is {1}. 17 | MemberNotValid = The group member {0} does not exist or cannot be resolved. 18 | IncludeAndExcludeConflict = The principal {0} is included in both {1} and {2} parameter values. The same principal cannot be included in both {1} and {2} parameter values. 19 | InvalidGroupName = The group name {0} cannot be used. Names may not consist entirely of periods and/or whitespace or contain these characters: {1} 20 | GroupExists = A group with the name {0} exists. 21 | GroupDoesNotExist = A group with the name {0} does not exist. 22 | PropertyMismatch = The value of the {0} property is expected to be {1} but it is {2}. 23 | MembersNumberMismatch = The number of provided unique group members {1} in {0} is different from the number of actual group members {2}. 24 | MembersMemberMismatch = At least one member {0} of the provided {1} parameter does not match a user in the existing group {2}. 25 | MemberToExcludeMatch = At least one member {0} of the provided {1} parameter matches a user in the existing group {2}. 26 | ResolvingLocalAccount = Resolving {0} as a local account. 27 | ResolvingDomainAccount = Resolving {0} in the domain {1}. 28 | ResolvingDomainAccountWithTrust = Resolving {0} with domain trust. 29 | DomainCredentialsRequired = Credentials are required to resolve the domain account {0}. 30 | UnableToResolveAccount = Unable to resolve account '{0}'. Failed with message: {1} (error code={2}) 31 | InvokingFunctionForGroup = Invoking the function {0} for the group {1}. 32 | SetTargetResourceStartMessage = Begin executing Set functionality on the group {0}. 33 | SetTargetResourceEndMessage = End executing Set functionality on the group {0}. 34 | MembersToIncludeEmpty = MembersToInclude is empty. No group member additions are needed. 35 | MembersToExcludeEmpty = MembersToExclude is empty. No group member removals are needed. 36 | '@ 37 | -------------------------------------------------------------------------------- /DscResources/MSFT_MsiPackage/MSFT_MsiPackage.schema.mof: -------------------------------------------------------------------------------- 1 | [ClassVersion("1.0.0"),FriendlyName("MsiPackage")] 2 | class MSFT_MsiPackage : OMI_BaseResource 3 | { 4 | [Key, Description("The identifying number used to find the package, usually a GUID.")] String ProductId; 5 | [Required, Description("The path to the MSI file that should be installed or uninstalled.")] String Path; 6 | [Write, Description("Specifies whether or not the MSI file should be installed or uninstalled."), ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure; 7 | [Write, Description("The arguments to be passed to the MSI package during installation or uninstallation.")] String Arguments; 8 | [Write, Description("The credential of a user account to be used to mount a UNC path if needed."), EmbeddedInstance("MSFT_Credential")] String Credential; 9 | [Write, Description("The path to the log file to log the output from the MSI execution.")] String LogPath; 10 | [Write, Description("The expected hash value of the MSI file at the given path.")] String FileHash; 11 | [Write, Description("The algorithm used to generate the given hash value."), ValueMap{"SHA1", "SHA256", "SHA384", "SHA512", "MD5", "RIPEMD160"}, Values{"SHA1", "SHA256", "SHA384", "SHA512", "MD5", "RIPEMD160"}] String HashAlgorithm; 12 | [Write, Description("The subject that should match the signer certificate of the digital signature of the MSI file.")] String SignerSubject; 13 | [Write, Description("The certificate thumbprint that should match the signer certificate of the digital signature of the MSI file.")] String SignerThumbprint; 14 | [Write, Description("PowerShell code that should be used to validate SSL certificates for paths using HTTPS.")] String ServerCertificateValidationCallback; 15 | [Write, Description("The credential of a user account under which to run the installation or uninstallation of the MSI package."), EmbeddedInstance("MSFT_Credential")] String RunAsCredential; 16 | [Read, Description("The display name of the MSI package.")] String Name; 17 | [Read, Description("The path to the MSI package.")] String InstallSource; 18 | [Read, Description("The date that the MSI package was installed on or serviced on, whichever is later.")] String InstalledOn; 19 | [Read, Description("The size of the MSI package in MB.")] UInt32 Size; 20 | [Read, Description("The version number of the MSI package.")] String Version; 21 | [Read, Description("The description of the MSI package.")] String PackageDescription; 22 | [Read, Description("The publisher of the MSI package.")] String Publisher; 23 | }; 24 | -------------------------------------------------------------------------------- /DscResources/MSFT_MsiPackage/en-US/MSFT_MsiPackage.schema.mfl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowerShell/PSDscResources/7064eda52d939a4a3ce40e1f38756cfe6a09acfd/DscResources/MSFT_MsiPackage/en-US/MSFT_MsiPackage.schema.mfl -------------------------------------------------------------------------------- /DscResources/MSFT_MsiPackage/en-US/MSFT_MsiPackage.strings.psd1: -------------------------------------------------------------------------------- 1 | # Localized resources for MSFT_MsiPackage 2 | 3 | ConvertFrom-StringData @' 4 | CheckingFileHash = Checking file '{0}' for expected {2} hash value of {1} 5 | CheckingFileSignature = Checking file '{0}' for valid digital signature 6 | CopyingTheSchemeStreamBytesToTheDiskCache = Copying the stream bytes to the disk cache 7 | CouldNotGetResponseFromWebRequest = An error occurred while trying to get the {0} response for file {1} 8 | CouldNotOpenDestFile = Could not open the file {0} for writing 9 | CouldNotOpenLog = The specified LogPath ({0}) could not be opened 10 | CouldNotStartProcess = The process {0} could not be started 11 | CreatingCacheLocation = Creating cache location 12 | CreatingTheDestinationCacheFile = Creating the destination cache file 13 | CreatingTheSchemeStream = Creating the {0} stream 14 | ErrorCopyingDataToFile = Encountered an error while copying the response to the output stream 15 | FileHasValidSignature = File '{0}' contains a valid digital signature. Signer Thumbprint: {1}, Subject: {2} 16 | GetTargetResourceFound = Successfully retrieved package {0} 17 | GetTargetResourceNotFound = Unable to find package: {0} 18 | GettingTheSchemeResponseStream = Getting the {0} response stream 19 | InvalidBinaryType = The specified Path ({0}) does not appear to specify an MSI file and as such is not supported 20 | InvalidFileHash = File '{0}' does not match expected {2} hash value of {1} 21 | InvalidFileSignature = File '{0}' does not have a valid Authenticode signature. Status: {1} 22 | InvalidId = The specified IdentifyingNumber ({0}) does not match the IdentifyingNumber ({1}) in the MSI file 23 | InvalidIdentifyingNumber = The specified IdentifyingNumber ({0}) is not a valid GUID 24 | InvalidPath = The specified Path ({0}) is not in a valid format. Valid formats are local paths, UNC, HTTP, and HTTPS 25 | MachineRequiresReboot = The machine requires a reboot 26 | PackageAppearsInstalled = The package {0} is installed 27 | PackageConfigurationStarting = Package configuration starting 28 | PackageDoesNotAppearInstalled = The package {0} is not installed 29 | PathDoesNotExist = The given Path ({0}) could not be found 30 | PackageInstalled = Package has been installed 31 | PackageUninstalled = Package has been uninstalled 32 | ParsedProductIdAsIdentifyingNumber = Parsed {0} as {1} 33 | ParsingProductIdAsAnIdentifyingNumber = Parsing {0} as an identifyingNumber 34 | PostValidationError = Package from {0} was installed, but the specified ProductId does not match package details 35 | RedirectingPackagePathToCacheFileLocation = Redirecting package path to cache file location 36 | SettingAuthenticationLevel = Setting authentication level to None 37 | SettingCertificateValidationCallback = Assigning user-specified certificate verification callback 38 | SettingDefaultCredential = Setting default credential 39 | StartingWithStartInfoFileNameStartInfoArguments = Starting {0} with {1} 40 | ThePathExtensionWasPathExt = The path extension was {0} 41 | TheUriSchemeWasUriScheme = The uri scheme was {0} 42 | WrongSignerSubject = File '{0}' was not signed by expected signer subject '{1}' 43 | WrongSignerThumbprint = File '{0}' was not signed by expected signer certificate thumbprint '{1}' 44 | '@ 45 | -------------------------------------------------------------------------------- /DscResources/MSFT_RegistryResource/MSFT_RegistryResource.schema.mof: -------------------------------------------------------------------------------- 1 | [ClassVersion("1.0.0"), FriendlyName("Registry")] 2 | class MSFT_RegistryResource : OMI_BaseResource 3 | { 4 | [Key, Description("The path of the registry key to add, modify, or remove. This path must include the registry hive/drive.")] String Key; 5 | [Key, Description("The name of the registry value. To add or remove a registry key, specify this property as an empty string without specifying ValueType or ValueData. To modify or remove the default value of a registry key, specify this property as an empty string while also specifying ValueType or ValueData.")] String ValueName; 6 | [Write, Description("The data the specified registry key value should have as a string or an array of strings (MultiString only).")] String ValueData[]; 7 | [Write, Description("The type the specified registry key value should have."), ValueMap{"String", "Binary", "DWord", "QWord", "MultiString", "ExpandString"},Values{"String", "Binary", "DWord", "QWord", "MultiString", "ExpandString"}] String ValueType; 8 | [Write, Description("Specifies whether or not the registry key or value should exist. To add or modify a registry key or value, set this property to Present. To remove a registry key or value, set the property to Absent."), ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] String Ensure; 9 | [Write, Description("Specifies whether or not the specified DWord or QWord registry key data is provided in a hexadecimal format. Not valid for types other than DWord and QWord. The default value is $false.")] Boolean Hex; 10 | [Write, Description("Specifies whether or not to overwrite the specified registry key value if it already has a value or whether or not to delete a registry key that has subkeys. The default value is $false.")] Boolean Force; 11 | }; 12 | -------------------------------------------------------------------------------- /DscResources/MSFT_RegistryResource/en-US/MSFT_RegistryResource.schema.mfl: -------------------------------------------------------------------------------- 1 | [Description("Provides a mechanism to manage registry keys and values on a target node.") : Amended,AMENDMENT, LOCALE("MS_409")] 2 | class MSFT_RegistryResource : OMI_BaseResource 3 | { 4 | [Key, Description("The path of the registry key to add, modify, or remove. This path must include the registry hive/drive.") : Amended] String Key; 5 | [Key, Description("The name of the registry value. To add or remove a registry key, specify this property as an empty string without specifying ValueType or ValueData. To modify or remove the default value of a registry key, specify this property as an empty string while also specifying ValueType or ValueData.") : Amended] String ValueName; 6 | [Description("The data the specified registry key value should have as a string or an array of strings (MultiString only).") : Amended] String ValueData[]; 7 | [Description("The type the specified registry key value should have.") : Amended] String ValueType; 8 | [Description("Specifies whether or not the registry key or value should exist. To add or modify a registry key or value, set this property to Present. To remove a registry key or value, set the property to Absent.") : Amended] String Ensure; 9 | [Description("Specifies whether or not the specified DWord or QWord registry key data is provided in a hexadecimal format. Not valid for types other than DWord and QWord. The default value is $false.") : Amended] Boolean Hex; 10 | [Description("Specifies whether or not to overwrite the specified registry key value if it already has a value or whether or not to delete a registry key that has subkeys. The default value is $false.") : Amended] Boolean Force; 11 | }; 12 | -------------------------------------------------------------------------------- /DscResources/MSFT_RegistryResource/en-US/MSFT_RegistryResource.strings.psd1: -------------------------------------------------------------------------------- 1 | # Localized resources for MSFT_RegistryResource 2 | 3 | ConvertFrom-StringData @' 4 | DefaultValueDisplayName = (Default) 5 | 6 | GetTargetResourceStartMessage = Get-TargetResource is starting for Registry resource with Key {0} 7 | GetTargetResourceEndMessage = Get-TargetResource has finished for Registry resource with Key {0} 8 | RegistryKeyDoesNotExist = The registry key at path {0} does not exist. 9 | RegistryKeyExists = The registry key at path {0} exists. 10 | RegistryKeyValueDoesNotExist = The registry key at path {0} does not have a value named {1}. 11 | RegistryKeyValueExists = The registry key at path {0} has a value named {1}. 12 | 13 | SetTargetResourceStartMessage = Set-TargetResource is starting for Registry resource with Key {0} 14 | SetTargetResourceEndMessage = Set-TargetResource has finished for Registry resource with Key {0} 15 | CreatingRegistryKey = Creating registry key at path {0}... 16 | SettingRegistryKeyValue = Setting the value {0} under the registry key at path {1}... 17 | OverwritingRegistryKeyValue = Overwriting the value {0} under the registry key at path {1}... 18 | RemovingRegistryKey = Removing registry key at path {0}... 19 | RegistryKeyValueAlreadySet = The value {0} under the registry key at path {1} has already been set to the specified value. 20 | RemovingRegistryKeyValue = Removing the value {0} from the registry key at path {1}... 21 | 22 | TestTargetResourceStartMessage = Test-TargetResource is starting for Registry resource with Key {0} 23 | TestTargetResourceEndMessage = Test-TargetResource has finished for Registry resource with Key {0} 24 | RegistryKeyValueTypeDoesNotMatch = The type of the value {0} under the registry key at path {1} does not match the expected type. Expected {2} but was {3}. 25 | RegistryKeyValueDoesNotMatch = The value {0} under the registry key at path {1} does not match the expected value. Expected {2} but was {3}. 26 | 27 | CannotRemoveExistingRegistryKeyWithSubKeysWithoutForce = The registry key at path {0} has subkeys. To remove this registry key please specifiy the Force parameter as $true. 28 | CannotOverwriteExistingRegistryKeyValueWithoutForce = The registry key at path {0} already has a value with the name {1}. To overwrite this registry key value please specifiy the Force parameter as $true. 29 | CannotRemoveExistingRegistryKeyValueWithoutForce = The registry key at path {0} already has a value with the name {1}. To remove this registry key value please specifiy the Force parameter as $true. 30 | RegistryDriveInvalid = The registry drive specified in the registry key path {0} is missing or invalid. 31 | ArrayNotAllowedForExpectedType = The specified value data has been declared as a string array, but the registry key type {0} cannot be converted from an array. Please declare the value data as only one string or use the registry type MultiString. 32 | DWordDataNotInHexFormat = The specified registry key value data {0} is not in the correct hex format to parse as an Int32 (dword). 33 | QWordDataNotInHexFormat = The specified registry key value data {0} is not in the correct hex format to parse as an Int64 (qword). 34 | BinaryDataNotInHexFormat = The specified registry key value data {0} is not in the correct hex format to parse as a Byte array (Binary). 35 | InvalidRegistryDrive = The registry drive {0} is invalid. Please update the Key parameter to include a valid registry drive. 36 | InvalidRegistryDriveAbbreviation = The registry drive abbreviation {0} is invalid. Please update the Key parameter to include a valid registry drive. 37 | RegistryDriveCouldNotBeMounted = The registry drive with the abbreviation {0} could not be mounted. 38 | '@ 39 | -------------------------------------------------------------------------------- /DscResources/MSFT_ScriptResource/MSFT_ScriptResource.schema.mof: -------------------------------------------------------------------------------- 1 | 2 | [ClassVersion("1.0.0"),FriendlyName("Script")] 3 | class MSFT_ScriptResource : OMI_BaseResource 4 | { 5 | [Key, Description("A string that can be used to create a PowerShell script block that retrieves the current state of the resource.")] String GetScript; 6 | [Key, Description("A string that can be used to create a PowerShell script block that sets the resource to the desired state.")] String SetScript; 7 | [Key, Description("A string that can be used to create a PowerShell script block that validates whether or not the resource is in the desired state.")] String TestScript; 8 | [Write, EmbeddedInstance("MSFT_Credential"), Description("The credential of the user account to run the script under if needed.")] String Credential; 9 | [Read, Description("The result from the GetScript script block.")] String Result; 10 | }; 11 | -------------------------------------------------------------------------------- /DscResources/MSFT_ScriptResource/en-US/MSFT_ScriptResource.schema.mfl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowerShell/PSDscResources/7064eda52d939a4a3ce40e1f38756cfe6a09acfd/DscResources/MSFT_ScriptResource/en-US/MSFT_ScriptResource.schema.mfl -------------------------------------------------------------------------------- /DscResources/MSFT_ScriptResource/en-US/MSFT_ScriptResource.strings.psd1: -------------------------------------------------------------------------------- 1 | # Localized MSFT_ScriptResource.strings.psd1 2 | 3 | ConvertFrom-StringData @' 4 | GetTargetResourceStartVerboseMessage = Begin executing get script. 5 | GetScriptThrewError = The get script threw an error. 6 | GetScriptDidNotReturnHashtable = The get script did not return a hashtable. 7 | GetTargetResourceEndVerboseMessage = End executing get script. 8 | SetTargetResourceStartVerboseMessage = Begin executing set script. 9 | SetScriptThrewError = The set script threw an error. 10 | SetTargetResourceEndVerboseMessage = End executing set script. 11 | TestTargetResourceStartVerboseMessage = Begin executing test script. 12 | TestScriptThrewError = The test script threw an error. 13 | TestScriptDidNotReturnBoolean = The test script did not return a boolean. 14 | TestTargetResourceEndVerboseMessage = End executing test script. 15 | ExecutingScriptMessage = Executing script: {0} 16 | '@ 17 | -------------------------------------------------------------------------------- /DscResources/MSFT_ServiceResource/MSFT_ServiceResource.schema.mof: -------------------------------------------------------------------------------- 1 | 2 | [ClassVersion("1.0.0"),FriendlyName("Service")] 3 | class MSFT_ServiceResource : OMI_BaseResource 4 | { 5 | [Key,Description("Indicates the service name. Note that sometimes this is different from the display name. You can get a list of the services and their current state with the Get-Service cmdlet.")] String Name; 6 | [Write,Description("Ensures that the service is present or absent. Defaults to Present."), ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure; 7 | [Write,Description("The path to the service executable file.")] String Path; 8 | [Write,Description("Indicates the startup type for the service."), ValueMap{"Automatic", "Manual", "Disabled"}, Values{"Automatic", "Manual", "Disabled"}] String StartupType; 9 | [Write,Description("Indicates the sign-in account to use for the service."), ValueMap{"LocalSystem", "LocalService", "NetworkService"},Values{"LocalSystem", "LocalService", "NetworkService"}] String BuiltInAccount; 10 | [Write,Description("The credential to run the service under."), EmbeddedInstance("MSFT_Credential")] String Credential; 11 | [Write,Description("The service can create or communicate with a window on the desktop. Must be false for services not running as LocalSystem. Defaults to False.")] Boolean DesktopInteract; 12 | [Write,Description("Indicates the state you want to ensure for the service. Defaults to Running."), ValueMap{"Running", "Stopped", "Ignore"}, Values{"Running", "Stopped", "Ignore"}] String State; 13 | [Write,Description("The display name of the service.")] String DisplayName; 14 | [Write,Description("The description of the service.")] String Description; 15 | [Write,Description("An array of strings indicating the names of the dependencies of the service.")] String Dependencies[]; 16 | [Write,Description("The time to wait for the service to start in milliseconds. Defaults to 30000.")] UInt32 StartupTimeout; 17 | [Write,Description("The time to wait for the service to stop in milliseconds. Defaults to 30000.")] UInt32 TerminateTimeout; 18 | }; 19 | -------------------------------------------------------------------------------- /DscResources/MSFT_ServiceResource/en-US/MSFT_ServiceResource.schema.mfl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowerShell/PSDscResources/7064eda52d939a4a3ce40e1f38756cfe6a09acfd/DscResources/MSFT_ServiceResource/en-US/MSFT_ServiceResource.schema.mfl -------------------------------------------------------------------------------- /DscResources/MSFT_ServiceResource/en-US/MSFT_ServiceResource.strings.psd1: -------------------------------------------------------------------------------- 1 | <# 2 | Localized resources for MSFT_ServiceResource 3 | Strings underneath the blank line are for Grant-LogOnAsServiceRight. 4 | #> 5 | 6 | 7 | ConvertFrom-StringData @' 8 | ServiceExists = Service {0} exists. 9 | ServiceDoesNotExist = Service {0} does not exist. 10 | BuiltInAccountAndCredentialSpecified = Both BuiltInAccount and Credential cannot be specified. Please remove one for service {0}. 11 | ServiceAlreadyAbsent = Service {0} is already absent. No change required. 12 | ServiceDoesNotExistPathMissingError = The service '{0}' does not exist, but Path was not specified. Please specify the path to the executable the service should run to create a new service. 13 | CreatingService = Creating new service {0}... 14 | EditingServiceProperties = Editing the properties of service {0}... 15 | RemovingService = Removing the service {0}... 16 | RestartingService = Restarting the service {0}... 17 | ServicePathMatches = The path of service {0} matches the expected path. 18 | ServicePathDoesNotMatch = The path of service {0} does not match the expected path. 19 | ServiceDepdenciesMatch = The dependencies of service {0} match the expected dependencies. 20 | ServiceDepdenciesDoNotMatch = The dependencies of service {0} do not match the expected dependencies. 21 | ServiceStartupTypeMatches = The start mode of service {0} matches the expected start mode. 22 | ServiceStartupTypeDoesNotMatch = The start mode of service {0} does not match the expected start mode. 23 | ServicePropertyDoesNotMatch = The service property {0} of service {1} does not match the expected value. The expected value is {2}. The actual value is {3}. 24 | ServiceCredentialDoesNotMatch = The start name of service {0} does not match the expected username from the given credential. The expected value is {1}. The actual value is {2}. 25 | ServiceDeletionSucceeded = The service {0} has been successfully deleted. 26 | ServiceDeletionFailed = Failed to delete service {0}. 27 | WaitingForServiceDeletion = Waiting for service {0} to be deleted. 28 | ErrorSettingLogOnAsServiceRightsForUser = Error granting user {0} the right to log on as a service. Error message: '{1}' 29 | StartupTypeStateConflict = Service {0} cannot have a startup type of {1} and a state of {2} at the same time. 30 | InvokeCimMethodFailed = The CIM method {0} failed on service {1} while attempting to update the {2} property(s) with the error code {3}. 31 | 32 | CannotOpenPolicyErrorMessage = Cannot open policy manager. 33 | UserNameTooLongErrorMessage = User name is too long. 34 | CannotLookupNamesErrorMessage = Failed to lookup user name. 35 | CannotOpenAccountErrorMessage = Failed to open policy for user. 36 | CannotCreateAccountAccessErrorMessage = Failed to create policy for user. 37 | CannotGetAccountAccessErrorMessage = Failed to get user policy rights. 38 | CannotSetAccountAccessErrorMessage = Failed to set user policy rights. 39 | '@ 40 | -------------------------------------------------------------------------------- /DscResources/MSFT_UserResource/MSFT_UserResource.schema.mof: -------------------------------------------------------------------------------- 1 | [ClassVersion("1.0.0"), FriendlyName("User")] 2 | class MSFT_UserResource : OMI_BaseResource 3 | { 4 | [Key,Description("The name of the User to Create/Modify/Delete")] String UserName; 5 | [Write,Description("An enumerated value that describes if the user is expected to exist on the machine"),ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] String Ensure; 6 | [Write,Description("The display name of the user")] String FullName; 7 | [Write,Description("A description for the user")] String Description; 8 | [Write,Description("The password for the user"),EmbeddedInstance("MSFT_Credential")] String Password; 9 | [Write,Description("Value used to disable/enable a user account")] Boolean Disabled; 10 | [Write,Description("Value used to set whether a user's password expires or not")] Boolean PasswordNeverExpires; 11 | [Write,Description("Value used to require a user to change their password")] Boolean PasswordChangeRequired; 12 | [Write,Description("Value used to set whether a user can/cannot change their password")] Boolean PasswordChangeNotAllowed; 13 | }; 14 | -------------------------------------------------------------------------------- /DscResources/MSFT_UserResource/en-US/MSFT_UserResource.schema.mfl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowerShell/PSDscResources/7064eda52d939a4a3ce40e1f38756cfe6a09acfd/DscResources/MSFT_UserResource/en-US/MSFT_UserResource.schema.mfl -------------------------------------------------------------------------------- /DscResources/MSFT_UserResource/en-US/MSFT_UserResource.strings.psd1: -------------------------------------------------------------------------------- 1 | # Localized resources for User 2 | 3 | ConvertFrom-StringData @' 4 | UserWithName = User: {0} 5 | RemoveOperation = Remove 6 | AddOperation = Add 7 | SetOperation = Set 8 | ConfigurationStarted = Configuration of user {0} started. 9 | ConfigurationCompleted = Configuration of user {0} completed successfully. 10 | UserCreated = User {0} created successfully. 11 | UserUpdated = User {0} properties updated successfully. 12 | UserRemoved = User {0} removed successfully. 13 | NoConfigurationRequired = User {0} exists on this node with the desired properties. No action required. 14 | NoConfigurationRequiredUserDoesNotExist = User {0} does not exist on this node. No action required. 15 | InvalidUserName = The name {0} cannot be used. Names may not consist entirely of periods and/or spaces, or contain these characters: {1} 16 | UserExists = A user with the name {0} exists. 17 | UserDoesNotExist = A user with the name {0} does not exist. 18 | PropertyMismatch = The value of the {0} property is expected to be {1} but it is {2}. 19 | PasswordPropertyMismatch = The value of the {0} property does not match. 20 | AllUserPropertiesMatch = All {0} {1} properties match. 21 | MultipleMatches = There could be a possible multiple matches exception while trying to use the System.DirectoryServices API's. 22 | '@ 23 | -------------------------------------------------------------------------------- /DscResources/MSFT_WindowsFeature/MSFT_WindowsFeature.schema.mof: -------------------------------------------------------------------------------- 1 | 2 | [ClassVersion("1.0.0.0"), FriendlyName("WindowsFeature")] 3 | class MSFT_WindowsFeature : OMI_BaseResource 4 | { 5 | [Key, Description("The name of the role or feature to install or uninstall.")] String Name; 6 | [Write, Description("Specifies whether the role or feature should be installed or uninstalled. To install the feature, set this property to Present. To uninstall the feature, set the property to Absent."), ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure; 7 | [Write, Description("Specifies whether the subfeatures of the main feature should also be installed.")] Boolean IncludeAllSubFeature; 8 | [Write, Description("The path to the log file to log this operation.")] String LogPath; 9 | [Write, Description("A credential, if needed, to install or uninstall the role or feature."), EmbeddedInstance("MSFT_Credential")] String Credential; 10 | [Read, Description("The display name of the retrieved role or feature.")] String DisplayName; 11 | }; 12 | -------------------------------------------------------------------------------- /DscResources/MSFT_WindowsFeature/en-US/MSFT_WindowsFeature.schema.mfl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowerShell/PSDscResources/7064eda52d939a4a3ce40e1f38756cfe6a09acfd/DscResources/MSFT_WindowsFeature/en-US/MSFT_WindowsFeature.schema.mfl -------------------------------------------------------------------------------- /DscResources/MSFT_WindowsFeature/en-US/MSFT_WindowsFeature.strings.psd1: -------------------------------------------------------------------------------- 1 | # Localized strings for MSFT_WindowsFeature.psd1 2 | 3 | ConvertFrom-StringData @' 4 | FeatureNotFoundError = The requested feature {0} could not be found on the target machine. 5 | MultipleFeatureInstancesError = Failure to get the requested feature {0} information from the target machine. Wildcard pattern is not supported in the feature name. 6 | FeatureInstallationFailureError = Failure to successfully install the feature {0} . 7 | FeatureUninstallationFailureError = Failure to successfully uninstall the feature {0} . 8 | QueryFeature = Querying for feature {0} using Server Manager cmdlet Get-WindowsFeature. 9 | InstallFeature = Trying to install feature {0} using Server Manager cmdlet Add-WindowsFeature. 10 | UninstallFeature = Trying to uninstall feature {0} using Server Manager cmdlet Remove-WindowsFeature. 11 | RestartNeeded = The Target machine needs to be restarted. 12 | GetTargetResourceStartMessage = Begin executing Get functionality on the {0} feature. 13 | GetTargetResourceEndMessage = End executing Get functionality on the {0} feature. 14 | SetTargetResourceStartMessage = Begin executing Set functionality on the {0} feature. 15 | SetTargetResourceEndMessage = End executing Set functionality on the {0} feature. 16 | TestTargetResourceStartMessage = Begin executing Test functionality on the {0} feature. 17 | TestTargetResourceEndMessage = End executing Test functionality on the {0} feature. 18 | ServerManagerModuleNotFoundMessage = ServerManager module is not installed on the machine. 19 | SkuNotSupported = Installing roles and features using PowerShell Desired State Configuration is supported only on Server SKU's. It is not supported on Client SKU. 20 | EnableServerManagerPSHCmdletsFeature = Windows Server 2008R2 Core operating system detected: ServerManager-PSH-Cmdlets feature has been enabled. 21 | UninstallSuccess = Successfully uninstalled the feature {0}. 22 | InstallSuccess = Successfully installed the feature {0}. 23 | IdentityNotFoundMessage = Some or all identity references could not be translated. 24 | '@ 25 | -------------------------------------------------------------------------------- /DscResources/MSFT_WindowsOptionalFeature/MSFT_WindowsOptionalFeature.schema.mof: -------------------------------------------------------------------------------- 1 | 2 | [ClassVersion("1.0.0.0"), FriendlyName("WindowsOptionalFeature")] 3 | class MSFT_WindowsOptionalFeature : OMI_BaseResource 4 | { 5 | [Key, Description("The name of the feature to enable or disable.")] String Name; 6 | [Write, Description("Specifies whether the feature should be enabled or disabled. To enable the feature, set this property to Present. To disable the feature, set the property to Absent."), ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure; 7 | [Write, Description("Specifies that all files associated with the feature should be removed if the feature is being disabled.")] Boolean RemoveFilesOnDisable; 8 | [Write, Description("Specifies whether or not DISM contacts Windows Update (WU) when searching for the source files to enable the feature. If $true, DISM will not contact WU.")] Boolean NoWindowsUpdateCheck; 9 | [Write, Description("The maximum output level to show in the log. Accepted values are: ErrorsOnly (only errors are logged), ErrorsAndWarning (errors and warnings are logged), and ErrorsAndWarningAndInformation (errors, warnings, and debug information are logged)."), ValueMap{"ErrorsOnly", "ErrorsAndWarning", "ErrorsAndWarningAndInformation"}, Values{"ErrorsOnly", "ErrorsAndWarning", "ErrorsAndWarningAndInformation"}] String LogLevel; 10 | [Write, Description("The path to the log file to log this operation.")] String LogPath; 11 | [Read, Description("The custom properties retrieved from the Windows optional feature as an array of strings.")] String CustomProperties[]; 12 | [Read, Description("The description retrieved from the Windows optional feature.")] String Description; 13 | [Read, Description("The display name retrieved from the Windows optional feature.")] String DisplayName; 14 | }; 15 | -------------------------------------------------------------------------------- /DscResources/MSFT_WindowsOptionalFeature/en-US/MSFT_WindowsOptionalFeature.schema.mfl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowerShell/PSDscResources/7064eda52d939a4a3ce40e1f38756cfe6a09acfd/DscResources/MSFT_WindowsOptionalFeature/en-US/MSFT_WindowsOptionalFeature.schema.mfl -------------------------------------------------------------------------------- /DscResources/MSFT_WindowsOptionalFeature/en-US/MSFT_WindowsOptionalFeature.strings.psd1: -------------------------------------------------------------------------------- 1 | # Localized resources for WindowsOptionalFeature 2 | 3 | ConvertFrom-StringData @' 4 | DismNotAvailable = PowerShell module DISM could not be imported. 5 | NotSupportedSku = This resource is available only on Windows client operating systems and Windows Server 2012 or later. 6 | ElevationRequired = This resource must run as an Administrator. 7 | ValidatingPrerequisites = Validating resource prerequisites... 8 | CouldNotConvertFeatureState = Could not convert feature state '{0}' into Absent or Present. 9 | RestartNeeded = Target machine needs to restart. 10 | GetTargetResourceStartMessage = Started Get-TargetResource on the {0} feature. 11 | GetTargetResourceEndMessage = Finished Get-TargetResource on the {0} feature. 12 | SetTargetResourceStartMessage = Started Set-TargetResource on the {0} feature. 13 | SetTargetResourceEndMessage = Finished Set-TargetResource on the {0} feature. 14 | TestTargetResourceStartMessage = Started Test-TargetResource on the {0} feature. 15 | TestTargetResourceEndMessage = Finished Test-TargetResource on the {0} feature. 16 | FeatureInstalled = Installed feature {0}. 17 | FeatureUninstalled = Uninstalled feature {0}. 18 | ShouldProcessEnableFeature = Enable Windows optional feature 19 | ShouldProcessDisableFeature = Disable Windows optional feature 20 | '@ 21 | -------------------------------------------------------------------------------- /DscResources/MSFT_WindowsPackageCab/MSFT_WindowsPackageCab.schema.mof: -------------------------------------------------------------------------------- 1 | 2 | [ClassVersion("1.0.0.0"), FriendlyName("WindowsPackageCab")] 3 | class MSFT_WindowsPackageCab : OMI_BaseResource 4 | { 5 | [Key, Description("The name of the package to install or uninstall.")] String Name; 6 | [Required, Description("Specifies whether the package should be installed or uninstalled. To install the package, set this property to Present. To uninstall the package, set the property to Absent."), ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure; 7 | [Required, Description("The path to the cab file to install or uninstall the package from.")] String SourcePath; 8 | [Write, Description("The path to a file to log the operation to.")] String LogPath; 9 | }; 10 | -------------------------------------------------------------------------------- /DscResources/MSFT_WindowsPackageCab/en-US/MSFT_WindowsPackageCab.schema.mfl: -------------------------------------------------------------------------------- 1 | [Description("This resource is used to install or uninstall a package from a windows cabinet (cab) file.") : Amended,AMENDMENT, LOCALE("MS_409")] 2 | class MSFT_WindowsPackageCab : OMI_BaseResource 3 | { 4 | [Key, Description("The name of the package to install or uninstall.") : Amended] String Name; 5 | [Description("Specifies whether the package should be installed or uninstalled. To install the package, set this property to Present. To uninstall the package, set the property to Absent.") : Amended] String Ensure; 6 | [Description("The path to the cab file to install or uninstall the package from.") : Amended] String SourcePath; 7 | [Description("The path to a file to log the operation to.") : Amended] String LogPath; 8 | }; 9 | -------------------------------------------------------------------------------- /DscResources/MSFT_WindowsPackageCab/en-US/MSFT_WindowsPackageCab.strings.psd1: -------------------------------------------------------------------------------- 1 | # Localized resources for WindowsPackageCab 2 | 3 | ConvertFrom-StringData @' 4 | RetrievingPackage = Retrieving information for the package {0} 5 | PackageEnsureState = The package {0} is currently {1} 6 | SourcePathDoesNotExist = Could not find the source file at path {0} 7 | SetTargetResourceStarting = Starting configuration of the WindowsPackageCab resource {0} 8 | SetTargetResourceFinished = Finished configuration of WindowsPackageCab resource {0} 9 | AddingPackage = Adding a package from the source at path {0} 10 | RemovingPackage = Removing package from the source at path {0} 11 | EnsureStatesMatch = Ensure states match for package {0} 12 | EnsureStatesDoNotMatch = Ensure states do not match for package {0} 13 | '@ 14 | -------------------------------------------------------------------------------- /DscResources/MSFT_WindowsProcess/MSFT_WindowsProcess.schema.mof: -------------------------------------------------------------------------------- 1 | [ClassVersion("1.0.0"), FriendlyName("WindowsProcess")] 2 | class MSFT_WindowsProcess : OMI_BaseResource 3 | { 4 | [Key, Description("The full path or file name to the process executable to start or stop.")] String Path; 5 | [Key, Description("A string of arguments to pass to the process executable. Pass in an empty string if no arguments are needed.")] String Arguments; 6 | [Write, EmbeddedInstance("MSFT_Credential"), Description("The credential to run the process under.")] String Credential; 7 | [Write, ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}, Description("Indicates whether the process is present (running) or absent (not running).")] String Ensure; 8 | [Write, Description("The path to write the standard output stream to.")] String StandardOutputPath; 9 | [Write, Description("The path to write the standard error stream to.")] String StandardErrorPath; 10 | [Write, Description("The path to receive standard input from.")] String StandardInputPath; 11 | [Write, Description("The directory to run the processes under.")] String WorkingDirectory; 12 | [Read, Description("The amount of paged memory, in bytes, allocated for the process.")] UInt64 PagedMemorySize; 13 | [Read, Description("The amount of nonpaged memory, in bytes, allocated for the process.")] UInt64 NonPagedMemorySize; 14 | [Read, Description("The amount of virtual memory, in bytes, allocated for the process.")] UInt64 VirtualMemorySize; 15 | [Read, Description("The number of handles opened by the process.")] SInt32 HandleCount; 16 | [Read, Description("The unique identifier of the process.")] SInt32 ProcessId; 17 | [Read, Description("The number of instances of the given process that are currently running.")] SInt32 ProcessCount; 18 | }; 19 | -------------------------------------------------------------------------------- /DscResources/MSFT_WindowsProcess/en-US/MSFT_WindowsProcess.schema.mfl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowerShell/PSDscResources/7064eda52d939a4a3ce40e1f38756cfe6a09acfd/DscResources/MSFT_WindowsProcess/en-US/MSFT_WindowsProcess.schema.mfl -------------------------------------------------------------------------------- /DscResources/MSFT_WindowsProcess/en-US/MSFT_WindowsProcess.strings.psd1: -------------------------------------------------------------------------------- 1 | # Localized resources for MSFT_WindowsProcess 2 | 3 | ConvertFrom-StringData @' 4 | CouldNotCreateProcessError = Could not create process. Error code: 5 | DuplicateTokenError = Duplicate token. Error code: 6 | FileNotFound = File '{0}' not found in the environment path. 7 | ErrorInvalidUserName = Invalid username: {0}. Username cannot contain multiple '@' or multiple '\' 8 | ErrorParametersNotSupportedWithCredential = Can't specify StandardOutputPath, StandardInputPath or WorkingDirectory when trying to run a process under a local user. 9 | ErrorRunAsCredentialParameterNotSupported = The PsDscRunAsCredential parameter is not supported by the Process resource. To start the process with user '{0}', add the Credential parameter. 10 | ErrorStarting = Failure starting process matching path '{0}'. Message: {1}. 11 | ErrorStopping = Failure stopping processes matching path '{0}' with IDs '({1})'. Message: {2}. 12 | FailureWaitingForProcessesToStart = Failed to wait for processes to start. 13 | FailureWaitingForProcessesToStop = Failed to wait for processes to stop. 14 | GetTargetResourceStartMessage = Begin executing Get functionality for the process {0}. 15 | GetTargetResourceEndMessage = End executing Get functionality for the process {0}. 16 | OpenProcessTokenError = Error while opening process token. Error code: 17 | ParameterShouldNotBeSpecified = Parameter {0} should not be specified. 18 | PathShouldBeAbsolute = The path '{0}' should be absolute for argument '{1}'. 19 | PathShouldExist = The path '{0}' should exist for argument '{1}'. 20 | PrivilegeLookingUpError = Error while looking up privilege. Error code: 21 | ProcessAlreadyStarted = Process matching path '{0}' found running. No action required. 22 | ProcessAlreadyStopped = Process matching path '{0}' not found running. No action required. 23 | ProcessesStarted = Processes matching path '{0}' started. 24 | ProcessesStopped = Processes matching path '{0}' with IDs '({1})' stopped. 25 | RetriveStatusError = Failed to retrieve status. Error code: 26 | SetTargetResourceStartMessage = Begin executing Set functionality for the process {0}. 27 | SetTargetResourceEndMessage = End executing Set functionality for the process {0}. 28 | StartingProcessWhatif = Start-Process. 29 | StoppingProcessWhatIf = Stop-Process. 30 | TestTargetResourceStartMessage = Begin executing Test functionality for the process {0}. 31 | TestTargetResourceEndMessage = End executing Test functionality for the process {0}. 32 | TokenElevationError = Error while getting token elevation. Error code: 33 | UserCouldNotBeLoggedError = User could not be logged. Error code: 34 | WaitFailedError = Failed while waiting for process. Error code: 35 | VerboseInProcessHandle = In process handle {0}. 36 | '@ 37 | -------------------------------------------------------------------------------- /DscResources/ProcessSet/ProcessSet.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 3 | # Script module or binary module file associated with this manifest. 4 | RootModule = 'ProcessSet.schema.psm1' 5 | 6 | # Version number of this module. 7 | ModuleVersion = '0.1.0.0' 8 | 9 | # ID used to uniquely identify this module 10 | GUID = '0cb71def-366f-4f3b-88a9-b9b37d266dd6' 11 | 12 | # Author of this module 13 | Author = 'Microsoft Corporation' 14 | 15 | # Company or vendor of this module 16 | CompanyName = 'Microsoft Corporation' 17 | 18 | # Copyright statement for this module 19 | Copyright = '(c) 2016 Microsoft. All rights reserved.' 20 | 21 | # Description of the functionality provided by this module 22 | Description = 'Provides a mechanism to configure and manage multiple WindowsProcess resources on a target node.' 23 | 24 | # Minimum version of the Windows PowerShell engine required by this module 25 | PowerShellVersion = '5.1' 26 | 27 | } 28 | -------------------------------------------------------------------------------- /DscResources/ProcessSet/ProcessSet.schema.psm1: -------------------------------------------------------------------------------- 1 | $errorActionPreference = 'Stop' 2 | Set-StrictMode -Version 'Latest' 3 | 4 | # Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock 5 | $script:dscResourcesFolderFilePath = Split-Path -Path $PSScriptRoot -Parent 6 | $script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'ResourceSetHelper.psm1' 7 | Import-Module -Name $script:resourceSetHelperFilePath 8 | 9 | <# 10 | .SYNOPSIS 11 | A composite DSC resource to configure a set of similar WindowsProcess resources. 12 | No arguments can be passed into these WindowsProcess resources. 13 | 14 | .DESCRIPTION 15 | A composite DSC resource to configure a set of similar WindowsProcess resources. 16 | 17 | .PARAMETER Path 18 | The file paths to the executables of the processes to start or stop. Only the names of the 19 | files may be specified if they are all accessible through the environment path. Relative 20 | paths are not supported. 21 | 22 | .PARAMETER Ensure 23 | Specifies whether or not the processes should exist. 24 | 25 | To start processes, set this property to Present. 26 | To stop processes, set this property to Absent. 27 | 28 | .PARAMETER Credential 29 | The credential of the user account to start the processes under. 30 | 31 | .PARAMETER StandardOutputPath 32 | The file path to write the standard output to. Any existing file at this path 33 | will be overwritten.This property cannot be specified at the same time as Credential 34 | when running the processes as a local user. 35 | 36 | .PARAMETER StandardErrorPath 37 | The file path to write the standard error output to. Any existing file at this path 38 | will be overwritten. 39 | 40 | .PARAMETER StandardInputPath 41 | The file path to get standard input from. This property cannot be specified at the 42 | same time as Credential when running the processes as a local user. 43 | 44 | .PARAMETER WorkingDirectory 45 | The file path to use as the working directory for the processes. Any existing file 46 | at this path will be overwritten. This property cannot be specified at the same time 47 | as Credential when running the processes as a local user. 48 | #> 49 | Configuration ProcessSet 50 | { 51 | [CmdletBinding()] 52 | param 53 | ( 54 | [Parameter(Mandatory = $true)] 55 | [ValidateNotNullOrEmpty()] 56 | [System.String[]] 57 | $Path, 58 | 59 | [Parameter()] 60 | [ValidateSet('Present', 'Absent')] 61 | [System.String] 62 | $Ensure, 63 | 64 | [Parameter()] 65 | [ValidateNotNullOrEmpty()] 66 | [System.Management.Automation.PSCredential] 67 | [System.Management.Automation.Credential()] 68 | $Credential, 69 | 70 | [Parameter()] 71 | [ValidateNotNullOrEmpty()] 72 | [System.String] 73 | $StandardOutputPath, 74 | 75 | [Parameter()] 76 | [ValidateNotNullOrEmpty()] 77 | [System.String] 78 | $StandardErrorPath, 79 | 80 | [Parameter()] 81 | [ValidateNotNullOrEmpty()] 82 | [System.String] 83 | $StandardInputPath, 84 | 85 | [Parameter()] 86 | [ValidateNotNullOrEmpty()] 87 | [System.String] 88 | $WorkingDirectory 89 | ) 90 | 91 | $newResourceSetConfigurationParams = @{ 92 | ResourceName = 'WindowsProcess' 93 | ModuleName = 'PSDscResources' 94 | KeyParameterName = 'Path' 95 | Parameters = $PSBoundParameters 96 | } 97 | 98 | # Arguments is a key parameter in WindowsProcess resource. Adding it as a common parameter with an empty value string 99 | $newResourceSetConfigurationParams['Parameters']['Arguments'] = '' 100 | 101 | $configurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams 102 | 103 | # This script block must be run directly in this configuration in order to resolve variables 104 | . $configurationScriptBlock 105 | } 106 | -------------------------------------------------------------------------------- /DscResources/ServiceSet/ServiceSet.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 3 | # Script module or binary module file associated with this manifest. 4 | RootModule = 'ServiceSet.schema.psm1' 5 | 6 | # Version number of this module. 7 | ModuleVersion = '0.1.0.0' 8 | 9 | # ID used to uniquely identify this module 10 | GUID = 'c3ac5e1f-c1fd-4ed0-be24-b271c7062484' 11 | 12 | # Author of this module 13 | Author = 'Microsoft Corporation' 14 | 15 | # Company or vendor of this module 16 | CompanyName = 'Microsoft Corporation' 17 | 18 | # Copyright statement for this module 19 | Copyright = '(c) 2016 Microsoft. All rights reserved.' 20 | 21 | # Description of the functionality provided by this module 22 | Description = 'Allows starting, stopping and change in state or account type for a group of services.' 23 | 24 | # Minimum version of the Windows PowerShell engine required by this module 25 | PowerShellVersion = '5.1' 26 | 27 | } 28 | -------------------------------------------------------------------------------- /DscResources/ServiceSet/ServiceSet.schema.psm1: -------------------------------------------------------------------------------- 1 | $errorActionPreference = 'Stop' 2 | Set-StrictMode -Version 'Latest' 3 | 4 | # Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock 5 | $script:dscResourcesFolderFilePath = Split-Path -Path $PSScriptRoot -Parent 6 | $script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'ResourceSetHelper.psm1' 7 | Import-Module -Name $script:resourceSetHelperFilePath 8 | 9 | <# 10 | .SYNOPSIS 11 | A composite DSC resource to configure a set of similar Service resources. 12 | 13 | .DESCRIPTION 14 | A composite DSC resource to configure a set of similar Service resources. 15 | 16 | .PARAMETER Name 17 | An array of the names of the services to configure. 18 | 19 | .PARAMETER Ensure 20 | Specifies whether or not the set of services should exist. 21 | 22 | Set this property to Present to modify a set of services. 23 | Set this property to Absent to remove a set of services. 24 | 25 | .PARAMETER StartupType 26 | The startup type each service in the set should have. 27 | 28 | .PARAMETER BuiltInAccount 29 | The built-in account each service in the set should start under. 30 | 31 | Cannot be specified at the same time as Credential. 32 | 33 | The user account specified by this property must have access to the service 34 | executable paths in order to start the services. 35 | 36 | .PARAMETER State 37 | The state each service in the set should be in. 38 | From the default value defined in Service, the default will be Running. 39 | 40 | .PARAMETER Credential 41 | The credential of the user account each service in the set should start under. 42 | 43 | Cannot be specified at the same time as BuiltInAccount. 44 | 45 | The user specified by this credential will automatically be granted the Log on as a Service 46 | right. The user account specified by this property must have access to the service 47 | executable paths in order to start the services. 48 | #> 49 | Configuration ServiceSet 50 | { 51 | [CmdletBinding()] 52 | param 53 | ( 54 | [Parameter(Mandatory = $true)] 55 | [ValidateNotNullOrEmpty()] 56 | [System.String[]] 57 | $Name, 58 | 59 | [Parameter()] 60 | [ValidateSet('Present', 'Absent')] 61 | [System.String] 62 | $Ensure, 63 | 64 | [Parameter()] 65 | [ValidateSet('Automatic', 'Manual', 'Disabled')] 66 | [System.String] 67 | $StartupType, 68 | 69 | [Parameter()] 70 | [ValidateSet('LocalSystem', 'LocalService', 'NetworkService')] 71 | [System.String] 72 | $BuiltInAccount, 73 | 74 | [Parameter()] 75 | [ValidateSet('Running', 'Stopped', 'Ignore')] 76 | [System.String] 77 | $State, 78 | 79 | [Parameter()] 80 | [ValidateNotNull()] 81 | [System.Management.Automation.PSCredential] 82 | [System.Management.Automation.Credential()] 83 | $Credential 84 | ) 85 | 86 | $newResourceSetConfigurationParams = @{ 87 | ResourceName = 'Service' 88 | ModuleName = 'PSDscResources' 89 | KeyParameterName = 'Name' 90 | Parameters = $PSBoundParameters 91 | } 92 | 93 | $configurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams 94 | 95 | # This script block must be run directly in this configuration in order to resolve variables 96 | . $configurationScriptBlock 97 | } 98 | -------------------------------------------------------------------------------- /DscResources/WindowsFeatureSet/WindowsFeatureSet.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 3 | # Script module or binary module file associated with this manifest. 4 | RootModule = 'WindowsFeatureSet.schema.psm1' 5 | 6 | # Version number of this module. 7 | ModuleVersion = '0.1.0.0' 8 | 9 | # ID used to uniquely identify this module 10 | GUID = 'b18a27e2-f710-4a4a-92b8-6cd076970eb2' 11 | 12 | # Author of this module 13 | Author = 'Microsoft Corporation' 14 | 15 | # Company or vendor of this module 16 | CompanyName = 'Microsoft Corporation' 17 | 18 | # Copyright statement for this module 19 | Copyright = '(c) 2016 Microsoft. All rights reserved.' 20 | 21 | # Description of the functionality provided by this module 22 | Description = 'Provides a mechanism to configure and manage multiple WindowsFeature resources on a target node.' 23 | 24 | # Minimum version of the Windows PowerShell engine required by this module 25 | PowerShellVersion = '5.1' 26 | 27 | } 28 | -------------------------------------------------------------------------------- /DscResources/WindowsFeatureSet/WindowsFeatureSet.schema.psm1: -------------------------------------------------------------------------------- 1 | $errorActionPreference = 'Stop' 2 | Set-StrictMode -Version 'Latest' 3 | 4 | # Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock 5 | $script:dscResourcesFolderFilePath = Split-Path -Path $PSScriptRoot -Parent 6 | $script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'ResourceSetHelper.psm1' 7 | Import-Module -Name $script:resourceSetHelperFilePath 8 | 9 | <# 10 | .SYNOPSIS 11 | A composite DSC resource to configure a set of similar WindowsFeature resources. 12 | 13 | .DESCRIPTION 14 | A composite DSC resource to configure a set of similar WindowsFeature resources. 15 | 16 | .PARAMETER Name 17 | The name of the roles or features to install or uninstall. 18 | 19 | .PARAMETER Ensure 20 | Specifies whether the roles or features should be installed or uninstalled. 21 | 22 | To install the features, set this property to Present. 23 | To uninstall the features, set this property to Absent. 24 | 25 | .PARAMETER IncludeAllSubFeature 26 | Specifies whether or not all subfeatures should be installed or uninstalled alongside the specified roles or features. 27 | 28 | If this property is true and Ensure is set to Present, all subfeatures will be installed. 29 | If this property is false and Ensure is set to Present, subfeatures will not be installed or uninstalled. 30 | If Ensure is set to Absent, all subfeatures will be uninstalled. 31 | 32 | .PARAMETER Credential 33 | The credential of the user account under which to install or uninstall the roles or features. 34 | 35 | .PARAMETER LogPath 36 | The custom file path to which to log this operation. 37 | If not passed in, the default log path will be used (%windir%\logs\ServerManager.log). 38 | #> 39 | Configuration WindowsFeatureSet 40 | { 41 | [CmdletBinding()] 42 | param 43 | ( 44 | [Parameter(Mandatory = $true)] 45 | [ValidateNotNullOrEmpty()] 46 | [System.String[]] 47 | $Name, 48 | 49 | [Parameter()] 50 | [ValidateSet('Present', 'Absent')] 51 | [System.String] 52 | $Ensure, 53 | 54 | [Parameter()] 55 | [ValidateNotNullOrEmpty()] 56 | [System.String] 57 | $Source, 58 | 59 | [Parameter()] 60 | [System.Boolean] 61 | $IncludeAllSubFeature, 62 | 63 | [Parameter()] 64 | [ValidateNotNull()] 65 | [System.Management.Automation.PSCredential] 66 | [System.Management.Automation.Credential()] 67 | $Credential, 68 | 69 | [Parameter()] 70 | [ValidateNotNullOrEmpty()] 71 | [System.String] 72 | $LogPath 73 | ) 74 | 75 | $newResourceSetConfigurationParams = @{ 76 | ResourceName = 'WindowsFeature' 77 | ModuleName = 'PSDscResources' 78 | KeyParameterName = 'Name' 79 | Parameters = $PSBoundParameters 80 | } 81 | 82 | $configurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams 83 | 84 | # This script block must be run directly in this configuration in order to resolve variables 85 | . $configurationScriptBlock 86 | } 87 | -------------------------------------------------------------------------------- /DscResources/WindowsOptionalFeatureSet/WindowsOptionalFeatureSet.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | 3 | # Script module or binary module file associated with this manifest. 4 | RootModule = 'WindowsOptionalFeatureSet.schema.psm1' 5 | 6 | # Version number of this module. 7 | ModuleVersion = '0.1.0.0' 8 | 9 | # ID used to uniquely identify this module 10 | GUID = 'a88c1458-db46-402c-947b-7d43ab57e27a' 11 | 12 | # Author of this module 13 | Author = 'Microsoft Corporation' 14 | 15 | # Company or vendor of this module 16 | CompanyName = 'Microsoft Corporation' 17 | 18 | # Copyright statement for this module 19 | Copyright = '(c) 2016 Microsoft. All rights reserved.' 20 | 21 | # Description of the functionality provided by this module 22 | Description = 'Provides a mechanism to configure and manage multiple WindowsOptionalFeature resources on a target node.' 23 | 24 | # Minimum version of the Windows PowerShell engine required by this module 25 | PowerShellVersion = '5.1' 26 | 27 | } 28 | -------------------------------------------------------------------------------- /DscResources/WindowsOptionalFeatureSet/WindowsOptionalFeatureSet.schema.psm1: -------------------------------------------------------------------------------- 1 | $errorActionPreference = 'Stop' 2 | Set-StrictMode -Version 'Latest' 3 | 4 | # Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock 5 | $script:dscResourcesFolderFilePath = Split-Path -Path $PSScriptRoot -Parent 6 | $script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'ResourceSetHelper.psm1' 7 | Import-Module -Name $script:resourceSetHelperFilePath 8 | 9 | <# 10 | .SYNOPSIS 11 | A composite DSC resource to configure a set of similar WindowsOptionalFeature resources. 12 | 13 | .DESCRIPTION 14 | A composite DSC resource to configure a set of similar WindowsOptionalFeature resources. 15 | 16 | .PARAMETER Name 17 | The names of the Windows optional features to enable or disable. 18 | 19 | .PARAMETER Ensure 20 | Specifies whether the features should be enabled or disabled. 21 | 22 | To enable a set of features, set this property to Present. 23 | To disable a set of features, set this property to Absent. 24 | 25 | .PARAMETER RemoveFilesOnDisable 26 | Specifies whether or not to remove all files associated with the features when they are 27 | disabled. 28 | 29 | .PARAMETER NoWindowsUpdateCheck 30 | Specifies whether or not DISM should contact Windows Update (WU) when searching for the 31 | source files to restore Windows optional features on an online image. 32 | 33 | .PARAMETER LogPath 34 | The file path to which to log the opertation. 35 | 36 | .PARAMETER LogLevel 37 | The level of detail to include in the log. 38 | #> 39 | Configuration WindowsOptionalFeatureSet 40 | { 41 | [CmdletBinding()] 42 | param 43 | ( 44 | [Parameter(Mandatory = $true)] 45 | [ValidateNotNullOrEmpty()] 46 | [System.String[]] 47 | $Name, 48 | 49 | [Parameter(Mandatory = $true)] 50 | [ValidateSet('Present', 'Absent')] 51 | [System.String] 52 | $Ensure, 53 | 54 | [Parameter()] 55 | [System.Boolean] 56 | $RemoveFilesOnDisable, 57 | 58 | [Parameter()] 59 | [System.Boolean] 60 | $NoWindowsUpdateCheck, 61 | 62 | [Parameter()] 63 | [ValidateNotNullOrEmpty()] 64 | [System.String] 65 | $LogPath, 66 | 67 | [Parameter()] 68 | [ValidateSet('ErrorsOnly', 'ErrorsAndWarning', 'ErrorsAndWarningAndInformation')] 69 | [System.String] 70 | $LogLevel 71 | ) 72 | 73 | $newResourceSetConfigurationParams = @{ 74 | ResourceName = 'WindowsOptionalFeature' 75 | ModuleName = 'PSDscResources' 76 | KeyParameterName = 'Name' 77 | Parameters = $PSBoundParameters 78 | } 79 | 80 | $configurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams 81 | 82 | # This script block must be run directly in this configuration in order to resolve variables 83 | . $configurationScriptBlock 84 | } 85 | -------------------------------------------------------------------------------- /Examples/Sample_Archive_ExpandArchiveChecksumAndForce.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Expands the archive located at 'C:\ExampleArchivePath\Archive.zip' to the destination path 4 | 'C:\ExampleDestinationPath\Destination'. 5 | 6 | Since Validate is specified as $true and the Checksum parameter is specified as SHA-256, the 7 | resource will check if the SHA-256 hash of the file in the archive matches the SHA-256 hash 8 | of the corresponding file at the destination and replace any files that do not match. 9 | 10 | Since Force is specified as $true, the resource will overwrite any mismatching files at the 11 | destination. If Force is specified as $false, the resource will throw an error instead of 12 | overwrite any files at the destination. 13 | #> 14 | Configuration Sample_Archive_ExpandArchiveChecksumAndForce 15 | { 16 | Import-DscResource -ModuleName 'PSDscResources' 17 | 18 | Node localhost 19 | { 20 | Archive Archive4 21 | { 22 | Path = 'C:\ExampleArchivePath\Archive.zip' 23 | Destination = 'C:\ExampleDestinationPath\Destination' 24 | Validate = $true 25 | Checksum = 'SHA-256' 26 | Force = $true 27 | Ensure = 'Present' 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Examples/Sample_Archive_ExpandArchiveDefaultValidationAndForce.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Expands the archive located at 'C:\ExampleArchivePath\Archive.zip' to the destination path 4 | 'C:\ExampleDestinationPath\Destination'. 5 | 6 | Since Validate is specified as $true and the Checksum parameter is not provided, the 7 | resource will check if the last write time of the archive file matches the last write time 8 | of the corresponding file at the destination and replace any files that do not match. 9 | 10 | Since Force is specified as $true, the resource will overwrite any mismatching files at the 11 | destination. If Force is specified as $false, the resource will throw an error instead of 12 | overwrite any files at the destination. 13 | #> 14 | Configuration Sample_Archive_ExpandArchiveDefaultValidationAndForce 15 | { 16 | Import-DscResource -ModuleName 'PSDscResources' 17 | 18 | Node localhost 19 | { 20 | Archive Archive3 21 | { 22 | Path = 'C:\ExampleArchivePath\Archive.zip' 23 | Destination = 'C:\ExampleDestinationPath\Destination' 24 | Validate = $true 25 | Force = $true 26 | Ensure = 'Present' 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Examples/Sample_Archive_ExpandArchiveNoValidation.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Expands the archive located at 'C:\ExampleArchivePath\Archive.zip' to the destination path 4 | 'C:\ExampleDestinationPath\Destination'. 5 | 6 | The resource will only check if the expanded archive files exist at the destination. 7 | No validation is performed on any existing files at the destination to ensure that they 8 | match the files in the archive. 9 | #> 10 | Configuration Sample_Archive_ExpandArchiveNoValidation 11 | { 12 | Import-DscResource -ModuleName 'PSDscResources' 13 | 14 | Node localhost 15 | { 16 | Archive Archive1 17 | { 18 | Path = 'C:\ExampleArchivePath\Archive.zip' 19 | Destination = 'C:\ExampleDestinationPath\Destination' 20 | Ensure = 'Present' 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Examples/Sample_Archive_ExpandArchiveNoValidationCredential.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Expands the archive located at 'C:\ExampleArchivePath\Archive.zip' to the destination path 4 | 'C:\ExampleDestinationPath\Destination'. 5 | 6 | The added specification of a Credential here allows you to provide the credential of a user 7 | to provide the resource access to the archive and destination paths. 8 | 9 | The resource will only check if the expanded archive files exist at the destination. 10 | No validation is performed on any existing files at the destination to ensure that they 11 | match the files in the archive. 12 | #> 13 | Configuration Sample_Archive_ExpandArchiveNoValidationCredential 14 | { 15 | param 16 | ( 17 | [Parameter(Mandatory = $true)] 18 | [System.Management.Automation.PSCredential] 19 | [System.Management.Automation.Credential()] 20 | $Credential 21 | ) 22 | 23 | Import-DscResource -ModuleName 'PSDscResources' 24 | 25 | Node localhost 26 | { 27 | Archive Archive2 28 | { 29 | Path = 'C:\ExampleArchivePath\Archive.zip' 30 | Destination = 'C:\ExampleDestinationPath\Destination' 31 | Credential = $Credential 32 | Ensure = 'Present' 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Examples/Sample_Archive_RemoveArchiveChecksum.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Remove the expansion of the archive located at 'C:\ExampleArchivePath\Archive.zip' from the 4 | destination path 'C:\ExampleDestinationPath\Destination'. 5 | 6 | Since Validate is specified as $true and the Checksum parameter is specified as SHA-256, the 7 | resource will check if the SHA-256 hash of the file in the archive matches the SHA-256 hash 8 | of the corresponding file at the destination and will not remove any files that do not match. 9 | #> 10 | Configuration Sample_Archive_RemoveArchiveChecksum 11 | { 12 | Import-DscResource -ModuleName 'PSDscResources' 13 | 14 | Node localhost 15 | { 16 | Archive Archive6 17 | { 18 | Path = 'C:\ExampleArchivePath\Archive.zip' 19 | Destination = 'C:\ExampleDestinationPath\Destination' 20 | Validate = $true 21 | Checksum = 'SHA-256' 22 | Ensure = 'Absent' 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Examples/Sample_Archive_RemoveArchiveNoValidation.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Removes the expansion of the archive located at 'C:\ExampleArchivePath\Archive.zip' from the 4 | destination path 'C:\ExampleDestinationPath\Destination'. 5 | 6 | The resource will only check if the expanded archive files exist at the destination. 7 | No validation is performed on any existing files at the destination to ensure that they 8 | match the files in the archive before removing them. 9 | #> 10 | Configuration Sample_Archive_RemoveArchiveNoValidation 11 | { 12 | Import-DscResource -ModuleName 'PSDscResources' 13 | 14 | Node localhost 15 | { 16 | Archive Archive5 17 | { 18 | Path = 'C:\ExampleArchivePath\Archive.zip' 19 | Destination = 'C:\ExampleDestinationPath\Destination' 20 | Ensure = 'Absent' 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Examples/Sample_Environment_CreateNonPathVariable.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Creates the environment variable 'TestEnvironmentVariable' and sets the value to 'TestValue' 4 | both on the machine and within the process. 5 | #> 6 | Configuration Sample_Environment_CreateNonPathVariable 7 | { 8 | param () 9 | 10 | Import-DscResource -ModuleName 'PSDscResources' 11 | 12 | Node localhost 13 | { 14 | Environment CreateEnvironmentVariable 15 | { 16 | Name = 'TestEnvironmentVariable' 17 | Value = 'TestValue' 18 | Ensure = 'Present' 19 | Path = $false 20 | Target = @('Process', 'Machine') 21 | } 22 | } 23 | } 24 | 25 | Sample_Environment_CreateNonPathVariable 26 | -------------------------------------------------------------------------------- /Examples/Sample_Environment_CreatePathVariable.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Creates the environment variable 'TestPathEnvironmentVariable' and sets the value to 'TestValue' 4 | if it doesn't already exist or appends the value 'TestValue' to the existing path if it does 5 | already exist on the machine and within the process. 6 | #> 7 | Configuration Sample_Environment_CreatePathVariable 8 | { 9 | param () 10 | 11 | Import-DscResource -ModuleName 'PSDscResources' 12 | 13 | Node localhost 14 | { 15 | Environment CreatePathEnvironmentVariable 16 | { 17 | Name = 'TestPathEnvironmentVariable' 18 | Value = 'TestValue' 19 | Ensure = 'Present' 20 | Path = $true 21 | Target = @('Process', 'Machine') 22 | } 23 | } 24 | } 25 | 26 | Sample_Environment_CreatePathVariable 27 | -------------------------------------------------------------------------------- /Examples/Sample_Environment_Remove.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Removes the environment variable 'TestEnvironmentVariable' from 4 | both the machine and the process. 5 | #> 6 | Configuration Sample_Environment_Remove 7 | { 8 | param () 9 | 10 | Import-DscResource -ModuleName 'PSDscResources' 11 | 12 | Node localhost 13 | { 14 | Environment RemoveEnvironmentVariable 15 | { 16 | Name = 'TestEnvironmentVariable' 17 | Ensure = 'Absent' 18 | Path = $false 19 | Target = @('Process', 'Machine') 20 | } 21 | } 22 | } 23 | 24 | Sample_Environment_Remove 25 | -------------------------------------------------------------------------------- /Examples/Sample_GroupSet_AddMembers.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | If the groups named GroupName1 and Administrators do not exist, creates the groups named 4 | GroupName1 and Administrators and adds the users with the usernames Username1 and Username2 5 | to both groups. 6 | 7 | If the groups named GroupName1 and Administrators already exist, adds the users with the 8 | usernames Username1 and Username2 to both groups. 9 | #> 10 | Configuration Sample_GroupSet_AddMembers 11 | { 12 | [CmdletBinding()] 13 | param () 14 | 15 | Import-DscResource -ModuleName 'PSDscResources' 16 | 17 | GroupSet GroupSet 18 | { 19 | GroupName = @( 'Administrators', 'GroupName1' ) 20 | Ensure = 'Present' 21 | MembersToInclude = @( 'Username1', 'Username2' ) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Examples/Sample_Group_RemoveMembers.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | If the group named GroupName1 does not exist, creates a group named GroupName1. 4 | 5 | If the group named GroupName1 already exists removes the users that have the usernames 6 | Username1 or Username2 from the group. 7 | #> 8 | Configuration Sample_Group_RemoveMembers 9 | { 10 | [CmdletBinding()] 11 | param () 12 | 13 | Import-DscResource -ModuleName 'PSDscResources' 14 | 15 | Group Group1 16 | { 17 | GroupName = 'GroupName1' 18 | Ensure = 'Present' 19 | MembersToExclude = @( 'Username1', 'Username2' ) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Examples/Sample_Group_SetMembers.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | If the group named GroupName1 does not exist, creates a group named GroupName1 and adds the 4 | users with the usernames Username1 and Username2 to the group. 5 | 6 | If the group named GroupName1 already exists, removes any users that do not have the 7 | usernames Username1 or Username2 from the group and adds the users that have the usernames 8 | Username1 and Username2 to the group. 9 | #> 10 | Configuration Sample_Group_SetMembers 11 | { 12 | [CmdletBinding()] 13 | param () 14 | 15 | Import-DscResource -ModuleName 'PSDscResources' 16 | 17 | Group Group1 18 | { 19 | GroupName = 'GroupName1' 20 | Ensure = 'Present' 21 | Members = @( 'Username1', 'Username2' ) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Examples/Sample_MsiPackage_InstallPackageFromFile.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Installs the MSI file with the product ID: '{DEADBEEF-80C6-41E6-A1B9-8BDB8A05027F}' 4 | at the path: 'file://Examples/example.msi'. 5 | 6 | Note that the MSI file with the given product ID must already exist at the specified path. 7 | The product ID and path value in this file are provided for example purposes only and will 8 | need to be replaced with valid values. 9 | 10 | You can run the following command to get a list of all available MSIs on 11 | your system with the correct Path (LocalPackage) and product ID (IdentifyingNumber): 12 | 13 | Get-WmiObject Win32_Product | Format-Table IdentifyingNumber, Name, LocalPackage 14 | #> 15 | Configuration Sample_MsiPackage_InstallPackageFromFile 16 | { 17 | Import-DscResource -ModuleName 'PSDscResources' 18 | 19 | Node localhost 20 | { 21 | MsiPackage MsiPackage1 22 | { 23 | ProductId = '{DEADBEEF-80C6-41E6-A1B9-8BDB8A05027F}' 24 | Path = 'file://Examples/example.msi' 25 | Ensure = 'Present' 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Examples/Sample_MsiPackage_InstallPackageFromHttp.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Installs the MSI file with the product ID: '{DEADBEEF-80C6-41E6-A1B9-8BDB8A05027F}' 4 | at the path: 'http://Examples/example.msi'. 5 | 6 | Note that the MSI file with the given product ID must already exist on the server. 7 | The product ID and path value in this file are provided for example purposes only and will 8 | need to be replaced with valid values. 9 | #> 10 | Configuration Sample_MsiPackage_InstallPackageFromHttp 11 | { 12 | Import-DscResource -ModuleName 'PSDscResources' 13 | 14 | Node localhost 15 | { 16 | MsiPackage MsiPackage1 17 | { 18 | ProductId = '{DEADBEEF-80C6-41E6-A1B9-8BDB8A05027F}' 19 | Path = 'http://Examples/example.msi' 20 | Ensure = 'Present' 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Examples/Sample_MsiPackage_UninstallPackageFromFile.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Uninstalls the MSI file with the product ID: '{DEADBEEF-80C6-41E6-A1B9-8BDB8A05027F}' 4 | at the path: 'file://Examples/example.msi'. 5 | 6 | Note that the MSI file with the given product ID must already exist at the specified path. 7 | The product ID and path value in this file are provided for example purposes only and will 8 | need to be replaced with valid values. 9 | 10 | You can run the following command to get a list of all available MSIs on 11 | your system with the correct Path (LocalPackage) and product ID (IdentifyingNumber): 12 | 13 | Get-WmiObject Win32_Product | Format-Table IdentifyingNumber, Name, LocalPackage 14 | #> 15 | Configuration Sample_MsiPackage_UninstallPackageFromFile 16 | { 17 | Import-DscResource -ModuleName 'PSDscResources' 18 | 19 | Node localhost 20 | { 21 | MsiPackage MsiPackage1 22 | { 23 | ProductId = '{DEADBEEF-80C6-41E6-A1B9-8BDB8A05027F}' 24 | Path = 'file://Examples/example.msi' 25 | Ensure = 'Absent' 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Examples/Sample_MsiPackage_UnstallPackageFromHttps.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Uninstalls the MSI file with the product ID: '{DEADBEEF-80C6-41E6-A1B9-8BDB8A05027F}' 4 | at the path: 'https://Examples/example.msi'. 5 | 6 | Note that the MSI file with the given product ID must already exist on the server. 7 | The product ID and path value in this file are provided for example purposes only and will 8 | need to be replaced with valid values. 9 | #> 10 | Configuration Sample_MsiPackage_UninstallPackageFromHttps 11 | { 12 | Import-DscResource -ModuleName 'PSDscResources' 13 | 14 | Node localhost 15 | { 16 | MsiPackage MsiPackage1 17 | { 18 | ProductId = '{DEADBEEF-80C6-41E6-A1B9-8BDB8A05027F}' 19 | Path = 'https://Examples/example.msi' 20 | Ensure = 'Absent' 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Examples/Sample_ProcessSet_Start.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Starts the processes with the executables at the file paths C:\Windows\cmd.exe and 4 | C:\TestPath\TestProcess.exe with no arguments. 5 | #> 6 | Configuration Sample_ProcessSet_Start 7 | { 8 | [CmdletBinding()] 9 | param () 10 | 11 | Import-DscResource -ModuleName 'PSDscResources' 12 | 13 | ProcessSet ProcessSet1 14 | { 15 | Path = @( 'C:\Windows\System32\cmd.exe', 'C:\TestPath\TestProcess.exe' ) 16 | Ensure = 'Present' 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Examples/Sample_ProcessSet_Stop.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Stops the processes with the executables at the file paths C:\Windows\cmd.exe and 4 | C:\TestPath\TestProcess.exe with no arguments and logs any output to the path 5 | C:\OutputPath\Output.log. 6 | #> 7 | Configuration Sample_ProcessSet_Stop 8 | { 9 | [CmdletBinding()] 10 | param () 11 | 12 | Import-DscResource -ModuleName 'PSDscResources' 13 | 14 | ProcessSet ProcessSet1 15 | { 16 | Path = @( 'C:\Windows\System32\cmd.exe', 'C:\TestPath\TestProcess.exe' ) 17 | Ensure = 'Absent' 18 | StandardOutputPath = 'C:\OutputPath\Output.log' 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Examples/Sample_RegistryResource_AddKey.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Create a new registry key called MyNewKey as a subkey under the key 4 | 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'. 5 | #> 6 | Configuration Sample_RegistryResource_AddKey 7 | { 8 | Import-DscResource -ModuleName 'PSDscResources' 9 | 10 | Node localhost 11 | { 12 | Registry Registry1 13 | { 14 | Key = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\MyNewKey' 15 | Ensure = 'Present' 16 | ValueName = '' 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Examples/Sample_RegistryResource_AddOrModifyValue.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | If the registry key value MyValue under the key 4 | 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' does not exist, 5 | creates it with the Binary value 0. 6 | 7 | If the registry key value MyValue under the key 8 | 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' already exists, 9 | overwrites it with the Binary value 0. 10 | #> 11 | Configuration Sample_RegistryResource_AddOrModifyValue 12 | { 13 | Import-DscResource -ModuleName 'PSDscResources' 14 | 15 | Node localhost 16 | { 17 | Registry Registry1 18 | { 19 | Key = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' 20 | Ensure = 'Present' 21 | ValueName = 'MyValue' 22 | ValueType = 'Binary' 23 | ValueData = '0x00' 24 | Force = $true 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Examples/Sample_RegistryResource_RemoveKey.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Removes the registry key called MyNewKey under the parent key 4 | 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'. 5 | #> 6 | Configuration Sample_RegistryResource_RemoveKey 7 | { 8 | Import-DscResource -ModuleName 'PSDscResources' 9 | 10 | Node localhost 11 | { 12 | Registry Registry1 13 | { 14 | Key = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\MyNewKey' 15 | Ensure = 'Absent' 16 | ValueName = '' 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Examples/Sample_RegistryResource_RemoveValue.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Removes the registry key value MyValue from the key 4 | 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'. 5 | #> 6 | Configuration Sample_RegistryResource_RemoveValue 7 | { 8 | Import-DscResource -ModuleName 'PSDscResources' 9 | 10 | Node localhost 11 | { 12 | Registry Registry1 13 | { 14 | Key = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' 15 | Ensure = 'Absent' 16 | ValueName = 'MyValue' 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Examples/Sample_Script.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Creates a file at the given file path with the specified content through the Script resource. 4 | 5 | .PARAMETER FilePath 6 | The path at which to create the file. 7 | 8 | .PARAMETER FileContent 9 | The content to set for the new file. 10 | #> 11 | Configuration ScriptExample { 12 | [CmdletBinding()] 13 | param 14 | ( 15 | [Parameter(Mandatory = $true)] 16 | [ValidateNotNullOrEmpty()] 17 | [String] 18 | $FilePath, 19 | 20 | [Parameter(Mandatory = $true)] 21 | [ValidateNotNullOrEmpty()] 22 | [String] 23 | $FileContent 24 | ) 25 | 26 | Import-DscResource -ModuleName 'PSDscResources' 27 | 28 | Node localhost 29 | { 30 | Script ScriptExample 31 | { 32 | SetScript = { 33 | $streamWriter = New-Object -TypeName 'System.IO.StreamWriter' -ArgumentList @( $using:FilePath ) 34 | $streamWriter.WriteLine($using:FileContent) 35 | $streamWriter.Close() 36 | } 37 | TestScript = { 38 | if (Test-Path -Path $using:FilePath) 39 | { 40 | $fileContent = Get-Content -Path $using:filePath -Raw 41 | return $fileContent -eq $using:FileContent 42 | } 43 | else 44 | { 45 | return $false 46 | } 47 | } 48 | GetScript = { 49 | $fileContent = $null 50 | 51 | if (Test-Path -Path $using:FilePath) 52 | { 53 | $fileContent = Get-Content -Path $using:filePath -Raw 54 | } 55 | 56 | return @{ 57 | Result = Get-Content -Path $fileContent 58 | } 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Examples/Sample_ServiceSet_BuiltInAccount.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Sets the Secure Socket Tunneling Protocol and DHCP Client services to run under the 4 | built-in account LocalService. 5 | #> 6 | Configuration ServiceSetBuiltInAccountExample 7 | { 8 | Import-DscResource -ModuleName 'PSDscResources' 9 | 10 | ServiceSet ServiceSet1 11 | { 12 | Name = @( 'SstpSvc', 'Dhcp' ) 13 | Ensure = 'Present' 14 | BuiltInAccount = 'LocalService' 15 | State = 'Ignore' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Examples/Sample_ServiceSet_StartServices.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Ensures that the DHCP Client and Windows Firewall services are running. 4 | #> 5 | Configuration ServiceSetStartExample 6 | { 7 | Import-DscResource -ModuleName 'PSDscResources' 8 | 9 | ServiceSet ServiceSet1 10 | { 11 | Name = @( 'Dhcp', 'MpsSvc' ) 12 | Ensure = 'Present' 13 | State = 'Running' 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Examples/Sample_Service_CreateService.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | If the service with the name Service1 does not exist, creates the service with the name 4 | Service1 and the executable/binary path 'C:\FilePath\MyServiceExecutable.exe'. The new 5 | service will be started by default. 6 | 7 | If the service with the name Service1 already exists, sets executable/binary path of the 8 | service with the name Service1 to 'C:\FilePath\MyServiceExecutable.exe' and starts the 9 | service by default if it is not running already. 10 | #> 11 | Configuration Sample_Service_CreateService 12 | { 13 | [CmdletBinding()] 14 | param 15 | () 16 | 17 | Import-DscResource -ModuleName 'PSDscResources' 18 | 19 | Node localhost 20 | { 21 | Service ServiceResource1 22 | { 23 | Name = 'Service1' 24 | Ensure = 'Present' 25 | Path = 'C:\FilePath\MyServiceExecutable.exe' 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Examples/Sample_Service_DeleteService.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Stops and then removes the service with the name Service1. 4 | #> 5 | Configuration Sample_Service_DeleteService 6 | { 7 | [CmdletBinding()] 8 | param 9 | () 10 | 11 | Import-DscResource -ModuleName 'PSDscResources' 12 | 13 | Node localhost 14 | { 15 | Service ServiceResource1 16 | { 17 | Name = 'Service1' 18 | Ensure = 'Absent' 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Examples/Sample_Service_UpdateStartupTypeIgnoreState.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | If the service with the name Service1 does not exist, this configuration would throw an 4 | error since the Path is not included here. 5 | 6 | If the service with the name Service1 already exists, sets the startup type of the service 7 | with the name Service1 to Manual and ignores the state that the service is currently in. 8 | If State is not specified, the configuration will ensure that the state of the service is 9 | Running by default. 10 | #> 11 | Configuration Sample_Service_UpdateStartupTypeIgnoreState 12 | { 13 | [CmdletBinding()] 14 | param () 15 | 16 | Import-DscResource -ModuleName 'PSDscResources' 17 | 18 | Node localhost 19 | { 20 | Service ServiceResource1 21 | { 22 | Name = 'Service1' 23 | Ensure = 'Present' 24 | StartupType = 'Manual' 25 | State = 'Ignore' 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Examples/Sample_User_CreateUser.ps1: -------------------------------------------------------------------------------- 1 | Configuration UserExample 2 | { 3 | param ( 4 | [System.Management.Automation.PSCredential] 5 | $PasswordCredential 6 | ) 7 | 8 | Import-DscResource -ModuleName PSDscResources 9 | 10 | User UserExample 11 | { 12 | Ensure = 'Present' # To ensure the user account does not exist, set Ensure to "Absent" 13 | UserName = 'SomeUserName' 14 | Password = $PasswordCredential # This needs to be a credential object 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Examples/Sample_User_Generic.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | <# 9 | Create a custom configuration by passing in whatever 10 | values you need. $Password is the only param that is 11 | required since it must be a PSCredential object. 12 | If you want to create a user with minimal attributes, 13 | every param except username can be deleted since they 14 | are optional. 15 | #> 16 | 17 | Configuration $ConfigurationName 18 | { 19 | param 20 | ( 21 | [System.String] 22 | $UserName = 'Test UserName', 23 | 24 | [System.String] 25 | $Description = 'Test Description', 26 | 27 | [System.String] 28 | $FullName = 'Test Full Name', 29 | 30 | [ValidateSet('Present', 'Absent')] 31 | [System.String] 32 | $Ensure = 'Present', 33 | 34 | [Parameter(Mandatory = $true)] 35 | [System.Management.Automation.PSCredential] 36 | [System.Management.Automation.Credential()] 37 | $Password, 38 | 39 | [System.Boolean] 40 | $Disabled = $false, 41 | 42 | [System.Boolean] 43 | $PasswordNeverExpires = $false, 44 | 45 | [System.Boolean] 46 | $PasswordChangeRequired = $false, 47 | 48 | [System.Boolean] 49 | $PasswordChangeNotAllowed = $false 50 | ) 51 | 52 | Import-DscResource -ModuleName 'PSDscResources' 53 | 54 | Node Localhost { 55 | 56 | User UserResource1 57 | { 58 | UserName = $UserName 59 | Ensure = $Ensure 60 | FullName = $FullName 61 | Description = $Description 62 | Password = $Password 63 | Disabled = $Disabled 64 | PasswordNeverExpires = $PasswordNeverExpires 65 | PasswordChangeRequired = $PasswordChangeRequired 66 | PasswordChangeNotAllowed = $PasswordChangeNotAllowed 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Examples/Sample_WindowsFeature.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Creates a custom configuration for installing or uninstalling a Windows role or feature. 4 | 5 | .PARAMETER Name 6 | The name of the role or feature to install or uninstall. 7 | Default is 'Telnet-Client'. 8 | 9 | .PARAMETER Ensure 10 | Specifies whether the role or feature should be installed ('Present') 11 | or uninstalled ('Absent'). 12 | By default this is set to Present. 13 | 14 | .PARAMETER IncludeAllSubFeature 15 | Specifies whether or not all subfeatures should be installed or uninstalled with 16 | the specified role or feature. Default is false. 17 | If this property is true and Ensure is set to Present, all subfeatures will be installed. 18 | If this property is false and Ensure is set to Present, subfeatures will not be installed or uninstalled. 19 | If Ensure is set to Absent, all subfeatures will be uninstalled. 20 | 21 | .PARAMETER Credential 22 | The credential (if required) to install or uninstall the role or feature. 23 | Optional. This must be added to the Node if it is required, as it is not being set 24 | in this configuration file currently. 25 | 26 | .PARAMETER LogPath 27 | The custom path to the log file to log this operation. 28 | If not passed in, the default log path will be used (%windir%\logs\ServerManager.log). 29 | Optional. This must be added to the Node if it is required, as it is not being set 30 | in this configuration file currently. 31 | #> 32 | 33 | Configuration 'Install_Feature_Telnet_Client' 34 | { 35 | param 36 | ( 37 | [System.String] 38 | $Name = 'Telnet-Client', 39 | 40 | [ValidateSet('Present', 'Absent')] 41 | [System.String] 42 | $Ensure = 'Present', 43 | 44 | [System.Boolean] 45 | $IncludeAllSubFeature = $false, 46 | 47 | [System.Management.Automation.PSCredential] 48 | [System.Management.Automation.Credential()] 49 | $Credential, 50 | 51 | [ValidateNotNullOrEmpty()] 52 | [System.String] 53 | $LogPath 54 | ) 55 | 56 | Import-DscResource -ModuleName 'PSDscResources' 57 | 58 | Node Localhost 59 | { 60 | WindowsFeature WindowsFeatureTest 61 | { 62 | Name = $Name 63 | Ensure = $Ensure 64 | IncludeAllSubFeature = $IncludeAllSubFeature 65 | } 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /Examples/Sample_WindowsFeatureSet_Install.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Installs the TelnetClient and RSAT-File-Services Windows features, including all their 4 | subfeatures. Logs the operation to the file at 'C:\LogPath\Log.log'. 5 | #> 6 | Configuration WindowsFeatureSetExample_Install 7 | { 8 | [CmdletBinding()] 9 | param () 10 | 11 | Import-DscResource -ModuleName 'PSDscResources' 12 | 13 | WindowsFeatureSet WindowsFeatureSet1 14 | { 15 | Name = @( 'Telnet-Client', 'RSAT-File-Services' ) 16 | Ensure = 'Present' 17 | IncludeAllSubFeature = $true 18 | LogPath = 'C:\LogPath\Log.log' 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Examples/Sample_WindowsFeatureSet_Uninstall.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Uninstalls the TelnetClient and RSAT-File-Services Windows features, including all their 4 | subfeatures. Logs the operation to the file at 'C:\LogPath\Log.log'. 5 | #> 6 | Configuration WindowsFeatureSetExample_Install 7 | { 8 | [CmdletBinding()] 9 | param () 10 | 11 | Import-DscResource -ModuleName 'PSDscResources' 12 | 13 | WindowsFeatureSet WindowsFeatureSet1 14 | { 15 | Name = @( 'Telnet-Client', 'RSAT-File-Services' ) 16 | Ensure = 'Absent' 17 | IncludeAllSubFeature = $true 18 | LogPath = 'C:\LogPath\Log.log' 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Examples/Sample_WindowsOptionalFeature.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Enables the Windows optional feature with the specified name and outputs a log to the specified path. 4 | 5 | .PARAMETER FeatureName 6 | The name of the Windows optional feature to enable. 7 | 8 | .PARAMETER LogPath 9 | The path to the file to log the enable operation to. 10 | 11 | .NOTES 12 | Can only be run on Windows client operating systems and Windows Server 2012 or later. 13 | The DISM PowerShell module must be available on the target machine. 14 | #> 15 | Configuration Sample_WindowsOptionalFeature 16 | { 17 | param 18 | ( 19 | [Parameter (Mandatory = $true)] 20 | [String] 21 | $FeatureName, 22 | 23 | [Parameter(Mandatory = $true)] 24 | [String] 25 | $LogPath 26 | ) 27 | 28 | Import-DscResource -ModuleName 'PSDscResources' 29 | 30 | WindowsOptionalFeature TelnetClient 31 | { 32 | Name = $FeatureName 33 | Ensure = 'Present' 34 | LogPath = $LogPath 35 | } 36 | } 37 | 38 | Sample_WindowsOptionalFeature 39 | -------------------------------------------------------------------------------- /Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Disables the Windows optional features TelnetClient and LegacyComponents and removes all 4 | files associated with these features. 5 | #> 6 | Configuration WindowsOptionalFeatureSet_Disable 7 | { 8 | Import-DscResource -ModuleName 'PSDscResources' 9 | 10 | WindowsOptionalFeatureSet WindowsOptionalFeatureSet1 11 | { 12 | Name = @('TelnetClient', 'LegacyComponents') 13 | Ensure = 'Absent' 14 | RemoveFilesOnDisable = $true 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Enables the Windows optional features MicrosoftWindowsPowerShellV2 and 4 | Internet-Explorer-Optional-amd64 and outputs a log of the operations to a file at the path 5 | 'C:\LogPath\Log.txt'. 6 | #> 7 | Configuration WindowsOptionalFeatureSet_Enable 8 | { 9 | Import-DscResource -ModuleName 'PSDscResources' 10 | 11 | WindowsOptionalFeatureSet WindowsOptionalFeatureSet1 12 | { 13 | Name = @('MicrosoftWindowsPowerShellV2', 'Internet-Explorer-Optional-amd64') 14 | Ensure = 'Present' 15 | LogPath = 'C:\LogPath\Log.txt' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Examples/Sample_WindowsPackageCab.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Installs a package from the cab file with the specified name from the specified source path 4 | and outputs a log to the specified log path. 5 | 6 | .PARAMETER Name 7 | The name of the package to install. 8 | 9 | .PARAMETER SourcePath 10 | The path to the cab file to install the package from. 11 | 12 | .PARAMETER LogPath 13 | The path to a file to log the install operation to. 14 | 15 | .NOTES 16 | The DISM PowerShell module must be available on the target machine. 17 | #> 18 | Configuration Sample_WindowsPackageCab 19 | { 20 | param 21 | ( 22 | [Parameter (Mandatory = $true)] 23 | [ValidateNotNullOrEmpty()] 24 | [String] 25 | $Name, 26 | 27 | [Parameter (Mandatory = $true)] 28 | [ValidateNotNullOrEmpty()] 29 | [String] 30 | $SourcePath, 31 | 32 | [Parameter(Mandatory = $true)] 33 | [ValidateNotNullOrEmpty()] 34 | [String] 35 | $LogPath 36 | ) 37 | 38 | Import-DscResource -ModuleName 'PSDscResources' 39 | 40 | WindowsPackageCab WindowsPackageCab1 41 | { 42 | Name = $Name 43 | Ensure = 'Present' 44 | SourcePath = $SourcePath 45 | LogPath = $LogPath 46 | } 47 | } 48 | 49 | Sample_WindowsPackageCab 50 | -------------------------------------------------------------------------------- /Examples/Sample_WindowsProcess_Start.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Starts the gpresult process which generates a log about the group policy. 4 | The path to the log is provided in 'Arguments'. 5 | #> 6 | Configuration Sample_WindowsProcess_Start 7 | { 8 | param () 9 | 10 | Import-DSCResource -ModuleName 'PSDscResources' 11 | 12 | Node localhost 13 | { 14 | WindowsProcess GPresult 15 | { 16 | Path = 'C:\Windows\System32\gpresult.exe' 17 | Arguments = '/h C:\gp2.htm' 18 | Ensure = 'Present' 19 | } 20 | } 21 | } 22 | 23 | Sample_WindowsProcess_Start 24 | 25 | -------------------------------------------------------------------------------- /Examples/Sample_WindowsProcess_StartUnderUser.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Starts the gpresult process under the given credential which generates a log 4 | about the group policy. The path to the log is provided in 'Arguments'. 5 | 6 | .PARAMETER Credential 7 | Credential to start the process under. 8 | #> 9 | Configuration Sample_WindowsProcess_StartUnderUser 10 | { 11 | [CmdletBinding()] 12 | param 13 | ( 14 | [System.Management.Automation.PSCredential] 15 | [System.Management.Automation.Credential()] 16 | $Credential = (Get-Credential) 17 | ) 18 | 19 | Import-DSCResource -ModuleName 'PSDscResources' 20 | 21 | Node localhost 22 | { 23 | WindowsProcess GPresult 24 | { 25 | Path = 'C:\Windows\System32\gpresult.exe' 26 | Arguments = '/h C:\gp2.htm' 27 | Credential = $Credential 28 | Ensure = 'Present' 29 | } 30 | } 31 | } 32 | 33 | <# 34 | To use the sample(s) with credentials, see blog at: 35 | http://blogs.msdn.com/b/powershell/archive/2014/01/31/want-to-secure-credentials-in-windows-powershell-desired-state-configuration.aspx 36 | #> 37 | -------------------------------------------------------------------------------- /Examples/Sample_WindowsProcess_Stop.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Stops the gpresult process if it is running. 4 | Since the Arguments parameter isn't needed to stop the process, 5 | an empty string is passed in. 6 | #> 7 | Configuration Sample_WindowsProcess_Stop 8 | { 9 | param () 10 | 11 | Import-DSCResource -ModuleName 'PSDscResources' 12 | 13 | Node localhost 14 | { 15 | WindowsProcess GPresult 16 | { 17 | Path = 'C:\Windows\System32\gpresult.exe' 18 | Arguments = '' 19 | Ensure = 'Absent' 20 | } 21 | } 22 | } 23 | 24 | Sample_WindowsProcess_Stop 25 | 26 | -------------------------------------------------------------------------------- /Examples/Sample_WindowsProcess_StopUnderUser.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Stops the gpresult process running under the given credential if it is running. 4 | Since the Arguments parameter isn't needed to stop the process, 5 | an empty string is passed in. 6 | 7 | .PARAMETER Credential 8 | Credential that the process is running under. 9 | #> 10 | Configuration Sample_WindowsProcess_StopUnderUser 11 | { 12 | [CmdletBinding()] 13 | param 14 | ( 15 | [ValidateNotNullOrEmpty()] 16 | [System.Management.Automation.PSCredential] 17 | [System.Management.Automation.Credential()] 18 | $Credential = (Get-Credential) 19 | ) 20 | 21 | Import-DSCResource -ModuleName 'PSDscResources' 22 | 23 | Node localhost 24 | { 25 | WindowsProcess GPresult 26 | { 27 | Path = 'C:\Windows\System32\gpresult.exe' 28 | Arguments = '' 29 | Credential = $Credential 30 | Ensure = 'Absent' 31 | } 32 | } 33 | } 34 | 35 | <# 36 | To use the sample(s) with credentials, see blog at: 37 | http://blogs.msdn.com/b/powershell/archive/2014/01/31/want-to-secure-credentials-in-windows-powershell-desired-state-configuration.aspx 38 | #> 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /Tests/Integration/GroupSet.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String[]] 15 | $GroupName, 16 | 17 | [Parameter()] 18 | [ValidateSet('Present', 'Absent')] 19 | [ValidateNotNullOrEmpty()] 20 | [System.String] 21 | $Ensure = 'Present', 22 | 23 | [Parameter()] 24 | [System.String[]] 25 | $MembersToInclude = @(), 26 | 27 | [Parameter()] 28 | [System.String[]] 29 | $MembersToExclude = @() 30 | ) 31 | 32 | Import-DscResource -ModuleName 'PSDscResources' 33 | 34 | GroupSet GroupSet1 35 | { 36 | GroupName = $GroupName 37 | Ensure = $Ensure 38 | MembersToInclude = $MembersToInclude 39 | MembersToExclude = $MembersToExclude 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_Archive_CredentialOnly.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String] 15 | $Path, 16 | 17 | [Parameter(Mandatory = $true)] 18 | [ValidateNotNullOrEmpty()] 19 | [System.String] 20 | $Destination, 21 | 22 | [Parameter()] 23 | [ValidateSet('Present', 'Absent')] 24 | [System.String] 25 | $Ensure = 'Present', 26 | 27 | [Parameter()] 28 | [System.Management.Automation.PSCredential] 29 | [System.Management.Automation.Credential()] 30 | $Credential 31 | ) 32 | 33 | Import-DscResource -ModuleName 'PSDscResources' 34 | 35 | Node localhost 36 | { 37 | Archive Archive1 38 | { 39 | Path = $Path 40 | Destination = $Destination 41 | Ensure = $Ensure 42 | Credential = $Credential 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_Archive_ValidateAndChecksum.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String] 15 | $Path, 16 | 17 | [Parameter(Mandatory = $true)] 18 | [ValidateNotNullOrEmpty()] 19 | [System.String] 20 | $Destination, 21 | 22 | [Parameter()] 23 | [ValidateSet('Present', 'Absent')] 24 | [System.String] 25 | $Ensure = 'Present', 26 | 27 | [Parameter()] 28 | [System.Boolean] 29 | $Validate = $false, 30 | 31 | [Parameter()] 32 | [System.String] 33 | $Checksum = 'SHA-256', 34 | 35 | [Parameter()] 36 | [System.Boolean] 37 | $Force = $false 38 | ) 39 | 40 | Import-DscResource -ModuleName 'PSDscResources' 41 | 42 | Node localhost 43 | { 44 | Archive Archive1 45 | { 46 | Path = $Path 47 | Destination = $Destination 48 | Ensure = $Ensure 49 | Validate = $Validate 50 | Checksum = $Checksum 51 | Force = $Force 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_Archive_ValidateOnly.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String] 15 | $Path, 16 | 17 | [Parameter(Mandatory = $true)] 18 | [ValidateNotNullOrEmpty()] 19 | [System.String] 20 | $Destination, 21 | 22 | [Parameter()] 23 | [ValidateSet('Present', 'Absent')] 24 | [System.String] 25 | $Ensure = 'Present', 26 | 27 | [Parameter()] 28 | [System.Boolean] 29 | $Validate = $false 30 | ) 31 | 32 | Import-DscResource -ModuleName 'PSDscResources' 33 | 34 | Node localhost 35 | { 36 | Archive Archive1 37 | { 38 | Path = $Path 39 | Destination = $Destination 40 | Ensure = $Ensure 41 | Validate = $Validate 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_EnvironmentResource.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String] 15 | $Name, 16 | 17 | [Parameter()] 18 | [ValidateNotNull()] 19 | [System.String] 20 | $Value = [System.String]::Empty, 21 | 22 | [Parameter()] 23 | [ValidateSet('Present', 'Absent')] 24 | [System.String] 25 | $Ensure = 'Present', 26 | 27 | [Parameter()] 28 | [System.Boolean] 29 | $Path = $false, 30 | 31 | [Parameter()] 32 | [ValidateSet('Process', 'Machine')] 33 | [System.String[]] 34 | $Target = @('Process', 'Machine') 35 | ) 36 | 37 | Import-DscResource -ModuleName 'PSDscResources' 38 | 39 | Environment Environment1 40 | { 41 | Name = $Name 42 | Value = $Value 43 | Ensure = $Ensure 44 | Path = $Path 45 | Target = $Target 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_GroupResource_Members.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String] 15 | $GroupName, 16 | 17 | [Parameter()] 18 | [ValidateSet('Present', 'Absent')] 19 | [ValidateNotNullOrEmpty()] 20 | [System.String] 21 | $Ensure = 'Present', 22 | 23 | [Parameter()] 24 | [System.String[]] 25 | $Members = @() 26 | ) 27 | 28 | Import-DscResource -ModuleName 'PSDscResources' 29 | 30 | Group Group1 31 | { 32 | GroupName = $GroupName 33 | Ensure = $Ensure 34 | Members = $Members 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_GroupResource_MembersToIncludeExclude.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String] 15 | $GroupName, 16 | 17 | [Parameter()] 18 | [ValidateSet('Present', 'Absent')] 19 | [ValidateNotNullOrEmpty()] 20 | [System.String] 21 | $Ensure = 'Present', 22 | 23 | [Parameter()] 24 | [System.String[]] 25 | $MembersToInclude = @(), 26 | 27 | [Parameter()] 28 | [System.String[]] 29 | $MembersToExclude = @() 30 | ) 31 | 32 | Import-DscResource -ModuleName 'PSDscResources' 33 | 34 | Group Group2 35 | { 36 | GroupName = $GroupName 37 | Ensure = $Ensure 38 | MembersToInclude = $MembersToInclude 39 | MembersToExclude = $MembersToExclude 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_GroupResource_NoMembers.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String] 15 | $GroupName, 16 | 17 | [Parameter()] 18 | [ValidateSet('Present', 'Absent')] 19 | [ValidateNotNullOrEmpty()] 20 | [System.String] 21 | $Ensure = 'Present' 22 | ) 23 | 24 | Import-DscResource -ModuleName 'PSDscResources' 25 | 26 | Group Group3 27 | { 28 | GroupName = $GroupName 29 | Ensure = $Ensure 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_MsiPackage_LogPath.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String] 15 | $ProductId, 16 | 17 | [Parameter(Mandatory = $true)] 18 | [ValidateNotNullOrEmpty()] 19 | [System.String] 20 | $Path, 21 | 22 | [ValidateSet('Present', 'Absent')] 23 | [System.String] 24 | $Ensure = 'Present', 25 | 26 | [Parameter(Mandatory = $true)] 27 | [System.String] 28 | $LogPath 29 | ) 30 | 31 | Import-DscResource -ModuleName 'PSDscResources' 32 | 33 | Node localhost 34 | { 35 | MsiPackage MsiPackage1 36 | { 37 | ProductId = $ProductId 38 | Path = $Path 39 | Ensure = $Ensure 40 | LogPath = $LogPath 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_MsiPackage_NoOptionalParameters.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String] 15 | $ProductId, 16 | 17 | [Parameter(Mandatory = $true)] 18 | [ValidateNotNullOrEmpty()] 19 | [System.String] 20 | $Path, 21 | 22 | [ValidateSet('Present', 'Absent')] 23 | [System.String] 24 | $Ensure = 'Present' 25 | ) 26 | 27 | Import-DscResource -ModuleName 'PSDscResources' 28 | 29 | Node localhost 30 | { 31 | MsiPackage MsiPackage1 32 | { 33 | ProductId = $ProductId 34 | Path = $Path 35 | Ensure = $Ensure 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_RegistryResource_KeyAndNameOnly.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String] 15 | $Key, 16 | 17 | [ValidateSet('Present', 'Absent')] 18 | [System.String] 19 | $Ensure = 'Present', 20 | 21 | [Parameter(Mandatory = $true)] 22 | [System.String] 23 | [AllowEmptyString()] 24 | $ValueName 25 | ) 26 | 27 | Import-DscResource -ModuleName 'PSDscResources' 28 | 29 | Node localhost 30 | { 31 | Registry Registry1 32 | { 33 | Key = $Key 34 | Ensure = $Ensure 35 | ValueName = $ValueName 36 | Force = $true 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_RegistryResource_WithDataAndType.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String] 15 | $Key, 16 | 17 | [ValidateSet('Present', 'Absent')] 18 | [System.String] 19 | $Ensure = 'Present', 20 | 21 | [Parameter(Mandatory = $true)] 22 | [System.String] 23 | [AllowEmptyString()] 24 | $ValueName, 25 | 26 | [Parameter(Mandatory = $true)] 27 | [ValidateSet('String', 'Binary', 'DWord', 'QWord', 'MultiString', 'ExpandString')] 28 | [System.String] 29 | $ValueType, 30 | 31 | [Parameter(Mandatory = $true)] 32 | [System.String[]] 33 | [AllowEmptyCollection()] 34 | $ValueData 35 | ) 36 | 37 | Import-DscResource -ModuleName 'PSDscResources' 38 | 39 | Node localhost 40 | { 41 | Registry Registry1 42 | { 43 | Key = $Key 44 | Ensure = $Ensure 45 | ValueName = $ValueName 46 | ValueType = $ValueType 47 | ValueData = $ValueData 48 | Force = $true 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_ScriptResource.Integration.Tests.ps1: -------------------------------------------------------------------------------- 1 | $errorActionPreference = 'Stop' 2 | Set-StrictMode -Version 'Latest' 3 | 4 | if ($PSVersionTable.PSVersion -lt [Version] '5.1') 5 | { 6 | Write-Warning -Message 'Cannot run PSDscResources integration tests on PowerShell versions lower than 5.1' 7 | return 8 | } 9 | 10 | Describe 'Script Integration Tests' { 11 | BeforeAll { 12 | # Import CommonTestHelper for Enter-DscResourceTestEnvironment, Exit-DscResourceTestEnvironment 13 | $script:moduleRootPath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent 14 | $script:testFolderPath = Split-Path -Path $PSScriptRoot -Parent 15 | $script:testHelpersPath = Join-Path -Path $script:testFolderPath -ChildPath 'TestHelpers' 16 | Import-Module -Name (Join-Path -Path $script:testHelpersPath -ChildPath 'CommonTestHelper.psm1') 17 | 18 | $script:testEnvironment = Enter-DscResourceTestEnvironment ` 19 | -DscResourceModuleName 'PSDscResources' ` 20 | -DscResourceName 'MSFT_ScriptResource' ` 21 | -TestType 'Integration' 22 | 23 | # Import Script module for Get-TargetResource, Test-TargetResource 24 | $dscResourcesFolderFilePath = Join-Path -Path $script:moduleRootPath -ChildPath 'DscResources' 25 | $scriptResourceFolderFilePath = Join-Path -Path $dscResourcesFolderFilePath -ChildPath 'MSFT_ScriptResource' 26 | $scriptResourceModuleFilePath = Join-Path -Path $scriptResourceFolderFilePath -ChildPath 'MSFT_ScriptResource.psm1' 27 | Import-Module -Name $scriptResourceModuleFilePath 28 | 29 | $script:configurationNoCredentialFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'MSFT_ScriptResource_NoCredential.config.ps1' 30 | $script:configurationWithCredentialFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'MSFT_ScriptResource_WithCredential.config.ps1' 31 | 32 | # Cannot use $TestDrive here because script is run outside of Pester 33 | $script:testFilePath = Join-Path -Path $env:SystemDrive -ChildPath 'TestFile.txt' 34 | 35 | if (Test-Path -Path $script:testFilePath) 36 | { 37 | $null = Remove-Item -Path $script:testFilePath -Force 38 | } 39 | } 40 | 41 | AfterAll { 42 | if (Test-Path -Path $script:testFilePath) 43 | { 44 | $null = Remove-Item -Path $script:testFilePath -Force 45 | } 46 | 47 | $null = Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment 48 | } 49 | 50 | Context 'Get, set, and test scripts specified and Credential not specified' { 51 | if (Test-Path -Path $script:testFilePath) 52 | { 53 | $null = Remove-Item -Path $script:testFilePath -Force 54 | } 55 | 56 | $configurationName = 'TestScriptNoCredential' 57 | 58 | # Cannot use $TestDrive here because script is run outside of Pester 59 | $resourceParameters = @{ 60 | FilePath = $script:testFilePath 61 | FileContent = 'Test file content' 62 | } 63 | 64 | It 'Should have removed test file before the configuration' { 65 | Test-Path -Path $resourceParameters.FilePath | Should -BeFalse 66 | } 67 | 68 | It 'Should compile and apply the MOF without throwing' { 69 | { 70 | . $script:configurationNoCredentialFilePath -ConfigurationName $configurationName 71 | & $configurationName -OutputPath $TestDrive @resourceParameters 72 | Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force 73 | } | Should Not Throw 74 | } 75 | 76 | It 'Should have created the test file' { 77 | Test-Path -Path $resourceParameters.FilePath | Should -BeTrue 78 | } 79 | 80 | It 'Should have set file content correctly' { 81 | Get-Content -Path $resourceParameters.FilePath -Raw | Should Be "$($resourceParameters.FileContent)`r`n" 82 | } 83 | } 84 | 85 | if ($env:appVeyor) 86 | { 87 | Context 'Get, set, and test scripts specified and Credential specified' { 88 | if (Test-Path -Path $script:testFilePath) 89 | { 90 | Remove-Item -Path $script:testFilePath -Force 91 | } 92 | 93 | $configurationName = 'TestScriptWithCredential' 94 | 95 | # Cannot use $TestDrive here because script is run outside of Pester 96 | $resourceParameters = @{ 97 | FilePath = $script:testFilePath 98 | FileContent = 'Test file content' 99 | Credential = Get-AppVeyorAdministratorCredential 100 | } 101 | 102 | It 'Should have removed test file before config runs' { 103 | Test-Path -Path $resourceParameters.FilePath | Should -BeFalse 104 | } 105 | 106 | $configData = @{ 107 | AllNodes = @( 108 | @{ 109 | NodeName = 'localhost' 110 | PSDscAllowPlainTextPassword = $true 111 | PSDscAllowDomainUser = $true 112 | } 113 | ) 114 | } 115 | 116 | It 'Should compile and apply the MOF without throwing' { 117 | { 118 | . $script:configurationWithCredentialFilePath -ConfigurationName $configurationName 119 | & $configurationName -OutputPath $TestDrive -ConfigurationData $configData @resourceParameters 120 | Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force 121 | } | Should -Not -Throw 122 | } 123 | 124 | It 'Should have created the test file' { 125 | Test-Path -Path $resourceParameters.FilePath | Should -BeTrue 126 | } 127 | 128 | It 'Should have set file content correctly' { 129 | Get-Content -Path $resourceParameters.FilePath -Raw | Should -Be "$($resourceParameters.FileContent)`r`n" 130 | } 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_ScriptResource_NoCredential.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | [CmdletBinding()] 11 | param 12 | ( 13 | [Parameter(Mandatory = $true)] 14 | [ValidateNotNullOrEmpty()] 15 | [System.String] 16 | $FilePath, 17 | 18 | [Parameter(Mandatory = $true)] 19 | [ValidateNotNullOrEmpty()] 20 | [System.String] 21 | $FileContent 22 | ) 23 | 24 | Import-DscResource -ModuleName 'PSDscResources' 25 | 26 | Node localhost 27 | { 28 | Script ScriptExample 29 | { 30 | SetScript = { 31 | $streamWriter = New-Object -TypeName 'System.IO.StreamWriter' -ArgumentList @( $using:FilePath ) 32 | $streamWriter.WriteLine($using:FileContent) 33 | $streamWriter.Close() 34 | } 35 | TestScript = { 36 | if (Test-Path -Path $using:FilePath) 37 | { 38 | $fileContent = Get-Content -Path $using:filePath -Raw 39 | return $fileContent -eq $using:FileContent 40 | } 41 | else 42 | { 43 | return $false 44 | } 45 | } 46 | GetScript = { 47 | $fileContent = $null 48 | 49 | if (Test-Path -Path $using:FilePath) 50 | { 51 | $fileContent = Get-Content -Path $using:filePath -Raw 52 | } 53 | 54 | return @{ 55 | Result = Get-Content -Path $fileContent 56 | } 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_ScriptResource_WithCredential.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | [CmdletBinding()] 11 | param 12 | ( 13 | [Parameter(Mandatory = $true)] 14 | [ValidateNotNullOrEmpty()] 15 | [System.String] 16 | $FilePath, 17 | 18 | [Parameter(Mandatory = $true)] 19 | [ValidateNotNullOrEmpty()] 20 | [System.String] 21 | $FileContent, 22 | 23 | [Parameter(Mandatory = $true)] 24 | [ValidateNotNullOrEmpty()] 25 | [System.Management.Automation.PSCredential] 26 | [System.Management.Automation.Credential()] 27 | $Credential 28 | ) 29 | 30 | Import-DscResource -ModuleName 'PSDscResources' 31 | 32 | Node localhost 33 | { 34 | Script Script1 35 | { 36 | SetScript = { 37 | $streamWriter = New-Object -TypeName 'System.IO.StreamWriter' -ArgumentList @( $using:FilePath ) 38 | $streamWriter.WriteLine($using:FileContent) 39 | $streamWriter.Close() 40 | } 41 | TestScript = { 42 | if (Test-Path -Path $using:FilePath) 43 | { 44 | $fileContent = Get-Content -Path $using:filePath -Raw 45 | return $fileContent -eq $using:FileContent 46 | } 47 | else 48 | { 49 | return $false 50 | } 51 | } 52 | GetScript = { 53 | $fileContent = $null 54 | 55 | if (Test-Path -Path $using:FilePath) 56 | { 57 | $fileContent = Get-Content -Path $using:filePath -Raw 58 | } 59 | 60 | return @{ 61 | Result = Get-Content -Path $fileContent 62 | } 63 | } 64 | Credential = $Credential 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_ServiceResource_AllExceptCredential.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String] 15 | $Name, 16 | 17 | [Parameter(Mandatory = $true)] 18 | [ValidateNotNullOrEmpty()] 19 | [System.String] 20 | $Path, 21 | 22 | [ValidateSet('Present', 'Absent')] 23 | [ValidateNotNullOrEmpty()] 24 | [System.String] 25 | $Ensure = 'Present', 26 | 27 | [Parameter()] 28 | [ValidateNotNullOrEmpty()] 29 | [System.String] 30 | $DisplayName = "$Name DisplayName", 31 | 32 | [Parameter()] 33 | [System.String] 34 | $Description = 'TestDescription', 35 | 36 | [Parameter()] 37 | [System.String[]] 38 | [AllowEmptyCollection()] 39 | $Dependencies = @(), 40 | 41 | [Parameter()] 42 | [ValidateSet('LocalSystem', 'LocalService', 'NetworkService')] 43 | [System.String] 44 | $BuiltInAccount = 'LocalSystem', 45 | 46 | [Parameter()] 47 | [System.Boolean] 48 | $DesktopInteract = $false, 49 | 50 | [Parameter()] 51 | [ValidateSet('Automatic', 'Manual', 'Disabled')] 52 | [System.String] 53 | $StartupType = 'Automatic', 54 | 55 | [Parameter()] 56 | [ValidateSet('Running', 'Stopped', 'Ignore')] 57 | [System.String] 58 | $State = 'Running', 59 | 60 | [Parameter()] 61 | [System.UInt32] 62 | $StartupTimeout = 30000, 63 | 64 | [Parameter()] 65 | [System.UInt32] 66 | $TerminateTimeout = 30000 67 | ) 68 | 69 | Import-DscResource -ModuleName 'PSDscResources' 70 | 71 | Node localhost 72 | { 73 | Service Service1 74 | { 75 | Name = $Name 76 | Ensure = $Ensure 77 | Path = $Path 78 | StartupType = $StartupType 79 | BuiltInAccount = $BuiltInAccount 80 | DesktopInteract = $DesktopInteract 81 | State = $State 82 | DisplayName = $DisplayName 83 | Description = $Description 84 | Dependencies = $Dependencies 85 | StartupTimeout = $StartupTimeout 86 | TerminateTimeout = $TerminateTimeout 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_ServiceResource_CredentialOnly.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String] 15 | $Name, 16 | 17 | [ValidateSet('Present', 'Absent')] 18 | [ValidateNotNullOrEmpty()] 19 | [System.String] 20 | $Ensure = 'Present', 21 | 22 | [Parameter(Mandatory = $true)] 23 | [ValidateNotNullOrEmpty()] 24 | [System.Management.Automation.PSCredential] 25 | $Credential 26 | ) 27 | 28 | Import-DscResource -ModuleName 'PSDscResources' 29 | 30 | Node localhost 31 | { 32 | Service Service1 33 | { 34 | Name = $Name 35 | Ensure = $Ensure 36 | Credential = $Credential 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_UserResource.config.ps1: -------------------------------------------------------------------------------- 1 | 2 | # Integration Test Config Template Version 1.0.0 3 | param 4 | ( 5 | [Parameter(Mandatory = $true)] 6 | [System.String] 7 | $ConfigurationName 8 | ) 9 | 10 | 11 | Configuration $ConfigurationName 12 | { 13 | param 14 | ( 15 | [System.String] 16 | $UserName = 'Test UserName', 17 | 18 | [System.String] 19 | $Description = 'Test Description', 20 | 21 | [System.String] 22 | $FullName = 'Test Full Name', 23 | 24 | [ValidateSet('Present', 'Absent')] 25 | [System.String] 26 | $Ensure = 'Present', 27 | 28 | [Parameter(Mandatory = $true)] 29 | [System.Management.Automation.PSCredential] 30 | [System.Management.Automation.Credential()] 31 | $Password, 32 | 33 | [Boolean] 34 | $PasswordNeverExpires = $false 35 | ) 36 | 37 | Import-DscResource -ModuleName 'PSDscResources' 38 | 39 | Node localhost { 40 | 41 | User UserResource1 42 | { 43 | UserName = $UserName 44 | Ensure = $Ensure 45 | FullName = $FullName 46 | Description = $Description 47 | Password = $Password 48 | PasswordNeverExpires = $PasswordNeverExpires 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_WindowsFeature.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [System.String] 14 | $Name, 15 | 16 | [ValidateSet('Present', 'Absent')] 17 | [System.String] 18 | $Ensure = 'Present', 19 | 20 | [System.Boolean] 21 | $IncludeAllSubFeature = $false 22 | ) 23 | 24 | Import-DscResource -ModuleName 'PSDscResources' 25 | 26 | Node Localhost 27 | { 28 | WindowsFeature WindowsFeatureTest 29 | { 30 | Name = $Name 31 | Ensure = $Ensure 32 | IncludeAllSubFeature = $IncludeAllSubFeature 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_WindowsOptionalFeature.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String] 15 | $Name, 16 | 17 | [ValidateSet('Present', 'Absent')] 18 | [ValidateNotNullOrEmpty()] 19 | [System.String] 20 | $Ensure = 'Present', 21 | 22 | [ValidateNotNullOrEmpty()] 23 | [System.String] 24 | $LogPath = (Join-Path -Path (Get-Location) -ChildPath 'WOFTestLog.txt'), 25 | 26 | [System.Boolean] 27 | $RemoveFilesOnDisable = $false, 28 | 29 | [System.Boolean] 30 | $NoWindowsUpdateCheck = $true 31 | ) 32 | 33 | Import-DscResource -ModuleName 'PSDscResources' 34 | 35 | WindowsOptionalFeature WindowsOptionalFeature1 36 | { 37 | Name = $Name 38 | Ensure = $Ensure 39 | LogPath = $LogPath 40 | NoWindowsUpdateCheck = $NoWindowsUpdateCheck 41 | RemoveFilesOnDisable = $RemoveFilesOnDisable 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_WindowsPackageCab.Integration.Tests.ps1: -------------------------------------------------------------------------------- 1 | if ($PSVersionTable.PSVersion -lt [Version] '5.1') 2 | { 3 | Write-Warning -Message 'Cannot run PSDscResources integration tests on PowerShell versions lower than 5.1' 4 | return 5 | } 6 | 7 | $errorActionPreference = 'Stop' 8 | Set-StrictMode -Version 'Latest' 9 | 10 | $script:testFolderPath = Split-Path -Path $PSScriptRoot -Parent 11 | $script:testHelpersPath = Join-Path -Path $script:testFolderPath -ChildPath 'TestHelpers' 12 | Import-Module -Name (Join-Path -Path $script:testHelpersPath -ChildPath 'CommonTestHelper.psm1') 13 | 14 | $script:testEnvironment = Enter-DscResourceTestEnvironment ` 15 | -DscResourceModuleName 'PSDscResources' ` 16 | -DscResourceName 'MSFT_WindowsPackageCab' ` 17 | -TestType 'Integration' 18 | 19 | try 20 | { 21 | Describe 'WindowsPackageCab Integration Tests' { 22 | BeforeAll { 23 | Import-Module -Name 'Dism' 24 | 25 | $script:installedStates = @( 'Installed', 'InstallPending' ) 26 | $script:confgurationFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'MSFT_WindowsPackageCab.config.ps1' 27 | 28 | $script:testPackageName = '' 29 | $script:testSourcePath = Join-Path -Path $PSScriptRoot -ChildPath '' 30 | 31 | $script:cabPackageNotProvided = $script:testPackageName -eq [System.String]::Empty 32 | 33 | try 34 | { 35 | $originalPackage = Dism\Get-WindowsPackage -PackageName $script:testPackageName -Online 36 | if ($null -ne $originalPackage -and $originalPackage.PackageState -in $script:installedStates) 37 | { 38 | $script:packageOriginallyInstalled = $true 39 | } 40 | else 41 | { 42 | $script:packageOriginallyInstalled = $false 43 | } 44 | } 45 | catch 46 | { 47 | $script:packageOriginallyInstalled = $false 48 | } 49 | 50 | if ($script:packageOriginallyInstalled) 51 | { 52 | throw "Package $script:testPackageName is currently installed on this machine. These tests may destroy this package. Aborting." 53 | } 54 | } 55 | 56 | AfterEach { 57 | if (-not $script:packageOriginallyInstalled) 58 | { 59 | try 60 | { 61 | $windowsPackage = Dism\Get-WindowsPackage -PackageName $script:testPackageName -Online 62 | if ($null -ne $windowsPackage -and $windowsPackage.PackageState -in $script:installedStates) 63 | { 64 | Dism\Remove-WindowsPackage -PackageName $script:testPackageName.Name -Online -NoRestart 65 | } 66 | } 67 | catch 68 | { 69 | Write-Verbose -Message "No test cleanup needed. Package $script:testPackageName not found." 70 | } 71 | } 72 | } 73 | 74 | It 'Should install a Windows package through a cab file' -Skip:$script:cabPackageNotProvided { 75 | $configurationName = 'InstallWindowsPackageCab' 76 | 77 | $resourceParameters = @{ 78 | Name = $script:testPackageName 79 | SourcePath = $script:testSourcePath 80 | Ensure = 'Present' 81 | } 82 | 83 | { 84 | . $script:confgurationFilePath -ConfigurationName $configurationName 85 | & $configurationName -OutputPath $TestDrive @resourceParameters 86 | Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force 87 | } | Should -Not -Throw 88 | 89 | { $null = Dism\Get-WindowsPackage -PackageName $resourceParameters.Name -Online } | Should -Not -Throw 90 | 91 | $windowsPackage = Dism\Get-WindowsPackage -PackageName $resourceParameters.Name -Online 92 | $windowsPackage | Should -Not -Be $null 93 | $windowsPackage.PackageState -in $script:installedStates | Should -BeTrue 94 | } 95 | 96 | It 'Should uninstall a Windows package through a cab file' -Skip:$script:cabPackageNotProvided { 97 | $configurationName = 'UninstallWindowsPackageCab' 98 | 99 | $resourceParameters = @{ 100 | Name = $script:testPackageName 101 | SourcePath = $script:testSourcePath 102 | Ensure = 'Absent' 103 | } 104 | 105 | Dism\Add-WindowsPackage -PackagePath $resourceParameters.SourcePath -Online -NoRestart 106 | 107 | { $null = Dism\Get-WindowsPackage -PackageName $resourceParameters.Name -Online } | Should -Not -Throw 108 | 109 | { 110 | . $script:confgurationFilePath -ConfigurationName $configurationName 111 | & $configurationName -OutputPath $TestDrive @resourceParameters 112 | Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force 113 | } | Should -Not -Throw 114 | 115 | { $null = Dism\Get-WindowsPackage -PackageName $resourceParameters.Name -Online } | Should -Throw 116 | } 117 | 118 | It 'Should not install an invalid Windows package through a cab file' { 119 | $configurationName = 'InstallInvalidWindowsPackageCab' 120 | 121 | $resourceParameters = @{ 122 | Name = 'NonExistentWindowsPackageCab' 123 | SourcePath = (Join-Path -Path $TestDrive -ChildPath 'FakePath.cab') 124 | Ensure = 'Present' 125 | LogPath = (Join-Path -Path $TestDrive -ChildPath 'InvalidWindowsPackageCab.log') 126 | } 127 | 128 | { Dism\Get-WindowsPackage -PackageName $resourceParameters.Name -Online } | Should -Throw 129 | 130 | { 131 | . $script:confgurationFilePath -ConfigurationName $configurationName 132 | & $configurationName -OutputPath $TestDrive @resourceParameters 133 | Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force 134 | } | Should -Throw 135 | 136 | Test-Path -Path $resourceParameters.LogPath | Should -BeTrue 137 | 138 | { Dism\Get-WindowsPackage -PackageName $resourceParameters.Name -Online } | Should -Throw 139 | } 140 | } 141 | } 142 | finally 143 | { 144 | Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment 145 | } 146 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_WindowsPackageCab.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String] 15 | $Name, 16 | 17 | [Parameter(Mandatory = $true)] 18 | [ValidateSet('Present', 'Absent')] 19 | [System.String] 20 | $Ensure, 21 | 22 | [Parameter(Mandatory = $true)] 23 | [ValidateNotNullOrEmpty()] 24 | [System.String] 25 | $SourcePath, 26 | 27 | [ValidateNotNullOrEmpty()] 28 | [System.String] 29 | $LogPath = (Join-Path -Path (Get-Location) -ChildPath 'WindowsPackageCabTestLog.txt') 30 | ) 31 | 32 | Import-DscResource -ModuleName 'PSDscResources' 33 | 34 | WindowsPackageCab WindowsPackageCab1 35 | { 36 | Name = $Name 37 | Ensure = $Ensure 38 | SourcePath = $SourcePath 39 | LogPath = $LogPath 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_WindowsProcess_NoCredential.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String] 15 | $Path, 16 | 17 | [Parameter(Mandatory = $true)] 18 | [AllowEmptyString()] 19 | [System.String] 20 | $Arguments, 21 | 22 | [ValidateSet('Present', 'Absent')] 23 | [System.String] 24 | $Ensure = 'Present' 25 | ) 26 | 27 | Import-DscResource -ModuleName 'PSDscResources' 28 | 29 | WindowsProcess Process1 30 | { 31 | Path = $Path 32 | Arguments = $Arguments 33 | Ensure = $Ensure 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Tests/Integration/MSFT_WindowsProcess_WithCredential.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String] 15 | $Path, 16 | 17 | [Parameter(Mandatory = $true)] 18 | [AllowEmptyString()] 19 | [System.String] 20 | $Arguments, 21 | 22 | [ValidateSet('Present', 'Absent')] 23 | [System.String] 24 | $Ensure = 'Present', 25 | 26 | [Parameter(Mandatory = $true)] 27 | [System.Management.Automation.PSCredential] 28 | [System.Management.Automation.Credential()] 29 | $Credential = (Get-Credential) 30 | ) 31 | 32 | Import-DscResource -ModuleName 'PSDscResources' 33 | 34 | Node $AllNodes.NodeName 35 | { 36 | WindowsProcess Process1 37 | { 38 | Path = $Path 39 | Arguments = $Arguments 40 | Credential = $Credential 41 | Ensure = $Ensure 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Tests/Integration/ProcessSet.Integration.Tests.ps1: -------------------------------------------------------------------------------- 1 | 2 | if ($PSVersionTable.PSVersion -lt [Version] '5.1') 3 | { 4 | Write-Warning -Message 'Cannot run PSDscResources integration tests on PowerShell versions lower than 5.1' 5 | return 6 | } 7 | 8 | $errorActionPreference = 'Stop' 9 | Set-StrictMode -Version 'Latest' 10 | 11 | $script:testFolderPath = Split-Path -Path $PSScriptRoot -Parent 12 | $script:testHelpersPath = Join-Path -Path $script:testFolderPath -ChildPath 'TestHelpers' 13 | Import-Module -Name (Join-Path -Path $script:testHelpersPath -ChildPath 'CommonTestHelper.psm1') 14 | 15 | $script:testEnvironment = Enter-DscResourceTestEnvironment ` 16 | -DscResourceModuleName 'PSDScResources' ` 17 | -DscResourceName 'ProcessSet' ` 18 | -TestType 'Integration' 19 | 20 | try 21 | { 22 | Describe 'ProcessSet Integration Tests' { 23 | BeforeAll { 24 | $script:configurationFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'ProcessSet.config.ps1' 25 | 26 | $originalProcessPath = Join-Path -Path $script:testHelpersPath -ChildPath 'WindowsProcessTestProcessSet.exe' 27 | $copiedProcessPath = Join-Path -Path $TestDrive -ChildPath 'TestWindowsProcess2.exe' 28 | 29 | Copy-Item -Path $originalProcessPath -Destination $copiedProcessPath -Force 30 | 31 | $script:processPaths = @( $originalProcessPath, $copiedProcessPath) 32 | } 33 | 34 | AfterAll { 35 | foreach ($processPath in $script:processPaths) 36 | { 37 | $processName = [System.IO.Path]::GetFileNameWithoutExtension($processPath) 38 | $process = Get-Process -Name $processName -ErrorAction 'SilentlyContinue' 39 | 40 | if ($null -ne $process) 41 | { 42 | Stop-Process -Name $processName -ErrorAction 'SilentlyContinue' -Force 43 | } 44 | } 45 | } 46 | 47 | Context 'Start two processes' { 48 | $configurationName = 'StartProcessSet' 49 | 50 | $processSetParameters = @{ 51 | ProcessPaths = $script:processPaths 52 | Ensure = 'Present' 53 | } 54 | 55 | foreach ($processPath in $processSetParameters.ProcessPaths) 56 | { 57 | $processName = [System.IO.Path]::GetFileNameWithoutExtension($processPath) 58 | $process = Get-Process -Name $processName -ErrorAction 'SilentlyContinue' 59 | 60 | if ($null -ne $process) 61 | { 62 | $null = Stop-Process -Name $processName -ErrorAction 'SilentlyContinue' -Force 63 | 64 | # May need to wait a moment for the correct state to populate 65 | $millisecondsElapsed = 0 66 | $startTime = Get-Date 67 | while ($null -eq $process -and $millisecondsElapsed -lt 3000) 68 | { 69 | $process = Get-Process -Name $processName -ErrorAction 'SilentlyContinue' 70 | $millisecondsElapsed = ((Get-Date) - $startTime).TotalMilliseconds 71 | } 72 | } 73 | 74 | It "Should not have started process $processName before configuration" { 75 | $process | Should -Be $null 76 | } 77 | } 78 | 79 | It 'Should compile and run configuration' { 80 | { 81 | . $script:configurationFilePath -ConfigurationName $configurationName 82 | & $configurationName -OutputPath $TestDrive @processSetParameters 83 | Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force 84 | } | Should -Not -Throw 85 | } 86 | 87 | foreach ($processPath in $processSetParameters.ProcessPaths) 88 | { 89 | $processName = [System.IO.Path]::GetFileNameWithoutExtension($processPath) 90 | $process = Get-Process -Name $processName -ErrorAction 'SilentlyContinue' 91 | 92 | It "Should have started process $processName after configuration" { 93 | $process | Should -Not -Be $null 94 | } 95 | } 96 | } 97 | 98 | Context 'Stop two processes' { 99 | $configurationName = 'StopProcessSet' 100 | 101 | $processSetParameters = @{ 102 | ProcessPaths = $script:processPaths 103 | Ensure = 'Absent' 104 | } 105 | 106 | foreach ($processPath in $processSetParameters.ProcessPaths) 107 | { 108 | $processName = [System.IO.Path]::GetFileNameWithoutExtension($processPath) 109 | $process = Get-Process -Name $processName -ErrorAction 'SilentlyContinue' 110 | 111 | if ($null -eq $process) 112 | { 113 | $null = Start-Process -FilePath $processPath -ErrorAction 'SilentlyContinue' 114 | 115 | # May need to wait a moment for the correct state to populate 116 | $millisecondsElapsed = 0 117 | $startTime = Get-Date 118 | while ($null -eq $process -and $millisecondsElapsed -lt 3000) 119 | { 120 | $process = Get-Process -Name $processName -ErrorAction 'SilentlyContinue' 121 | $millisecondsElapsed = ((Get-Date) - $startTime).TotalMilliseconds 122 | } 123 | } 124 | 125 | It "Should have started process $processName before configuration" { 126 | $process | Should -Not -Be $null 127 | } 128 | } 129 | 130 | It 'Should compile and run configuration' { 131 | { 132 | . $script:configurationFilePath -ConfigurationName $configurationName 133 | & $configurationName -OutputPath $TestDrive @processSetParameters 134 | Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force 135 | } | Should -Not -Throw 136 | } 137 | 138 | foreach ($processPath in $processSetParameters.ProcessPaths) 139 | { 140 | $processName = [System.IO.Path]::GetFileNameWithoutExtension($processPath) 141 | $process = Get-Process -Name $processName -ErrorAction 'SilentlyContinue' 142 | 143 | It "Should have stopped process $processName after configuration" { 144 | $process | Should -Be $null 145 | } 146 | } 147 | } 148 | } 149 | } 150 | finally 151 | { 152 | Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment 153 | } 154 | -------------------------------------------------------------------------------- /Tests/Integration/ProcessSet.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String[]] 15 | $ProcessPaths, 16 | 17 | [ValidateSet('Present', 'Absent')] 18 | [System.String] 19 | $Ensure = 'Present' 20 | ) 21 | 22 | Import-DscResource -ModuleName 'PSDscResources' 23 | 24 | ProcessSet ProcessSet1 25 | { 26 | Path = $ProcessPaths 27 | Ensure = $Ensure 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Tests/Integration/ServiceSet_AllExceptBuiltInAccount.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String[]] 15 | $Name, 16 | 17 | [ValidateSet('Present', 'Absent')] 18 | [ValidateNotNullOrEmpty()] 19 | [System.String] 20 | $Ensure = 'Present', 21 | 22 | [Parameter(Mandatory = $true)] 23 | [ValidateNotNullOrEmpty()] 24 | [System.Management.Automation.PSCredential] 25 | [System.Management.Automation.Credential()] 26 | $Credential, 27 | 28 | [ValidateSet('Running', 'Stopped', 'Ignore')] 29 | [System.String] 30 | $State = 'Running', 31 | 32 | [ValidateSet('Automatic', 'Manual', 'Disabled')] 33 | [System.String] 34 | $StartupType = 'Automatic' 35 | ) 36 | 37 | Import-DscResource -ModuleName 'PSDscResources' 38 | 39 | Node localhost 40 | { 41 | ServiceSet ServiceSet1 42 | { 43 | Name = $Name 44 | Ensure = $Ensure 45 | Credential = $Credential 46 | State = $State 47 | StartupType = $StartupType 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Tests/Integration/ServiceSet_BuiltInAccountOnly.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String[]] 15 | $Name, 16 | 17 | [ValidateSet('Present', 'Absent')] 18 | [ValidateNotNullOrEmpty()] 19 | [System.String] 20 | $Ensure = 'Present', 21 | 22 | [Parameter(Mandatory = $true)] 23 | [ValidateSet('LocalSystem', 'LocalService', 'NetworkService')] 24 | [System.String] 25 | $BuiltInAccount 26 | ) 27 | 28 | Import-DscResource -ModuleName 'PSDscResources' 29 | 30 | Node localhost 31 | { 32 | ServiceSet ServiceSet1 33 | { 34 | Name = $Name 35 | Ensure = $Ensure 36 | BuiltInAccount = $BuiltInAccount 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Tests/Integration/WindowsFeatureSet.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String[]] 15 | $WindowsFeatureNames, 16 | 17 | [ValidateSet('Present', 'Absent')] 18 | [System.String] 19 | $Ensure = 'Present', 20 | 21 | [ValidateNotNullOrEmpty()] 22 | [System.String] 23 | $LogPath 24 | ) 25 | 26 | Import-DscResource -ModuleName 'PSDscResources' 27 | 28 | WindowsFeatureSet WindowsFeatureSet1 29 | { 30 | Name = $WindowsFeatureNames 31 | Ensure = $Ensure 32 | LogPath = $LogPath 33 | IncludeAllSubfeature = $false 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Tests/Integration/WindowsOptionalFeatureSet.config.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [Parameter(Mandatory = $true)] 4 | [System.String] 5 | $ConfigurationName 6 | ) 7 | 8 | Configuration $ConfigurationName 9 | { 10 | param 11 | ( 12 | [Parameter(Mandatory = $true)] 13 | [ValidateNotNullOrEmpty()] 14 | [System.String[]] 15 | $WindowsOptionalFeatureNames, 16 | 17 | [ValidateSet('Present', 'Absent')] 18 | [System.String] 19 | $Ensure = 'Present', 20 | 21 | [ValidateNotNullOrEmpty()] 22 | [System.String] 23 | $LogPath 24 | ) 25 | 26 | Import-DscResource -ModuleName 'PSDscResources' 27 | 28 | WindowsOptionalFeatureSet WindowsOptionalFeatureSet1 29 | { 30 | Name = $WindowsOptionalFeatureNames 31 | Ensure = $Ensure 32 | LogPath = $LogPath 33 | NoWindowsUpdateCheck = $false 34 | RemoveFilesOnDisable = $false 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Tests/TestHelpers/DSCTestService.cs: -------------------------------------------------------------------------------- 1 | namespace TestServiceNamespace 2 | { 3 | using System; 4 | using System.ComponentModel; 5 | using System.Configuration.Install; 6 | using System.IO; 7 | using System.ServiceProcess; 8 | 9 | [RunInstaller(true)] 10 | public class MyProjectInstaller : Installer 11 | { 12 | private ServiceInstaller serviceInstaller; 13 | private ServiceProcessInstaller processInstaller; 14 | 15 | public MyProjectInstaller() 16 | { 17 | processInstaller = new ServiceProcessInstaller(); 18 | serviceInstaller = new ServiceInstaller(); 19 | processInstaller.Account = ServiceAccount.LocalSystem; 20 | serviceInstaller.StartType = ServiceStartMode.Manual; 21 | serviceInstaller.ServiceName = TestService.TestServiceName; 22 | serviceInstaller.DisplayName = TestService.TestServiceDisplayName; 23 | serviceInstaller.Description = TestService.TestServiceDescription; 24 | serviceInstaller.ServicesDependedOn = new string[] { TestService.TestServiceDependsOn }; 25 | Installers.Add(serviceInstaller); 26 | Installers.Add(processInstaller); 27 | } 28 | } 29 | 30 | public class TestService : ServiceBase 31 | { 32 | public const string TestServiceName = "TestServiceReplacementName"; 33 | public const string TestServiceDisplayName = "TestServiceReplacementDisplayName"; 34 | public const string TestServiceDescription = "TestServiceReplacementDescription"; 35 | public const string TestServiceDependsOn = "TestServiceReplacementDependsOn"; 36 | 37 | private string fileName = null; 38 | private System.ComponentModel.IContainer components = null; 39 | private bool failToStop = false; 40 | 41 | public TestService() 42 | { 43 | this.CanStop=true; 44 | this.CanPauseAndContinue=true; 45 | InitializeComponent(); 46 | } 47 | 48 | protected override void OnStart(string[] args) 49 | { 50 | if(args.Length == 1 && args[0] == "FailToStop") 51 | { 52 | this.failToStop=true; 53 | return; 54 | } 55 | 56 | if (args.Length == 0 || !Path.IsPathRooted(args[0])) 57 | { 58 | return; 59 | } 60 | 61 | this.fileName=args[0]; 62 | using (StreamWriter writer = File.CreateText(fileName)) 63 | { 64 | writer.WriteLine("Service started at {0}.", DateTime.Now); 65 | writer.WriteLine("Argument count: {0}.\r\nArguments:", args.Length); 66 | foreach (string arg in args) 67 | { 68 | writer.WriteLine(" '{0}'", arg); 69 | } 70 | } 71 | } 72 | 73 | protected override void OnStop() 74 | { 75 | if(this.failToStop) 76 | { 77 | this.failToStop = false; 78 | throw new Exception("Will fail to stop"); 79 | } 80 | 81 | if (this.fileName == null) { return; } 82 | using (StreamWriter writer = File.AppendText(this.fileName)) 83 | { 84 | writer.WriteLine("Service stopped at {0}.", DateTime.Now); 85 | } 86 | } 87 | 88 | protected override void OnPause() 89 | { 90 | base.OnPause(); 91 | } 92 | 93 | protected override void OnContinue() 94 | { 95 | base.OnContinue(); 96 | } 97 | 98 | 99 | protected override void Dispose(bool disposing) 100 | { 101 | if (disposing && (components != null)) 102 | { 103 | components.Dispose(); 104 | } 105 | base.Dispose(disposing); 106 | } 107 | 108 | private void InitializeComponent() 109 | { 110 | components = new System.ComponentModel.Container(); 111 | this.ServiceName = TestService.TestServiceName; 112 | } 113 | 114 | static void Main() 115 | { 116 | ServiceBase[] ServicesToRun; 117 | ServicesToRun = new ServiceBase[] 118 | { 119 | new TestService() 120 | }; 121 | ServiceBase.Run(ServicesToRun); 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Tests/TestHelpers/DSCTestServiceNew.cs: -------------------------------------------------------------------------------- 1 | namespace TestServiceNamespace 2 | { 3 | using System; 4 | using System.ComponentModel; 5 | using System.Configuration.Install; 6 | using System.IO; 7 | using System.ServiceProcess; 8 | 9 | [RunInstaller(true)] 10 | public class MyProjectInstaller : Installer 11 | { 12 | private ServiceInstaller serviceInstaller; 13 | private ServiceProcessInstaller processInstaller; 14 | 15 | public MyProjectInstaller() 16 | { 17 | processInstaller = new ServiceProcessInstaller(); 18 | serviceInstaller = new ServiceInstaller(); 19 | processInstaller.Account = ServiceAccount.LocalSystem; 20 | serviceInstaller.StartType = ServiceStartMode.Manual; 21 | serviceInstaller.ServiceName = TestService.TestServiceName; 22 | serviceInstaller.DisplayName = TestService.TestServiceDisplayName; 23 | serviceInstaller.Description = TestService.TestServiceDescription; 24 | serviceInstaller.ServicesDependedOn = new string[] { TestService.TestServiceDependsOn }; 25 | Installers.Add(serviceInstaller); 26 | Installers.Add(processInstaller); 27 | } 28 | } 29 | 30 | public class TestService : ServiceBase 31 | { 32 | public const string TestServiceName = "TestServiceReplacementName"; 33 | public const string TestServiceDisplayName = "TestServiceReplacementDisplayName"; 34 | public const string TestServiceDescription = "TestServiceReplacementDescription"; 35 | public const string TestServiceDependsOn = "TestServiceReplacementDependsOn"; 36 | 37 | private string fileName = null; 38 | private System.ComponentModel.IContainer components = null; 39 | private bool failToStop = false; 40 | 41 | public TestService() 42 | { 43 | this.CanStop=true; 44 | this.CanPauseAndContinue=true; 45 | InitializeComponent(); 46 | } 47 | 48 | protected override void OnStart(string[] args) 49 | { 50 | if(args.Length == 1 && args[0] == "FailToStop") 51 | { 52 | this.failToStop=true; 53 | return; 54 | } 55 | 56 | if (args.Length == 0 || !Path.IsPathRooted(args[0])) 57 | { 58 | return; 59 | } 60 | 61 | this.fileName=args[0]; 62 | using (StreamWriter writer = File.CreateText(fileName)) 63 | { 64 | writer.WriteLine("Service started at {0}.", DateTime.Now); 65 | writer.WriteLine("Argument count: {0}.\r\nArguments:", args.Length); 66 | foreach (string arg in args) 67 | { 68 | writer.WriteLine(" '{0}'", arg); 69 | } 70 | } 71 | } 72 | 73 | protected override void OnStop() 74 | { 75 | if(this.failToStop) 76 | { 77 | this.failToStop = false; 78 | throw new Exception("Will fail to stop"); 79 | } 80 | 81 | if (this.fileName == null) { return; } 82 | using (StreamWriter writer = File.AppendText(this.fileName)) 83 | { 84 | writer.WriteLine("Service stopped at {0}.", DateTime.Now); 85 | } 86 | } 87 | 88 | protected override void OnPause() 89 | { 90 | base.OnPause(); 91 | } 92 | 93 | protected override void OnContinue() 94 | { 95 | base.OnContinue(); 96 | } 97 | 98 | 99 | protected override void Dispose(bool disposing) 100 | { 101 | if (disposing && (components != null)) 102 | { 103 | components.Dispose(); 104 | } 105 | base.Dispose(disposing); 106 | } 107 | 108 | private void InitializeComponent() 109 | { 110 | components = new System.ComponentModel.Container(); 111 | this.ServiceName = TestService.TestServiceName; 112 | } 113 | 114 | static void Main() 115 | { 116 | ServiceBase[] ServicesToRun; 117 | ServicesToRun = new ServiceBase[] 118 | { 119 | new TestService() 120 | }; 121 | ServiceBase.Run(ServicesToRun); 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Tests/TestHelpers/MSFT_ServiceResource.TestHelper.psm1: -------------------------------------------------------------------------------- 1 | $errorActionPreference = 'Stop' 2 | Set-StrictMode -Version 'Latest' 3 | 4 | <# 5 | .SYNOPSIS 6 | Creates a service executable. 7 | 8 | .PARAMETER ServiceName 9 | The name of the service to create the executable for. 10 | 11 | .PARAMETER ServiceCodePath 12 | The path to the code for the service to create the executable for. 13 | 14 | .PARAMETER ServiceDisplayName 15 | The display name of the service to create the executable for. 16 | 17 | .PARAMETER ServiceDescription 18 | The description of the service to create the executable for. 19 | 20 | .PARAMETER ServiceDependsOn 21 | The names of the dependencies of the service to create the executable for. 22 | 23 | .PARAMETER OutputPath 24 | The path to write the outputed service executable to. 25 | #> 26 | function New-ServiceExecutable 27 | { 28 | [CmdletBinding()] 29 | param ( 30 | [Parameter(Mandatory = $true)] 31 | [ValidateNotNullOrEmpty()] 32 | [System.String] 33 | $ServiceName, 34 | 35 | [Parameter(Mandatory = $true)] 36 | [ValidateNotNullOrEmpty()] 37 | [System.String] 38 | $ServiceCodePath, 39 | 40 | [Parameter(Mandatory = $true)] 41 | [ValidateNotNullOrEmpty()] 42 | [System.String] 43 | $ServiceDisplayName, 44 | 45 | [Parameter(Mandatory = $true)] 46 | [ValidateNotNullOrEmpty()] 47 | [System.String] 48 | $ServiceDescription, 49 | 50 | [Parameter()] 51 | [ValidateNotNullOrEmpty()] 52 | [System.String] 53 | $ServiceDependsOn = "''", 54 | 55 | [Parameter(Mandatory = $true)] 56 | [ValidateNotNullOrEmpty()] 57 | [System.String] 58 | $OutputPath 59 | ) 60 | 61 | $fileText = Get-Content -Path $ServiceCodePath -Raw 62 | $fileText = $fileText.Replace('TestServiceReplacementName', $ServiceName) 63 | $fileText = $fileText.Replace('TestServiceReplacementDisplayName', $ServiceDisplayName) 64 | $fileText = $fileText.Replace('TestServiceReplacementDescription', $ServiceDescription) 65 | $fileText = $fileText.Replace('TestServiceReplacementDependsOn', $ServiceDependsOn) 66 | 67 | $addTypeParameters = @{ 68 | TypeDefinition = $fileText 69 | OutputAssembly = $OutputPath 70 | OutputType = 'WindowsApplication' 71 | ReferencedAssemblies = @( 'System.ServiceProcess', 'System.Configuration.Install' ) 72 | } 73 | 74 | $null = Add-Type @addTypeParameters 75 | } 76 | 77 | <# 78 | .SYNOPSIS 79 | Deletes the service with the given name and waits 5 seconds maximum for the service to be 80 | deleted. 81 | 82 | .PARAMETER Name 83 | The name of the service to delete. 84 | #> 85 | function Remove-ServiceWithTimeout 86 | { 87 | [CmdletBinding()] 88 | param 89 | ( 90 | [Parameter(Mandatory = $true)] 91 | [ValidateNotNullorEmpty()] 92 | [System.String] 93 | $Name 94 | ) 95 | 96 | Stop-Service -Name $Name 97 | 98 | & 'sc.exe' 'delete' $Name 99 | 100 | $serviceDeleted = $false 101 | $start = [System.DateTime]::Now 102 | 103 | while (-not $serviceDeleted -and ([System.DateTime]::Now - $start).TotalMilliseconds -lt 5000) 104 | { 105 | $service = Get-Service -Name $Name -ErrorAction 'SilentlyContinue' 106 | 107 | if ($null -eq $service) 108 | { 109 | $serviceDeleted = $true 110 | } 111 | else 112 | { 113 | Start-Sleep -Seconds 1 114 | } 115 | } 116 | } 117 | 118 | <# 119 | .SYNOPSIS 120 | Tests if the service with the specified name exists. 121 | 122 | .PARAMETER Name 123 | The name of the service. 124 | #> 125 | function Test-ServiceExists 126 | { 127 | [OutputType([System.Boolean])] 128 | [CmdletBinding()] 129 | param 130 | ( 131 | [Parameter(Mandatory = $true)] 132 | [System.String] 133 | $Name 134 | ) 135 | 136 | $service = Get-Service -Name $Name -ErrorAction 'SilentlyContinue' 137 | return $null -ne $service 138 | } 139 | 140 | Export-ModuleMember -Function @( 'New-ServiceExecutable', 'Remove-ServiceWithTimeout', 'Test-ServiceExists' ) 141 | -------------------------------------------------------------------------------- /Tests/TestHelpers/WMF5Dot1Installation.psm1: -------------------------------------------------------------------------------- 1 | Set-StrictMode -Version 'latest' 2 | $errorActionPreference = 'Stop' 3 | 4 | <# 5 | .SYNOPSIS 6 | Retrieves the URL for downloading the WMF 5.1 installation file for Windows 8.1 and Windows Server 2012 R2(amd64). 7 | #> 8 | function Get-Wmf5Dot1InstallFileUrl 9 | { 10 | [OutputType([String])] 11 | [CmdletBinding()] 12 | param () 13 | 14 | return 'https://download.microsoft.com/download/6/F/5/6F5FF66C-6775-42B0-86C4-47D41F2DA187/Win8.1AndW2K12R2-KB3191564-x64.msu' 15 | } 16 | 17 | <# 18 | .SYNOPSIS 19 | Downloads the WMF 5.1 installation file to the given location. 20 | 21 | .PARAMETER DownloadLocation 22 | The file path to download the WMF 5.1 install file to. 23 | #> 24 | function Download-Wmf5Dot1InstallFile 25 | { 26 | [CmdletBinding()] 27 | param 28 | ( 29 | [Parameter(Mandatory = $true)] 30 | [String] 31 | $DownloadLocation 32 | ) 33 | 34 | $wmf5Dot1InstallFileUrl = Get-Wmf5Dot1InstallFileUrl 35 | $null = Invoke-WebRequest -Uri $wmf5Dot1InstallFileUrl -OutFile $DownloadLocation 36 | } 37 | 38 | <# 39 | .SYNOPSIS 40 | Invokes WUSA to install the given file. 41 | Outputs the exit code from WUSA. 42 | 43 | .PARAMETER InstallFile 44 | The file to install using WUSA. 45 | 46 | .NOTES 47 | WUSA: Windows Update Service Application 48 | #> 49 | function Invoke-Wusa 50 | { 51 | [OutputType([Int])] 52 | [CmdletBinding()] 53 | param 54 | ( 55 | [Parameter(Mandatory = $true)] 56 | [String] 57 | $InstallFile 58 | ) 59 | 60 | Write-Verbose -Message "Installing $InstallFile..." 61 | 62 | $wusaProcess = [System.Diagnostics.Process]::Start($InstallFile, "/quiet /norestart ") 63 | 64 | Write-Verbose -Message 'Waiting for WUSA install to complete...' 65 | 66 | # Wait for 60 minutes for the process to exit 67 | if (-not $wusaProcess.WaitForExit(60 * 60 * 1000)) 68 | { 69 | throw "Installing $InstallFile timed out after 60 minutes. Exiting..." 70 | } 71 | 72 | return $wusaProcess.ExitCode 73 | } 74 | 75 | <# 76 | .SYNOPSIS 77 | Installs WMF 5.1. 78 | #> 79 | function Install-Wmf5Dot1 80 | { 81 | [CmdletBinding()] 82 | param () 83 | 84 | $downloadLocation = "$env:SystemDrive\WMF5Dot1.msu" 85 | 86 | $null = Download-Wmf5Dot1InstallFile -DownloadLocation $downloadLocation 87 | 88 | Write-Verbose -Message 'Restarting the Windows Update service (wuauserv)...' 89 | 90 | $null = Set-Service -Name 'wuauserv' -StartupType 'Manual' 91 | $null = Start-Service -Name 'wuauserv' 92 | 93 | Write-Verbose -Message 'Installing WMF 5.1...' 94 | 95 | $wusaExitCode = Invoke-Wusa -InstallFile $downloadLocation 96 | 97 | Write-Verbose -Message "Completed WMF 5.1 installation with exit code $wusaExitCode" 98 | } 99 | 100 | Export-ModuleMember -Function @( 'Install-Wmf5Dot1' ) 101 | -------------------------------------------------------------------------------- /Tests/TestHelpers/WindowsProcessTestProcess.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Threading; 3 | 4 | // This is a test process used for testing configuring running and stopping a process on a machine 5 | namespace WindowsProcessTestProcess 6 | { 7 | class Program 8 | { 9 | static void Main(string[] args) 10 | { 11 | string[] lines = { "Test line1", "Test line2", "Test line3" }; 12 | 13 | if (args.Length > 0) 14 | { 15 | string filePath = args[0]; 16 | 17 | using (StreamWriter outputFile = new StreamWriter(filePath)) 18 | { 19 | // Write to a log file so that we can see if the process ran 20 | foreach (var line in lines) 21 | { 22 | outputFile.WriteLine(line); 23 | } 24 | } 25 | } 26 | 27 | if (args.Length <= 1 || (args.Length > 1 && args[1] != "Stop Running")) 28 | { 29 | // Sleep so that the process stays running until it is killed 30 | Thread.Sleep(Timeout.Infinite); 31 | } 32 | } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /Tests/TestHelpers/WindowsProcessTestProcess.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowerShell/PSDscResources/7064eda52d939a4a3ce40e1f38756cfe6a09acfd/Tests/TestHelpers/WindowsProcessTestProcess.exe -------------------------------------------------------------------------------- /Tests/TestHelpers/WindowsProcessTestProcessSet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PowerShell/PSDscResources/7064eda52d939a4a3ce40e1f38756cfe6a09acfd/Tests/TestHelpers/WindowsProcessTestProcessSet.exe -------------------------------------------------------------------------------- /Tests/Unit/CommonResourceHelper.Tests.ps1: -------------------------------------------------------------------------------- 1 | $errorActionPreference = 'Stop' 2 | Set-StrictMode -Version 'Latest' 3 | 4 | Describe 'CommonResourceHelper Unit Tests' { 5 | BeforeAll { 6 | # Import the CommonResourceHelper module to test 7 | $testsFolderFilePath = Split-Path -Path $PSScriptRoot -Parent 8 | $moduleRootFilePath = Split-Path -Path $testsFolderFilePath -Parent 9 | $dscResourcesFolderFilePath = Join-Path -Path $moduleRootFilePath -ChildPath 'DscResources' 10 | $commonResourceHelperFilePath = Join-Path -Path $dscResourcesFolderFilePath -ChildPath 'CommonResourceHelper.psm1' 11 | Import-Module -Name $commonResourceHelperFilePath 12 | } 13 | 14 | InModuleScope 'CommonResourceHelper' { 15 | Describe 'Test-IsNanoServer' { 16 | $testComputerInfoNanoServer = @{ 17 | NanoServer = 1 18 | } 19 | 20 | $testComputerInfoServerNotNano = @{ 21 | } 22 | 23 | Context 'Computer OS type is Server and OS server level is NanoServer' { 24 | Mock -CommandName 'Test-Path' -MockWith { return $true } 25 | Mock -CommandName 'Get-ItemProperty' -MockWith { return $testComputerInfoNanoServer } 26 | It 'Should not throw' { 27 | { $null = Test-IsNanoServer } | Should -Not -Throw 28 | } 29 | 30 | It 'Should check the ServerLevels registry path' { 31 | Assert-MockCalled -CommandName 'Get-ItemProperty' -Exactly 1 -Scope 'Context' 32 | } 33 | 34 | It 'Should return true' { 35 | Test-IsNanoServer | Should -BeTrue 36 | } 37 | } 38 | 39 | Context 'Computer OS type is Server and OS server level is not NanoServer' { 40 | Mock -CommandName 'Test-Path' -MockWith { return $true } 41 | Mock -CommandName 'Get-ItemProperty' -MockWith { return $testComputerInfoServerNotNano } 42 | 43 | It 'Should not throw' { 44 | { $null = Test-IsNanoServer } | Should -Not -Throw 45 | } 46 | 47 | It 'Should check the ServerLevels registry path' { 48 | Assert-MockCalled -CommandName 'Get-ItemProperty' -Exactly 1 -Scope 'Context' 49 | } 50 | 51 | It 'Should return false' { 52 | Test-IsNanoServer | Should -BeFalse 53 | } 54 | } 55 | 56 | Context 'Computer OS type is not Server' { 57 | Mock -CommandName 'Test-Path' -MockWith { return $false } 58 | 59 | It 'Should not throw' { 60 | { $null = Test-IsNanoServer } | Should -Not -Throw 61 | } 62 | 63 | It 'Should check the ServerLevels registry path' { 64 | Assert-MockCalled -CommandName 'Test-Path' -Exactly 1 -Scope 'Context' 65 | } 66 | 67 | It 'Should return false' { 68 | Test-IsNanoServer | Should -BeFalse 69 | } 70 | } 71 | } 72 | 73 | Describe 'Test-CommandExists' { 74 | $testCommandName = 'TestCommandName' 75 | 76 | Mock -CommandName 'Get-Command' -MockWith { return $Name } 77 | 78 | Context 'Get-Command returns the command' { 79 | It 'Should not throw' { 80 | { $null = Test-CommandExists -Name $testCommandName } | Should -Not -Throw 81 | } 82 | 83 | It 'Should retrieve the command with the specified name' { 84 | $getCommandParameterFilter = { 85 | return $Name -eq $testCommandName 86 | } 87 | 88 | Assert-MockCalled -CommandName 'Get-Command' -ParameterFilter $getCommandParameterFilter -Exactly 1 -Scope 'Context' 89 | } 90 | 91 | It 'Should return true' { 92 | Test-CommandExists -Name $testCommandName | Should -BeTrue 93 | } 94 | } 95 | 96 | Context 'Get-Command returns null' { 97 | Mock -CommandName 'Get-Command' -MockWith { return $null } 98 | 99 | It 'Should not throw' { 100 | { $null = Test-CommandExists -Name $testCommandName } | Should -Not -Throw 101 | } 102 | 103 | It 'Should retrieve the command with the specified name' { 104 | $getCommandParameterFilter = { 105 | return $Name -eq $testCommandName 106 | } 107 | 108 | Assert-MockCalled -CommandName 'Get-Command' -ParameterFilter $getCommandParameterFilter -Exactly 1 -Scope 'Context' 109 | } 110 | 111 | It 'Should return false' { 112 | Test-CommandExists -Name $testCommandName | Should -BeFalse 113 | } 114 | } 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | #---------------------------------# 2 | # environment configuration # 3 | #---------------------------------# 4 | version: 2.4.{build}.0 5 | install: 6 | - git clone https://github.com/PowerShell/DscResource.Tests 7 | - ps: | 8 | $moduleName = 'PSDscResources' 9 | Import-Module "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" 10 | Invoke-AppveyorInstallTask 11 | 12 | #---------------------------------# 13 | # build configuration # 14 | #---------------------------------# 15 | 16 | build: false 17 | 18 | #---------------------------------# 19 | # test configuration # 20 | #---------------------------------# 21 | 22 | test_script: 23 | - ps: | 24 | Invoke-AppveyorTestScriptTask ` 25 | -Type 'Default' ` 26 | -CodeCoverage ` 27 | -CodeCovIo ` 28 | -DisableConsistency ` 29 | -ExcludeTag @() 30 | 31 | after_test: 32 | - ps: | 33 | Import-Module -Name "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" 34 | Invoke-AppveyorAfterTestTask ` 35 | -ResourceModuleName $moduleName 36 | 37 | #---------------------------------# 38 | # deployment configuration # 39 | #---------------------------------# 40 | 41 | deploy_script: 42 | - ps: | 43 | Invoke-AppveyorAfterTestTask 44 | --------------------------------------------------------------------------------