-
Notifications
You must be signed in to change notification settings - Fork 0
/
Invoke-Actions.ps1
65 lines (55 loc) · 2.3 KB
/
Invoke-Actions.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
# Requires:
# Log.ps1
function Invoke-Actions{
param(
[System.Xml.XmlElement]$actionsRoot,
[string]$progressTitle
)
$scriptPath = Split-Path -Parent $script:MyInvocation.MyCommand.Path
$actionDefinitionsPath = Join-Path -Path $scriptPath -ChildPath SupportedActions.xml
$actionDefinitions = [xml](Get-Content $actionDefinitionsPath)
#$validActions = "Features", "IIS", "TimerJobs", "Provision", "Variation", "HostsFile"
#$actionsRoot.ChildNodes | Where-Object { $validActions -contains $_.Name } |
$actionsRoot.SelectNodes("./*") |
ForEach-Object {
$actionConfig = $_
$actionDefinition = $actionDefinitions.SelectSingleNode("./SupportedActions/Action[@Name='$($_.LocalName)']")
if ($actionDefinition) {
Log "Information" "$progressTitle > $($actionConfig.LocalName)..."
# Run action's script file if required
if ($actionDefinition.ScriptPath) {
$actionScriptPath = Join-Path $scriptPath -ChildPath $actionDefinition.ScriptPath
#Invoke-Command -ScriptBlock [scriptblock]::Create(". `"$actionScriptPath`"")
Invoke-Expression ". ""$actionScriptPath"""
}
# Figure out if the action needs root or children of config
$command = Get-Command $actionDefinition.Command
$config = if ($command.Parameters["Config"].ParameterType -eq [System.Xml.XmlElement]) { $actionConfig } else { $actionConfig.SelectNodes("./*") }
# Build up parameters
$params = @{Config = $config; ProgressTitle = "$progressTitle > $($actionConfig.LocalName)"; ActionDefinition = $actionDefinition}
# Run the command
&($actionDefinition.Command) @params
Log "Information" "$progressTitle > $($actionConfig.LocalName) done."
} else {
Log "Critical" "$($_.LocalName) deployment action is not supported."
}
}
}
function Invoke-DynamicCommand {
param(
[string]$CommandName,
[Hashtable]$CommandParameters,
[string]$ContainingScriptPath
)
process {
# Run action's script file if required
if ($ContainingScriptPath) {
$actionScriptPath = Join-Path $scriptPath -ChildPath $ContainingScriptPath
#Invoke-Command -ScriptBlock [scriptblock]::Create(". $actionScriptPath")
Invoke-Expression -ScriptBlock ". ""$actionScriptPath"""
}
# Run the command
$scriptBlock = [scriptblock]::Create("&$CommandName @params")
Invoke-Command -ScriptBlock $scriptBlock -ArgumentList $CommandParameters
}
}