-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathBuild-Module.ps1
138 lines (115 loc) · 6.84 KB
/
Build-Module.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
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
param (
# A CalVer string if you need to manually override the default yyyy.M.d version string.
[string]$CalVer
)
if (Get-Module -Name 'PSPublishModule' -ListAvailable) {
Write-Information 'PSPublishModule is installed.'
} else {
Write-Information 'PSPublishModule is not installed. Attempting installation.'
try {
Install-Module -Name Pester -AllowClobber -Scope CurrentUser -SkipPublisherCheck -Force
Install-Module -Name PSPublishModule -AllowClobber -Scope CurrentUser -Force
}
catch {
Write-Error 'PSPublishModule installation failed.'
}
}
Update-Module -Name PSPublishModule
Import-Module -Name PSPublishModule -Force
Build-Module -ModuleName 'Locksmith' {
# Usual defaults as per standard module
$Manifest = [ordered] @{
ModuleVersion = if ($Calver) {$CalVer} else {(Get-Date -Format yyyy.M.d)}
CompatiblePSEditions = @('Desktop', 'Core')
GUID = 'b1325b42-8dc4-4f17-aa1f-dcb5984ca14a'
Author = 'Jake Hildreth'
Copyright = "(c) 2022 - $((Get-Date).Year). All rights reserved."
Description = 'A small tool to find and fix common misconfigurations in Active Directory Certificate Services.'
ProjectUri = 'https://github.com/TrimarcJake/Locksmith'
IconUri = 'https://raw.githubusercontent.com/TrimarcJake/Locksmith/main/Images/locksmith.ico'
PowerShellVersion = '5.1'
Tags = @('Windows', 'Locksmith', 'CA', 'PKI', 'ActiveDirectory', 'CertificateServices','ADCS')
}
New-ConfigurationManifest @Manifest
# See [PR26](https://github.com/EvotecIT/PSPublishModule/pull/26) for notes about using placeholders and
# built-in placeholders for common module metadata.
# New-ConfigurationPlaceHolder -CustomReplacement @(
# @{ Find = '{CustomName}'; Replace = 'SpecialCase' }
# @{ Find = '{CustomVersion}'; Replace = '1.0.0' }
# )
# Add standard module dependencies (directly, but can be used with loop as well)
#New-ConfigurationModule -Type RequiredModule -Name 'PSSharedGoods' -Guid 'Auto' -Version 'Latest'
# Add external module dependencies, using loop for simplicity
# those modules are not available in PowerShellGallery so user has to have them installed
$ExternalModules = @(
# Required RSAT AD module
'ActiveDirectory'
'ServerManager'
# those modules are builtin in PowerShell so no need to install them
# could as well be ignored with New-ConfigurationModuleSkip
'Microsoft.PowerShell.Utility'
'Microsoft.PowerShell.LocalAccounts'
'Microsoft.PowerShell.Management'
'Microsoft.PowerShell.Security'
'CimCmdlets'
'Dism'
)
foreach ($Module in $ExternalModules) {
New-ConfigurationModule -Type ExternalModule -Name $Module
}
# Ignore missing modules or cmdlets during build process
New-ConfigurationModuleSkip -IgnoreFunctionName @('Out-ConsoleGridView') -IgnoreModuleName @('Microsoft.PowerShell.ConsoleGuiTools')
# Tells the script to exclude commands from functions if the module is not available to be loaded
# New-ConfigurationCommand -CommandName @('') -ModuleName @('') # Populate arrays or remove empty example.
$ConfigurationFormat = [ordered] @{
RemoveComments = $false
PlaceOpenBraceEnable = $true
PlaceOpenBraceOnSameLine = $true
PlaceOpenBraceNewLineAfter = $true
PlaceOpenBraceIgnoreOneLineBlock = $false
PlaceCloseBraceEnable = $true
PlaceCloseBraceNewLineAfter = $true
PlaceCloseBraceIgnoreOneLineBlock = $false
PlaceCloseBraceNoEmptyLineBefore = $true
UseConsistentIndentationEnable = $true
UseConsistentIndentationKind = 'space'
UseConsistentIndentationPipelineIndentation = 'IncreaseIndentationAfterEveryPipeline'
UseConsistentIndentationIndentationSize = 4
UseConsistentWhitespaceEnable = $true
UseConsistentWhitespaceCheckInnerBrace = $true
UseConsistentWhitespaceCheckOpenBrace = $true
UseConsistentWhitespaceCheckOpenParen = $true
UseConsistentWhitespaceCheckOperator = $true
UseConsistentWhitespaceCheckPipe = $true
UseConsistentWhitespaceCheckSeparator = $true
AlignAssignmentStatementEnable = $true
AlignAssignmentStatementCheckHashtable = $true
UseCorrectCasingEnable = $true
}
# format PSD1 and PSM1 files when merging into a single file
# enable formatting is not required as Configuration is provided
New-ConfigurationFormat -ApplyTo 'OnMergePSM1', 'OnMergePSD1' -Sort None @ConfigurationFormat
# format PSD1 and PSM1 files within the module
# enable formatting is required to make sure that formatting is applied (with default settings)
New-ConfigurationFormat -ApplyTo 'DefaultPSD1', 'DefaultPSM1' -EnableFormatting -Sort None
# when creating PSD1 use special style without comments and with only required parameters
New-ConfigurationFormat -ApplyTo 'DefaultPSD1', 'OnMergePSD1' -PSD1Style 'Minimal'
# configuration for documentation, at the same time it enables documentation processing
New-ConfigurationDocumentation -Enable:$false -StartClean -UpdateWhenNew -PathReadme 'Docs\Readme.md' -Path 'Docs'
New-ConfigurationImportModule -ImportSelf #-ImportRequiredModules
New-ConfigurationBuild -Enable:$true -SignModule:$false -DeleteTargetModuleBeforeBuild -MergeModuleOnBuild -UseWildcardForFunctions
$PreScriptMerge = {
param (
[int]$Mode,
[Parameter()]
[ValidateSet('Auditing','ESC1','ESC2','ESC3','ESC4','ESC5','ESC6','ESC8','All','PromptMe')]
[array]$Scans = 'All'
)
}
$PostScriptMerge = { Invoke-Locksmith -Mode $Mode -Scans $Scans }
New-ConfigurationArtefact -Type Packed -Enable -Path "$PSScriptRoot\..\Artefacts\Packed" -ArtefactName '<ModuleName>-v<ModuleVersion>.zip'
New-ConfigurationArtefact -Type Script -Enable -Path "$PSScriptRoot\..\Artefacts\Script" -PreScriptMerge $PreScriptMerge -PostScriptMerge $PostScriptMerge -ScriptName "Invoke-<ModuleName>.ps1"
New-ConfigurationArtefact -Type ScriptPacked -Enable -Path "$PSScriptRoot\..\Artefacts\ScriptPacked" -ArtefactName "Invoke-<ModuleName>.zip" -PreScriptMerge $PreScriptMerge -PostScriptMerge $PostScriptMerge -ScriptName "Invoke-<ModuleName>.ps1"
New-ConfigurationArtefact -Type Unpacked -Enable -Path "$PSScriptRoot\..\Artefacts\Unpacked"
}
Copy-Item "$PSScriptRoot\..\Artefacts\Script\Invoke-Locksmith.ps1" "$PSScriptRoot\..\"