-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path99_Invoke-OptionalUserCommand.ps1
51 lines (37 loc) · 1.18 KB
/
99_Invoke-OptionalUserCommand.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
<#
.SYNOPSIS
Runs optional user command.
.DESCRIPTION
Executes an optional user command. This script will run as the final step in the EC2 startup process,
potentially overriding any changes applied in previous scripts.
.PARAMETER UserCommand
(Optional) Optional user command.
.EXAMPLE
Invoke-OptionalUserCommand -UserCommand "<OPTIONAL_USER_COMMAND>"
.NOTES
Copyright 2023-2024 The MathWorks, Inc.
#>
function Invoke-OptionalUserCommand {
param(
[Parameter()]
[string] $UserCommand
)
Write-Output 'Starting Invoke-OptionalUserCommand...'
Write-Output "$UserCommand"
if ([string]::IsNullOrWhiteSpace("$UserCommand")) {
Write-Output 'No optional user command was passed.'
}
else {
Write-Output 'The passed string is an inline PowerShell command.'
Invoke-Expression "$UserCommand"
}
Write-Output 'Done with Invoke-OptionalUserCommand.'
}
try {
Invoke-OptionalUserCommand -UserCommand $Env:OptionalUserCommand
}
catch {
$ScriptPath = $MyInvocation.MyCommand.Path
Write-Output "ERROR - An error occurred while running script 'Invoke-OptionalUserCommand': $ScriptPath. Error: $_"
throw
}