-
Notifications
You must be signed in to change notification settings - Fork 14
/
Import-Deployment.ps1
77 lines (68 loc) · 4.53 KB
/
Import-Deployment.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
function Import-Deployment
{
<#
.Synopsis
Imports modules in your deployment
.Description
Imports modules in a deployment
.Link
Push-Deployment
.Link
Add-Deployment
.Link
Remove-Deployment
.Example
# Import all modules in a deployment
Import-Deployment
#>
[CmdletBinding(DefaultParameterSetName='AllDeployments')]
[OutputType([Management.Automation.PSModuleInfo])]
param(
# The name of the deployment
[Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,ParameterSetName='SpecificDeployments')]
[string]
$Name
)
begin {
#Get all deployments
$deployments = Get-Deployment
$progId = Get-Random
#region Define Loader for each module
$loadModule = {
$c++
$perc = ($c / $total) * 100
$in = $_
Write-Progress "Importing Modules" $in.Name -PercentComplete $perc -Id $progId
$module = @(Import-Module $_.Path -PassThru -Global -Force)
if ($module.ExportedFunctions.Keys -like "*SecureSetting*") {
Import-Module Pipeworks -Force -Global
}
if ($module.Count -gt 1 ) {
$module | Where-Object {$_.Name -eq $in.Name }
} else {
$module
}
}
#endregion Define Loader for each module
}
process {
#region Find appropriate deployment
if ($PSCmdlet.ParameterSetName -eq 'AllDeployments') {
$deploymentsToLoad = $deployments |
Sort-Object Name
} else {
$deploymentsToLoad = $deployments|
Where-Object { $_.Name -like $name } |
Sort-Object Name
}
#endregion Find appropriate deployment
#region Import deployment modules
if ($deploymentsToLoad) {
$c =0; $total = @($deploymentsToLoad).Count
foreach ($_ in $deploymentsToLoad) {
. $loadModule
}
}
#endregion Import deployment modules
}
}