forked from jmaddington/dRMM-Template-PS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.ps1
118 lines (96 loc) · 4.21 KB
/
command.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
#Generic function to check variables in dRMM PowerShell script
#@param $site_variable: the value of the site/account level variable to check
#@param $script_variable: the value of the script level variable to check
#@param $exit_if_missing: set to $true is variable is required to finish the script
#@param $exit_message: message to output if script is erroring out
#@param $warning_message: message to output if script has variable related error but will continue
#@param $default: default value to return
function Get-dRMMVariable {
[cmdletbinding()]
Param($site_variable,
$script_variable,
[boolean]$exit_if_missing = $true,
$exit_message,
$warning_message,
$default)
#Check to see if NO variable value has been passed as either account, site or script level
If ($null -eq $site_variable -and $null -eq $script_variable) {
#If no variable has been passed and this is mandatory, exit
if ($exit_if_missing) {
$exitcode = 1
dRMM-ExitScript -exitcode $exitcode -results $exit_message
} else {
#Otherwise throw a warning and carry on
if (!($null -eq $warning_message)) { Write-output $warning_message}
#Return a default value if set
If (!($null -eq $default)) { return $default }
}
}
#Check to see if the script level variable is set to 0, indicating that a site/acct level variable should be used
#but site/account level variable is missing
If ($script_variable -eq 0 -and $null -eq $site_variable) {
#If no variable has been passed and this is mandatory, exit
if ($exit_if_missing) {
$exitcode = 1
Exit-dRMMScript -exitcode $exitcode -results $exit_message
} else {
#Otherwise throw a warning and carry on
if (!($null -eq $warning_message)) { Write-output $warning_message}
}
}
#Finally, we should have tested for all other options above. Return script_variable, if set, otherwise
#return the site/acct variable
If (!($script_variable -eq 0)) {
return $script_variable
} else {
return $site_variable
}
} #End function
#Generic function to gracefully exit dRMM PowerShell script
#@param exitcode: mandatory, code to exit with; 0=success, 1=failure
#@param results: string or integer to pass back to dRMM for results of script
#@param diagnostics: additional information to pass back to dRMM for results of script
function Exit-dRMMScript {
[cmdletbinding()]
Param([Parameter(Mandatory=$true)]$exitcode, $results, $diagnostics)
#Output results
Write-Output "<-Start Result->"
Write-Output "Result=$results"
Write-Output "<-End Result->"
#Output diagnostics, if they exist
if (!($null -eq $diagnostics)) {
Write-Output "<-Start Diagnostics->"
Write-Output "Result=$diagnostics"
Write-Output "<-End Result->"
}
exit $exitcode
} #End function
#Generic function to set dRMM UDF
#@param udf_number: mandatory, UDF number to set
#@param udf_value: mandatory, value to set UDF to
function Set-dRMM-UDF {
Param([Parameter(Mandatory=$true)]$udf_number, $udf_value)
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\CentraStage /v "Custom$udf_number" /t REG_SZ /d "$udf_value" /f
}
#Dump all the environmental variables to stdout, usually only for debugging
if ($env:drmm_dump_env_vars -eq "true") {
Get-ChildItem variable:$env | ForEach-Object {
Write-Output $_
}
}
########################################
##### Begin custom script section ######
########################################
#Check to see if we are in test mode, usually for for local for dev
If (!($env:test -eq "true")) {
#Get variables
$hello_world_var = Get-dRMMVariable -site_variable $env:hello_world_var -script_variable $env:script_hello_world_var -exit_if_missing $false -warning "Hello World value not set, continuing" -default "Hello world!"
} else {
#We're in test mode, manually set variables
$hello_world_var = "Hello all y'all!"
}
# Do things
Write-Output $hello_world_var
#Exit with success, to exit with failure use $exitcode = 1
$exitcode = 0
Exit-dRMMScript -exitcode $exitcode -results "Success!" -diagnostics "Additional info here"