-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew-DscCompositeResource.ps1
71 lines (55 loc) · 2.45 KB
/
New-DscCompositeResource.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function New-DscCompositeResource {
<#
.SYNOPSIS
Provides a quick way to create the directory structure for a composite resource
.DESCRIPTION
Given a module and resource name, the function will create the skeleton folder structure and manifest files
necessary for the use of composite resources
.PARAMETER ModuleName
Name of the new base module folder being created under C:\Program Files\WindowsPowerShell\Modules
.PARAMETER ResourceName
Name of the composite resource being created. Affects the directory structure and file names.
.INPUTS
None
.OUTPUTS
"C:\Program Files\WindowsPowerShell\Modules\$ModuleName"
"$ModulePath\DSCResources"
"$ModulePath\DSCResources\$ResourceName"
"$ModulePath\$ModuleName.psd1"
"$ResourcePath\$ResourceName.psd1"
"$ResourcePath\$ResourceName.schema.psm1"
.NOTES
Version: 1.0
Author: Joshua Barton (@foobartn)
Creation Date: 11.9.2016
Purpose/Change: Initial script development
.EXAMPLE
Create a new module named MyDscResources
Create a new composite resource under that module named MyCompositeResource
New-DscCompositeResource -ModuleName MyDscResources -ResourceName MyCompositeResource
#>
param (
# Name of module folder to create
[Parameter(Mandatory=$true)]
[string]
$ModuleName,
# Name of composite resource to create
[Parameter(Mandatory=$true)]
[string]
$ResourceName
)
$ModulePath = "C:\Program Files\WindowsPowerShell\Modules\$ModuleName"
$ResourcePath = "$ModulePath\DSCResources\$ResourceName"
$ResourceSchemaPath = "$ResourcePath\$ResourceName.schema.psm1"
$DscResourcePath = "$ModulePath\DSCResources"
# Create Directory Structure
New-Item -Path @($ModulePath,$DscResourcePath,$ResourcePath) -ItemType Directory
# Add Base Module Manifest
New-ModuleManifest -RootModule $ModuleName –Path "$ModulePath\$ModuleName.psd1"
# Add Composite Resource Files
New-Item –Path $ResourceSchemaPath -ItemType File
New-ModuleManifest -RootModule "$ResourceName.schema.psm1" –Path "$ResourcePath\$ResourceName.psd1"
# Add Base Content to Resource
Add-Content -Path $ResourceSchemaPath -Value "configuration $ResourceName {"
Add-Content -Path $ResourceSchemaPath -Value "}"
}