-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBuild.ps1
More file actions
148 lines (116 loc) · 5.3 KB
/
Build.ps1
File metadata and controls
148 lines (116 loc) · 5.3 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
$moduleName = "cMDTBuildLab"
$moduleGuid = "df45de26-88b1-4a95-98af-b798fde1424f"
$year = (Get-Date).Year
$moduleVersion = "3.0.0"
$releaseNotes = "
* Remove Windows 7/8.1/2012R2 deployments and prerequisites
* Update download URLs for MDT
* Add MDT Hotfix KB4564442 (Build: 6.3.8456.1001)
* Update ADK (v.2004)
* Download ADK installers (cMDTBuildLabPrereqs)
* Update VC++ prerequisites (VC++ 2022)
* New design for AppVeyor tests
"
$allResources = @( Get-ChildItem -Path $PSScriptRoot\src\DSCResources\*.psm1 -ErrorAction SilentlyContinue -Recurse | Sort-Object)
$allFunctions = @( Get-ChildItem -Path $PSScriptRoot\src\Public\*.ps1 -ErrorAction SilentlyContinue -Recurse | Sort-Object)
$buildDir = "C:\Projects"
$combinedModule = "$BuildDir\Build\$moduleName\$ModuleName.psm1"
$manifestFile = "$BuildDir\Build\$moduleName\$ModuleName.psd1"
[string]$dscResourcesToExport = $null
$ensureDefiniton = @"
enum Ensure
{
Present
Absent
}
"@
# Init module script
[string]$combinedResources = $ensureDefiniton
# Prepare DSC resources
Foreach ($resource in @($allResources)) {
Write-Output "Add Resource: $resource"
Try {
$resourceContent = Get-Content $resource -Raw -Encoding UTF8
$combinedResources += $resourceContent.Substring($resourceContent.IndexOf("[DscResource()]"))
if ($resourceContent -match 'class\s*(?<ClassName>\w*)[\r\t]') {
foreach ($match in $Matches.ClassName) {
[string]$dscResourcesToExport += "'$match',"
}
}
}
Catch {
throw $_
}
}
# Prepare Functions
Foreach ($function in @($allFunctions)) {
Write-Output "Add Function: $function"
Try {
$functionContent = Get-Content $function -Raw
$combinedResources += $functionContent.Substring($functionContent.IndexOf("Function"))
}
Catch {
throw $_
}
}
# Prepare Manifest
$dscResourcesToExport = $dscResourcesToExport.TrimEnd(",")
$ManifestDefinition = @"
@{
# Script module or binary module file associated with this manifest.
RootModule = '$moduleName.psm1'
DscResourcesToExport = @($dscResourcesToExport)
FunctionsToExport = @('Import-MDTModule','Invoke-ExpandArchive','Invoke-RemovePath','Invoke-TestPath','Get-ConfigurationData')
# Version number of this module.
ModuleVersion = '$moduleVersion'
# ID used to uniquely identify this module
GUID = '$moduleGuid'
# Author of this module
Author = 'Pavel Andreev'
# Company or vendor of this module
CompanyName = ''
# Copyright statement for this module
Copyright = '(c) $Year Pavel Andreev. All rights reserved.'
# Description of the functionality provided by this module
Description = 'A DSC Module to help automize deployment Windows Reference Images on MDT Server'
# Project site link
HelpInfoURI = 'https://github.com/pvs043/cMDTBuildLab/wiki'
# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.1'
# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @('cNtfsAccessControl',
@{ModuleName = 'xSmbShare'; ModuleVersion = '2.0.0.0';}
)
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{
PSData = @{
# Tags applied to this module. These help with module discovery in online galleries.
Tags = @('DesiredStateConfiguration', 'DSC', 'DSCResource', 'MDT', 'MicrosoftDeploymentToolkit', 'Deploy')
# A URL to the license for this module.
LicenseUri = 'https://github.com/pvs043/cMDTBuildLab/blob/master/LICENSE'
# A URL to the main website for this project.
ProjectUri = 'https://github.com/pvs043/cMDTBuildLab'
# A URL to an icon representing this module.
# IconUri = ''
# ReleaseNotes of this module
ReleaseNotes = '$releaseNotes'
} # End of PSData hashtable
} # End of PrivateData hashtable
# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''
}
"@
# Create Build dir
If (Test-Path -Path "$buildDir\Build") { Remove-Item -Path "$buildDir\Build" -Recurse -Force}
$null = New-Item -ItemType Directory -Path "$buildDir\Build\$moduleName"
# Build module from sources
Set-Content -Path $combinedModule -Value $combinedResources
Set-Content -Path $manifestFile -Value $ManifestDefinition
Copy-Item -Path "$PSScriptRoot\src\cMDTBuildLabPrereqs.psd1" -Destination "$BuildDir\Build\$moduleName\cMDTBuildLabPrereqs.psd1" -Force
# Add artefacts
Copy-Item -Path "$PSScriptRoot\src\Deploy" -Destination "$BuildDir\Build\$moduleName\Deploy" -Recurse -Force
Copy-Item -Path "$PSScriptRoot\src\Examples" -Destination "$BuildDir\Build\$moduleName\Examples" -Recurse -Force
Copy-Item -Path "$PSScriptRoot\src\Sources" -Destination "$BuildDir\Build\$moduleName\Sources" -Recurse -Force
Copy-Item -Path "$PSScriptRoot\src\Tests" -Destination "$BuildDir\Build\$moduleName\Tests" -Recurse -Force
Copy-Item -Path "$PSScriptRoot\README.md" -Destination "$BuildDir\Build\$moduleName\Readme.md" -Force
Copy-Item -Path "$PSScriptRoot\LICENSE" -Destination "$BuildDir\Build\$moduleName\LICENSE" -Force