mirror of
https://github.com/PowerShell/PSDscResources
synced 2026-06-21 13:45:29 +00:00
adding resources and examples for sets
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'GroupSet.schema.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '0.1.0.0'
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = 'c5e227b5-52dc-4653-b08f-6d94e06bb90b'
|
||||
|
||||
# Author of this module
|
||||
Author = 'Microsoft Corporation'
|
||||
|
||||
# Company or vendor of this module
|
||||
CompanyName = 'Microsoft Corporation'
|
||||
|
||||
# Copyright statement for this module
|
||||
Copyright = '(c) 2016 Microsoft. All rights reserved.'
|
||||
|
||||
# Description of the functionality provided by this module
|
||||
Description = 'Configures multiple Group resources with common settings but different names.'
|
||||
|
||||
# Minimum version of the Windows PowerShell engine required by this module
|
||||
PowerShellVersion = '4.0'
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
|
||||
# Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock
|
||||
$script:dscResourcesFolderFilePath = Split-Path -Path $PSScriptRoot -Parent
|
||||
$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'ResourceSetHelper.psm1'
|
||||
Import-Module -Name $script:resourceSetHelperFilePath
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A composite DSC resource to configure a set of similar Group resources.
|
||||
|
||||
.PARAMETER GroupName
|
||||
An array of the names of the groups to configure.
|
||||
|
||||
.PARAMETER Ensure
|
||||
Specifies whether or not the set of groups should exist.
|
||||
|
||||
Set this property to Present to create or modify a set of groups.
|
||||
Set this property to Absent to remove a set of groups.
|
||||
|
||||
.PARAMETER MembersToInclude
|
||||
The members that should be included in each group in the set.
|
||||
|
||||
.PARAMETER MembersToExclude
|
||||
The members that should be excluded from each group in the set.
|
||||
|
||||
.PARAMETER Credential
|
||||
The credential to resolve all groups and user accounts.
|
||||
#>
|
||||
Configuration GroupSet
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String[]]
|
||||
$GroupName,
|
||||
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
$Ensure,
|
||||
|
||||
[String[]]
|
||||
$MembersToInclude,
|
||||
|
||||
[String[]]
|
||||
$MembersToExclude,
|
||||
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[System.Management.Automation.PSCredential]
|
||||
[System.Management.Automation.Credential()]
|
||||
$Credential
|
||||
)
|
||||
|
||||
$newResourceSetConfigurationParams = @{
|
||||
ResourceName = 'Group'
|
||||
ModuleName = 'PSDscResources'
|
||||
KeyParameterName = 'GroupName'
|
||||
Parameters = $PSBoundParameters
|
||||
}
|
||||
|
||||
$configurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams
|
||||
|
||||
# This script block must be run directly in this configuration in order to resolve variables
|
||||
. $configurationScriptBlock
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'ProcessSet.schema.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '0.1.0.0'
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = '0cb71def-366f-4f3b-88a9-b9b37d266dd6'
|
||||
|
||||
# Author of this module
|
||||
Author = 'Microsoft Corporation'
|
||||
|
||||
# Company or vendor of this module
|
||||
CompanyName = 'Microsoft Corporation'
|
||||
|
||||
# Copyright statement for this module
|
||||
Copyright = '(c) 2016 Microsoft. All rights reserved.'
|
||||
|
||||
# Description of the functionality provided by this module
|
||||
Description = 'Provides a mechanism to configure and manage multiple WindowsProcess resources on a target node.'
|
||||
|
||||
# Minimum version of the Windows PowerShell engine required by this module
|
||||
PowerShellVersion = '4.0'
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
|
||||
# Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock
|
||||
$script:dscResourcesFolderFilePath = Split-Path -Path $PSScriptRoot -Parent
|
||||
$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'ResourceSetHelper.psm1'
|
||||
Import-Module -Name $script:resourceSetHelperFilePath
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A composite DSC resource to configure a set of similar WindowsProcess resources.
|
||||
No arguments can be passed into these WindowsProcess resources.
|
||||
|
||||
.PARAMETER Path
|
||||
The file paths to the executables of the processes to start or stop. Only the names of the
|
||||
files may be specified if they are all accessible through the environment path. Relative
|
||||
paths are not supported.
|
||||
|
||||
.PARAMETER Ensure
|
||||
Specifies whether or not the processes should exist.
|
||||
|
||||
To start processes, set this property to Present.
|
||||
To stop processes, set this property to Absent.
|
||||
|
||||
.PARAMETER Credential
|
||||
The credential of the user account to start the processes under.
|
||||
|
||||
.PARAMETER StandardOutputPath
|
||||
The file path to write the standard output to. Any existing file at this path
|
||||
will be overwritten.This property cannot be specified at the same time as Credential
|
||||
when running the processes as a local user.
|
||||
|
||||
.PARAMETER StandardErrorPath
|
||||
The file path to write the standard error output to. Any existing file at this path
|
||||
will be overwritten.
|
||||
|
||||
.PARAMETER StandardInputPath
|
||||
The file path to get standard input from. This property cannot be specified at the
|
||||
same time as Credential when running the processes as a local user.
|
||||
|
||||
.PARAMETER WorkingDirectory
|
||||
The file path to use as the working directory for the processes. Any existing file
|
||||
at this path will be overwritten. This property cannot be specified at the same time
|
||||
as Credential when running the processes as a local user.
|
||||
#>
|
||||
Configuration ProcessSet
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String[]]
|
||||
$Path,
|
||||
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
$Ensure,
|
||||
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[System.Management.Automation.PSCredential]
|
||||
[System.Management.Automation.Credential()]
|
||||
$Credential,
|
||||
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$StandardOutputPath,
|
||||
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$StandardErrorPath,
|
||||
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$StandardInputPath,
|
||||
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$WorkingDirectory
|
||||
)
|
||||
|
||||
$newResourceSetConfigurationParams = @{
|
||||
ResourceName = 'WindowsProcess'
|
||||
ModuleName = 'PSDscResource'
|
||||
KeyParameterName = 'Path'
|
||||
Parameters = $PSBoundParameters
|
||||
}
|
||||
|
||||
# Arguments is a key parameter in WindowsProcess resource. Adding it as a common parameter with an empty value string
|
||||
$newResourceSetConfigurationParams['Parameters']['Arguments'] = ''
|
||||
|
||||
$configurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams
|
||||
|
||||
# This script block must be run directly in this configuration in order to resolve variables
|
||||
. $configurationScriptBlock
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
# This module should not write any verbose or error messages unless a localization file for it is added
|
||||
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Builds a string of the common parameters shared across all resources in a set.
|
||||
|
||||
.PARAMETER KeyParameterName
|
||||
The name of the key parameter for the resource.
|
||||
|
||||
.PARAMETER Parameters
|
||||
The hashtable of all parameters to the resource set (PSBoundParameters).
|
||||
|
||||
.EXAMPLE
|
||||
$parameters = @{
|
||||
KeyParameter = @( 'MyKeyParameter1', 'MyKeyParameter2' )
|
||||
CommonParameter1 = 'CommonValue1'
|
||||
CommonParameter2 = 2
|
||||
}
|
||||
|
||||
New-ResourceSetCommonParameterString -KeyParameterName 'KeyParameter' -Parameters $parameters
|
||||
|
||||
OUTPUT (as string):
|
||||
CommonParameter1 = "CommonValue1"`r`nCommonParameter2 = $CommonParameter2
|
||||
#>
|
||||
function New-ResourceSetCommonParameterString
|
||||
{
|
||||
[OutputType([String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$KeyParameterName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[Hashtable]
|
||||
$Parameters
|
||||
)
|
||||
|
||||
$stringBuilder = New-Object -TypeName 'System.Text.StringBuilder'
|
||||
|
||||
foreach ($parameterName in $Parameters.Keys)
|
||||
{
|
||||
# All composite resources have an extra parameter 'InstanceName'
|
||||
if ($parameterName -ine $KeyParameterName -and $parameterName -ine 'InstanceName')
|
||||
{
|
||||
$parameterValue = $Parameters[$parameterName]
|
||||
|
||||
if ($null -ne $parameterValue)
|
||||
{
|
||||
if ($parameterValue -is [String])
|
||||
{
|
||||
$null = $stringBuilder.AppendFormat('{0} = "{1}"', $parameterName, $parameterValue)
|
||||
}
|
||||
else
|
||||
{
|
||||
$null = $stringBuilder.Append($parameterName + ' = $' + $parameterName)
|
||||
}
|
||||
|
||||
$null = $stringBuilder.AppendLine()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $stringBuilder.ToString()
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates a string representing a configuration script for a set of resources.
|
||||
|
||||
.PARAMETER ResourceName
|
||||
The name of the resource to create a set of.
|
||||
|
||||
.PARAMETER ModuleName
|
||||
The name of the module to import the resource from.
|
||||
|
||||
.PARAMETER KeyParameterName
|
||||
The name of the key parameter that will differentiate each resource.
|
||||
|
||||
.PARAMETER KeyParameterValues
|
||||
An array of the values of the key parameter that will differentiate each resource.
|
||||
|
||||
.PARAMETER CommonParameterString
|
||||
A string representing the common parameters for each resource.
|
||||
Can be retrieved from New-ResourceSetCommonParameterString.
|
||||
|
||||
.EXAMPLE
|
||||
New-ResourceSetConfigurationString `
|
||||
-ResourceName 'WindowsFeature' `
|
||||
-ModuleName 'PSDscResources' `
|
||||
-KeyParameterName 'Name' `
|
||||
-KeyParameterValues @( 'Telnet-Client', 'Web-Server' ) `
|
||||
-CommonParameterString 'Ensure = "Present"`r`nIncludeAllSubFeature = $true'
|
||||
|
||||
OUTPUT (as a String):
|
||||
Import-Module -Name WindowsFeature -ModuleName PSDscResources
|
||||
|
||||
WindowsFeature Resource0
|
||||
{
|
||||
Name = "Telnet-Client"
|
||||
Ensure = "Present"
|
||||
IncludeAllSubFeature = $true
|
||||
}
|
||||
|
||||
WindowsFeature Resource1
|
||||
{
|
||||
Name = "Web-Server"
|
||||
Ensure = "Present"
|
||||
IncludeAllSubFeature = $true
|
||||
}
|
||||
#>
|
||||
function New-ResourceSetConfigurationString
|
||||
{
|
||||
[OutputType([String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$ResourceName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$ModuleName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$KeyParameterName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String[]]
|
||||
$KeyParameterValues,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$CommonParameterString
|
||||
)
|
||||
|
||||
$stringBuilder = New-Object -TypeName 'System.Text.StringBuilder'
|
||||
|
||||
$null = $stringBuilder.AppendFormat('Import-DscResource -Name {0} -ModuleName {1}', $ResourceName, $ModuleName)
|
||||
$null = $stringBuilder.AppendLine()
|
||||
|
||||
$resourceCount = 0
|
||||
foreach ($keyParameterValue in $KeyParameterValues)
|
||||
{
|
||||
$null = $stringBuilder.AppendFormat('{0} Resource{1}', $ResourceName, $resourceCount)
|
||||
$null = $stringBuilder.AppendLine()
|
||||
$null = $stringBuilder.AppendLine('{')
|
||||
$null = $stringBuilder.AppendFormat($KeyParameterName + ' = "{0}"', $keyParameterValue)
|
||||
$null = $stringBuilder.AppendLine()
|
||||
$null = $stringBuilder.Append($CommonParameterString)
|
||||
$null = $stringBuilder.AppendLine('}')
|
||||
|
||||
$resourceCount++
|
||||
}
|
||||
|
||||
return $stringBuilder.ToString()
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates a configuration script block for a set of resources.
|
||||
|
||||
.PARAMETER ResourceName
|
||||
The name of the resource to create a set of.
|
||||
|
||||
.PARAMETER ModuleName
|
||||
The name of the module to import the resource from.
|
||||
|
||||
.PARAMETER KeyParameterName
|
||||
The name of the key parameter that will differentiate each resource.
|
||||
|
||||
.PARAMETER Parameters
|
||||
The hashtable of all parameters to the resource set (PSBoundParameters).
|
||||
|
||||
.EXAMPLE
|
||||
# From the GroupSet composite resource
|
||||
|
||||
$newResourceSetConfigurationParams = @{
|
||||
ResourceName = xGroup'
|
||||
ModuleName = 'PSDscResource'
|
||||
KeyParameterName = 'GroupName'
|
||||
CommonParameterNames = @( 'Ensure', 'MembersToInclude', 'MembersToExclude', 'Credential' )
|
||||
Parameters = $PSBoundParameters
|
||||
}
|
||||
|
||||
$configurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams
|
||||
|
||||
.NOTES
|
||||
Only allows one key parameter to be defined for each node.
|
||||
For resources with multiple key parameters, only one key can be different for each resource.
|
||||
See ProcessSet for an example of a resource set with two key parameters.
|
||||
#>
|
||||
function New-ResourceSetConfigurationScriptBlock
|
||||
{
|
||||
[OutputType([ScriptBlock])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$ResourceName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$ModuleName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$KeyParameterName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[Hashtable]
|
||||
$Parameters
|
||||
)
|
||||
|
||||
$commonParameterString = New-ResourceSetCommonParameterString -KeyParameterName $KeyParameterName -Parameters $Parameters
|
||||
|
||||
$newResourceSetConfigurationStringParams = @{
|
||||
ResourceName = $ResourceName
|
||||
ModuleName = $ModuleName
|
||||
KeyParameterName = $KeyParameterName
|
||||
KeyParameterValues = $Parameters[$KeyParameterName]
|
||||
CommonParameterString = $commonParameterString
|
||||
}
|
||||
|
||||
$resourceString = New-ResourceSetConfigurationString @newResourceSetConfigurationStringParams
|
||||
|
||||
return [ScriptBlock]::Create($resourceString)
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function @( 'New-ResourceSetConfigurationScriptBlock' )
|
||||
@@ -0,0 +1,27 @@
|
||||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'ServiceSet.schema.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '0.1.0.0'
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = 'c3ac5e1f-c1fd-4ed0-be24-b271c7062484'
|
||||
|
||||
# Author of this module
|
||||
Author = 'Microsoft Corporation'
|
||||
|
||||
# Company or vendor of this module
|
||||
CompanyName = 'Microsoft Corporation'
|
||||
|
||||
# Copyright statement for this module
|
||||
Copyright = '(c) 2016 Microsoft. All rights reserved.'
|
||||
|
||||
# Description of the functionality provided by this module
|
||||
Description = 'Allows starting, stopping and change in state or account type for a group of services.'
|
||||
|
||||
# Minimum version of the Windows PowerShell engine required by this module
|
||||
PowerShellVersion = '4.0'
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
|
||||
# Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock
|
||||
$script:dscResourcesFolderFilePath = Split-Path -Path $PSScriptRoot -Parent
|
||||
$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'ResourceSetHelper.psm1'
|
||||
Import-Module -Name $script:resourceSetHelperFilePath
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A composite DSC resource to configure a set of similar Service resources.
|
||||
|
||||
.PARAMETER Name
|
||||
An array of the names of the services to configure.
|
||||
|
||||
.PARAMETER Ensure
|
||||
Specifies whether or not the set of services should exist.
|
||||
|
||||
Set this property to Present to modify a set of services.
|
||||
Set this property to Absent to remove a set of services.
|
||||
|
||||
.PARAMETER StartupType
|
||||
The startup type each service in the set should have.
|
||||
|
||||
.PARAMETER BuiltInAccount
|
||||
The built-in account each service in the set should start under.
|
||||
|
||||
Cannot be specified at the same time as Credential.
|
||||
|
||||
The user account specified by this property must have access to the service
|
||||
executable paths in order to start the services.
|
||||
|
||||
.PARAMETER State
|
||||
The state each service in the set should be in.
|
||||
From the default value defined in Service, the default will be Running.
|
||||
|
||||
.PARAMETER Credential
|
||||
The credential of the user account each service in the set should start under.
|
||||
|
||||
Cannot be specified at the same time as BuiltInAccount.
|
||||
|
||||
The user specified by this credential will automatically be granted the Log on as a Service
|
||||
right. The user account specified by this property must have access to the service
|
||||
executable paths in order to start the services.
|
||||
#>
|
||||
Configuration ServiceSet
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String[]]
|
||||
$Name,
|
||||
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
$Ensure,
|
||||
|
||||
[ValidateSet('Automatic', 'Manual', 'Disabled')]
|
||||
[String]
|
||||
$StartupType,
|
||||
|
||||
[ValidateSet('LocalSystem', 'LocalService', 'NetworkService')]
|
||||
[String]
|
||||
$BuiltInAccount,
|
||||
|
||||
[ValidateSet('Running', 'Stopped', 'Ignore')]
|
||||
[String]
|
||||
$State,
|
||||
|
||||
[ValidateNotNull()]
|
||||
[System.Management.Automation.PSCredential]
|
||||
[System.Management.Automation.Credential()]
|
||||
$Credential
|
||||
)
|
||||
|
||||
$newResourceSetConfigurationParams = @{
|
||||
ResourceName = 'Service'
|
||||
ModuleName = 'PSDscResource'
|
||||
KeyParameterName = 'Name'
|
||||
Parameters = $PSBoundParameters
|
||||
}
|
||||
|
||||
$configurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams
|
||||
|
||||
# This script block must be run directly in this configuration in order to resolve variables
|
||||
. $configurationScriptBlock
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'WindowsFeatureSet.schema.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '0.1.0.0'
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = 'b18a27e2-f710-4a4a-92b8-6cd076970eb2'
|
||||
|
||||
# Author of this module
|
||||
Author = 'Microsoft Corporation'
|
||||
|
||||
# Company or vendor of this module
|
||||
CompanyName = 'Microsoft Corporation'
|
||||
|
||||
# Copyright statement for this module
|
||||
Copyright = '(c) 2016 Microsoft. All rights reserved.'
|
||||
|
||||
# Description of the functionality provided by this module
|
||||
Description = 'Provides a mechanism to configure and manage multiple WindowsFeature resources on a target node.'
|
||||
|
||||
# Minimum version of the Windows PowerShell engine required by this module
|
||||
PowerShellVersion = '4.0'
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
|
||||
# Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock
|
||||
$script:dscResourcesFolderFilePath = Split-Path -Path $PSScriptRoot -Parent
|
||||
$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'ResourceSetHelper.psm1'
|
||||
Import-Module -Name $script:resourceSetHelperFilePath
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A composite DSC resource to configure a set of similar WindowsFeature resources.
|
||||
|
||||
.PARAMETER Name
|
||||
The name of the roles or features to install or uninstall.
|
||||
|
||||
.PARAMETER Ensure
|
||||
Specifies whether the roles or features should be installed or uninstalled.
|
||||
|
||||
To install the features, set this property to Present.
|
||||
To uninstall the features, set this property to Absent.
|
||||
|
||||
.PARAMETER IncludeAllSubFeature
|
||||
Specifies whether or not all subfeatures should be installed or uninstalled alongside the specified roles or features.
|
||||
|
||||
If this property is true and Ensure is set to Present, all subfeatures will be installed.
|
||||
If this property is false and Ensure is set to Present, subfeatures will not be installed or uninstalled.
|
||||
If Ensure is set to Absent, all subfeatures will be uninstalled.
|
||||
|
||||
.PARAMETER Credential
|
||||
The credential of the user account under which to install or uninstall the roles or features.
|
||||
|
||||
.PARAMETER LogPath
|
||||
The custom file path to which to log this operation.
|
||||
If not passed in, the default log path will be used (%windir%\logs\ServerManager.log).
|
||||
#>
|
||||
Configuration WindowsFeatureSet
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String[]]
|
||||
$Name,
|
||||
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
$Ensure,
|
||||
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$Source,
|
||||
|
||||
[Boolean]
|
||||
$IncludeAllSubFeature,
|
||||
|
||||
[ValidateNotNull()]
|
||||
[System.Management.Automation.PSCredential]
|
||||
[System.Management.Automation.Credential()]
|
||||
$Credential,
|
||||
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$LogPath
|
||||
)
|
||||
|
||||
$newResourceSetConfigurationParams = @{
|
||||
ResourceName = 'WindowsFeature'
|
||||
ModuleName = 'PSDscResource'
|
||||
KeyParameterName = 'Name'
|
||||
Parameters = $PSBoundParameters
|
||||
}
|
||||
|
||||
$configurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams
|
||||
|
||||
# This script block must be run directly in this configuration in order to resolve variables
|
||||
. $configurationScriptBlock
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'WindowsOptionalFeatureSet.schema.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '0.1.0.0'
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = 'a88c1458-db46-402c-947b-7d43ab57e27a'
|
||||
|
||||
# Author of this module
|
||||
Author = 'Microsoft Corporation'
|
||||
|
||||
# Company or vendor of this module
|
||||
CompanyName = 'Microsoft Corporation'
|
||||
|
||||
# Copyright statement for this module
|
||||
Copyright = '(c) 2016 Microsoft. All rights reserved.'
|
||||
|
||||
# Description of the functionality provided by this module
|
||||
Description = 'Provides a mechanism to configure and manage multiple WindowsOptionalFeature resources on a target node.'
|
||||
|
||||
# Minimum version of the Windows PowerShell engine required by this module
|
||||
PowerShellVersion = '4.0'
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
|
||||
# Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock
|
||||
$script:dscResourcesFolderFilePath = Split-Path -Path $PSScriptRoot -Parent
|
||||
$script:resourceSetHelperFilePath = Join-Path -Path $script:dscResourcesFolderFilePath -ChildPath 'ResourceSetHelper.psm1'
|
||||
Import-Module -Name $script:resourceSetHelperFilePath
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A composite DSC resource to configure a set of similar WindowsOptionalFeature resources.
|
||||
|
||||
.PARAMETER Name
|
||||
The names of the Windows optional features to enable or disable.
|
||||
|
||||
.PARAMETER Ensure
|
||||
Specifies whether the features should be enabled or disabled.
|
||||
|
||||
To enable a set of features, set this property to Present.
|
||||
To disable a set of features, set this property to Absent.
|
||||
|
||||
.PARAMETER RemoveFilesOnDisable
|
||||
Specifies whether or not to remove all files associated with the features when they are
|
||||
disabled.
|
||||
|
||||
.PARAMETER NoWindowsUpdateCheck
|
||||
Specifies whether or not DISM should contact Windows Update (WU) when searching for the
|
||||
source files to restore Windows optional features on an online image.
|
||||
|
||||
.PARAMETER LogPath
|
||||
The file path to which to log the opertation.
|
||||
|
||||
.PARAMETER LogLevel
|
||||
The level of detail to include in the log.
|
||||
#>
|
||||
Configuration WindowsOptionalFeatureSet
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String[]]
|
||||
$Name,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
$Ensure,
|
||||
|
||||
[Boolean]
|
||||
$RemoveFilesOnDisable,
|
||||
|
||||
[Boolean]
|
||||
$NoWindowsUpdateCheck,
|
||||
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$LogPath,
|
||||
|
||||
[ValidateSet('ErrorsOnly', 'ErrorsAndWarning', 'ErrorsAndWarningAndInformation')]
|
||||
[String]
|
||||
$LogLevel
|
||||
)
|
||||
|
||||
$newResourceSetConfigurationParams = @{
|
||||
ResourceName = 'WindowsOptionalFeature'
|
||||
ModuleName = 'PSDscResource'
|
||||
KeyParameterName = 'Name'
|
||||
Parameters = $PSBoundParameters
|
||||
}
|
||||
|
||||
$configurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams
|
||||
|
||||
# This script block must be run directly in this configuration in order to resolve variables
|
||||
. $configurationScriptBlock
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
If the groups named GroupName1 and Administrators do not exist, creates the groups named
|
||||
GroupName1 and Administrators and adds the users with the usernames Username1 and Username2
|
||||
to both groups.
|
||||
|
||||
If the groups named GroupName1 and Administrators already exist, adds the users with the
|
||||
usernames Username1 and Username2 to both groups.
|
||||
#>
|
||||
Configuration Sample_GroupSet_AddMembers
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param ()
|
||||
|
||||
Import-DscResource -ModuleName 'PSDscResources'
|
||||
|
||||
GroupSet GroupSet
|
||||
{
|
||||
GroupName = @( 'Administrators', 'GroupName1' )
|
||||
Ensure = 'Present'
|
||||
MembersToInclude = @( 'Username1', 'Username2' )
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Starts the processes with the executables at the file paths C:\Windows\cmd.exe and
|
||||
C:\TestPath\TestProcess.exe with no arguments.
|
||||
#>
|
||||
Configuration Sample_ProcessSet_Start
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param ()
|
||||
|
||||
Import-DscResource -ModuleName 'PSDscResources'
|
||||
|
||||
ProcessSet ProcessSet1
|
||||
{
|
||||
Path = @( 'C:\Windows\System32\cmd.exe', 'C:\TestPath\TestProcess.exe' )
|
||||
Ensure = 'Present'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Stops the processes with the executables at the file paths C:\Windows\cmd.exe and
|
||||
C:\TestPath\TestProcess.exe with no arguments and logs any output to the path
|
||||
C:\OutputPath\Output.log.
|
||||
#>
|
||||
Configuration Sample_ProcessSet_Stop
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param ()
|
||||
|
||||
Import-DscResource -ModuleName 'PSDscResources'
|
||||
|
||||
ProcessSet ProcessSet1
|
||||
{
|
||||
Path = @( 'C:\Windows\System32\cmd.exe', 'C:\TestPath\TestProcess.exe' )
|
||||
Ensure = 'Absent'
|
||||
StandardOutputPath = 'C:\OutputPath\Output.log'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sets the Secure Socket Tunneling Protocol and DHCP Client services to run under the
|
||||
built-in account LocalService.
|
||||
#>
|
||||
Configuration ServiceSetBuiltInAccountExample
|
||||
{
|
||||
Import-DscResource -ModuleName 'PSDscResources'
|
||||
|
||||
ServiceSet ServiceSet1
|
||||
{
|
||||
Name = @( 'SstpSvc', 'Dhcp' )
|
||||
Ensure = 'Present'
|
||||
BuiltInAccount = 'LocalService'
|
||||
State = 'Ignore'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Ensures that the DHCP Client and Windows Firewall services are running.
|
||||
#>
|
||||
Configuration ServiceSetStartExample
|
||||
{
|
||||
Import-DscResource -ModuleName 'PSDscResources'
|
||||
|
||||
ServiceSet ServiceSet1
|
||||
{
|
||||
Name = @( 'Dhcp', 'MpsSvc' )
|
||||
Ensure = 'Present'
|
||||
State = 'Running'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
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
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param ()
|
||||
|
||||
Import-DscResource -ModuleName 'PSDscResources'
|
||||
|
||||
WindowsFeatureSet WindowsFeatureSet1
|
||||
{
|
||||
Name = @( 'Telnet-Client', 'RSAT-File-Services' )
|
||||
Ensure = 'Present'
|
||||
IncludeAllSubFeature = $true
|
||||
LogPath = 'C:\LogPath\Log.log'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
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
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param ()
|
||||
|
||||
Import-DscResource -ModuleName 'PSDscResources'
|
||||
|
||||
WindowsFeatureSet WindowsFeatureSet1
|
||||
{
|
||||
Name = @( 'Telnet-Client', 'RSAT-File-Services' )
|
||||
Ensure = 'Absent'
|
||||
IncludeAllSubFeature = $true
|
||||
LogPath = 'C:\LogPath\Log.log'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Disables the Windows optional features TelnetClient and LegacyComponents and removes all
|
||||
files associated with these features.
|
||||
#>
|
||||
Configuration WindowsOptionalFeatureSet_Disable
|
||||
{
|
||||
Import-DscResource -ModuleName 'PSDscResources'
|
||||
|
||||
WindowsOptionalFeatureSet WindowsOptionalFeatureSet1
|
||||
{
|
||||
Name = @('TelnetClient', 'LegacyComponents')
|
||||
Ensure = 'Absent'
|
||||
RemoveFilesOnDisable = $true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Enables the Windows optional features MicrosoftWindowsPowerShellV2 and
|
||||
Internet-Explorer-Optional-amd64 and outputs a log of the operations to a file at the path
|
||||
'C:\LogPath\Log.txt'.
|
||||
#>
|
||||
Configuration WindowsOptionalFeatureSet_Enable
|
||||
{
|
||||
Import-DscResource -ModuleName 'PSDscResources'
|
||||
|
||||
WindowsOptionalFeatureSet WindowsOptionalFeatureSet1
|
||||
{
|
||||
Name = @('MicrosoftWindowsPowerShellV2', 'Internet-Explorer-Optional-amd64')
|
||||
Ensure = 'Present'
|
||||
LogPath = 'C:\LogPath\Log.txt'
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user