diff --git a/.MetaTestOptIn.json b/.MetaTestOptIn.json index 7f445ce..ba96ff4 100644 --- a/.MetaTestOptIn.json +++ b/.MetaTestOptIn.json @@ -1,5 +1,6 @@ [ "Common Tests - Validate Module Files", "Common Tests - Validate Script Files", + "Common Tests - Validate Example Files", "Common Tests - Relative Path Length" ] diff --git a/Examples/Sample_MsiPackage_UnstallPackageFromHttps.ps1 b/Examples/Sample_MsiPackage_UninstallPackageFromHttps.ps1 similarity index 100% rename from Examples/Sample_MsiPackage_UnstallPackageFromHttps.ps1 rename to Examples/Sample_MsiPackage_UninstallPackageFromHttps.ps1 diff --git a/Examples/Sample_Script.ps1 b/Examples/Sample_Script.ps1 index e086cf7..013d2bc 100644 --- a/Examples/Sample_Script.ps1 +++ b/Examples/Sample_Script.ps1 @@ -8,7 +8,7 @@ .PARAMETER FileContent The content to set for the new file. #> -Configuration ScriptExample { +Configuration Sample_Script { [CmdletBinding()] param ( diff --git a/Examples/Sample_ServiceSet_BuiltInAccount.ps1 b/Examples/Sample_ServiceSet_BuiltInAccount.ps1 index 79c7820..c614dc3 100644 --- a/Examples/Sample_ServiceSet_BuiltInAccount.ps1 +++ b/Examples/Sample_ServiceSet_BuiltInAccount.ps1 @@ -3,7 +3,7 @@ Sets the Secure Socket Tunneling Protocol and DHCP Client services to run under the built-in account LocalService. #> -Configuration ServiceSetBuiltInAccountExample +Configuration Sample_ServiceSet_BuiltInAccount { Import-DscResource -ModuleName 'PSDscResources' diff --git a/Examples/Sample_ServiceSet_StartServices.ps1 b/Examples/Sample_ServiceSet_StartServices.ps1 index 1ac00dd..08c932b 100644 --- a/Examples/Sample_ServiceSet_StartServices.ps1 +++ b/Examples/Sample_ServiceSet_StartServices.ps1 @@ -2,7 +2,7 @@ .SYNOPSIS Ensures that the DHCP Client and Windows Firewall services are running. #> -Configuration ServiceSetStartExample +Configuration Sample_ServiceSet_StartServices { Import-DscResource -ModuleName 'PSDscResources' diff --git a/Examples/Sample_User_CreateUser.ps1 b/Examples/Sample_User_CreateUser.ps1 index fc75587..43fdf60 100644 --- a/Examples/Sample_User_CreateUser.ps1 +++ b/Examples/Sample_User_CreateUser.ps1 @@ -1,16 +1,22 @@ -Configuration UserExample +Configuration Sample_User_CreateUser { - param ( + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullorEmpty()] [System.Management.Automation.PSCredential] - $PasswordCredential + $Credential ) Import-DscResource -ModuleName PSDscResources - User UserExample + Node localhost { - Ensure = 'Present' # To ensure the user account does not exist, set Ensure to "Absent" - UserName = 'SomeUserName' - Password = $PasswordCredential # This needs to be a credential object + User UserExample + { + Ensure = 'Present' # To ensure the user account does not exist, set Ensure to "Absent" + UserName = 'SomeUserName' + Password = $Credential # This needs to be a credential object + } } } diff --git a/Examples/Sample_User_Generic.ps1 b/Examples/Sample_User_Generic.ps1 index bd44a8d..134a510 100644 --- a/Examples/Sample_User_Generic.ps1 +++ b/Examples/Sample_User_Generic.ps1 @@ -1,10 +1,3 @@ -param -( - [Parameter(Mandatory)] - [System.String] - $ConfigurationName -) - <# Create a custom configuration by passing in whatever values you need. $Password is the only param that is @@ -14,28 +7,28 @@ param are optional. #> -Configuration $ConfigurationName +Configuration Sample_User_Generic { - param - ( + param + ( [System.String] $UserName = 'Test UserName', - + [System.String] $Description = 'Test Description', - + [System.String] $FullName = 'Test Full Name', - + [ValidateSet('Present', 'Absent')] [System.String] $Ensure = 'Present', - + [Parameter(Mandatory = $true)] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $Password, - + [System.Boolean] $Disabled = $false, @@ -48,9 +41,9 @@ Configuration $ConfigurationName [System.Boolean] $PasswordChangeNotAllowed = $false ) - + Import-DscResource -ModuleName 'PSDscResources' - + Node Localhost { User UserResource1 diff --git a/Examples/Sample_WindowsFeature.ps1 b/Examples/Sample_WindowsFeature.ps1 index db23f46..4e6ad0c 100644 --- a/Examples/Sample_WindowsFeature.ps1 +++ b/Examples/Sample_WindowsFeature.ps1 @@ -30,7 +30,7 @@ in this configuration file currently. #> -Configuration 'Install_Feature_Telnet_Client' +Configuration Sample_WindowsFeature { param ( diff --git a/Examples/Sample_WindowsFeatureSet_Install.ps1 b/Examples/Sample_WindowsFeatureSet_Install.ps1 index 48aeb95..6653bcc 100644 --- a/Examples/Sample_WindowsFeatureSet_Install.ps1 +++ b/Examples/Sample_WindowsFeatureSet_Install.ps1 @@ -3,7 +3,7 @@ Installs the TelnetClient and RSAT-File-Services Windows features, including all their subfeatures. Logs the operation to the file at 'C:\LogPath\Log.log'. #> -Configuration WindowsFeatureSetExample_Install +Configuration Sample_WindowsFeatureSet_Install { [CmdletBinding()] param () diff --git a/Examples/Sample_WindowsFeatureSet_Uninstall.ps1 b/Examples/Sample_WindowsFeatureSet_Uninstall.ps1 index eb8ecdf..45261bf 100644 --- a/Examples/Sample_WindowsFeatureSet_Uninstall.ps1 +++ b/Examples/Sample_WindowsFeatureSet_Uninstall.ps1 @@ -3,7 +3,7 @@ Uninstalls the TelnetClient and RSAT-File-Services Windows features, including all their subfeatures. Logs the operation to the file at 'C:\LogPath\Log.log'. #> -Configuration WindowsFeatureSetExample_Install +Configuration Sample_WindowsFeatureSet_Uninstall { [CmdletBinding()] param () diff --git a/Examples/Sample_WindowsOptionalFeature.ps1 b/Examples/Sample_WindowsOptionalFeature.ps1 index 151ba55..8abdc19 100644 --- a/Examples/Sample_WindowsOptionalFeature.ps1 +++ b/Examples/Sample_WindowsOptionalFeature.ps1 @@ -17,22 +17,25 @@ Configuration Sample_WindowsOptionalFeature param ( [Parameter (Mandatory = $true)] + [ValidateNotNullOrEmpty()] [String] $FeatureName, [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] [String] $LogPath ) Import-DscResource -ModuleName 'PSDscResources' - WindowsOptionalFeature TelnetClient + Node localhost { - Name = $FeatureName - Ensure = 'Present' - LogPath = $LogPath + WindowsOptionalFeature FeatureExample + { + Name = $FeatureName + Ensure = 'Present' + LogPath = $LogPath + } } } - -Sample_WindowsOptionalFeature diff --git a/Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1 b/Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1 index ea8eb61..dc8accc 100644 --- a/Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1 +++ b/Examples/Sample_WindowsOptionalFeatureSet_Disable.ps1 @@ -3,7 +3,7 @@ Disables the Windows optional features TelnetClient and LegacyComponents and removes all files associated with these features. #> -Configuration WindowsOptionalFeatureSet_Disable +Configuration Sample_WindowsOptionalFeatureSet_Disable { Import-DscResource -ModuleName 'PSDscResources' diff --git a/Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1 b/Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1 index 16fb179..68d9535 100644 --- a/Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1 +++ b/Examples/Sample_WindowsOptionalFeatureSet_Enable.ps1 @@ -4,7 +4,7 @@ Internet-Explorer-Optional-amd64 and outputs a log of the operations to a file at the path 'C:\LogPath\Log.txt'. #> -Configuration WindowsOptionalFeatureSet_Enable +Configuration Sample_WindowsOptionalFeatureSet_Enable { Import-DscResource -ModuleName 'PSDscResources' diff --git a/Examples/Sample_WindowsPackageCab.ps1 b/Examples/Sample_WindowsPackageCab.ps1 index 656a4bf..80a2eea 100644 --- a/Examples/Sample_WindowsPackageCab.ps1 +++ b/Examples/Sample_WindowsPackageCab.ps1 @@ -37,13 +37,14 @@ Configuration Sample_WindowsPackageCab Import-DscResource -ModuleName 'PSDscResources' - WindowsPackageCab WindowsPackageCab1 + Node localhost { - Name = $Name - Ensure = 'Present' - SourcePath = $SourcePath - LogPath = $LogPath + WindowsPackageCab WindowsPackageCab1 + { + Name = $Name + Ensure = 'Present' + SourcePath = $SourcePath + LogPath = $LogPath + } } } - -Sample_WindowsPackageCab diff --git a/Tests/Unit/ResourceSetHelper.Tests.ps1 b/Tests/Unit/ResourceSetHelper.Tests.ps1 index 1e175dd..c4e7ca2 100644 --- a/Tests/Unit/ResourceSetHelper.Tests.ps1 +++ b/Tests/Unit/ResourceSetHelper.Tests.ps1 @@ -4,10 +4,11 @@ param () $errorActionPreference = 'Stop' Set-StrictMode -Version 'Latest' +$resourceSetHelperName = 'ResourceSetHelper' $script:testsFolderFilePath = Split-Path -Path $PSScriptRoot -Parent $script:moduleRootFilePath = Split-Path -Path $script:testsFolderFilePath -Parent $script:dscResourcesFolderFilePath = Join-Path -Path $script:moduleRootFilePath -ChildPath 'DscResources' -$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'ResourceSetHelper.psm1' +$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath ($resourceSetHelperName + '.psm1') Import-Module -Name $script:resourceSetHelperFilePath InModuleScope 'ResourceSetHelper' {