SRXEnv.psm1

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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
if ($Host.Name -like 'ScriptRunner Extended (SRX) PowerShell*Host') {
    throw "The SRXEnv module cannot be imported into a $($Host.Name)."
}

New-Variable -Name SRXEnv -Scope Global -Visibility Public -Description 'ScriptRunner host environment hashtable.' -Force

function Reset-SRXEnvironment {
    <#
    .SYNOPSIS
    Reset global ScriptRunner PowerShell Host Environment Variable $SRXEnv.
    .DESCRIPTION
    Reset global ScriptRunner PowerShell Host Environment Variable $SRXEnv.
    #>

    [CmdletBinding()]
    param ()

    $me = whoami
    $ipaddress = '127.0.0.1'
    if (Get-Command -Name 'Get-NetIPAddress' -ErrorAction SilentlyContinue) {
        $ipaddress = Get-NetIPAddress -AddressFamily IPv4 -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty 'IPAddress' -ErrorAction SilentlyContinue
    }
    $cmdPath = $PSCommandPath
    if ([string]::IsNullOrEmpty($cmdPath)) {
        $cmdPath = Join-Path -Path (Get-Location).Path -ChildPath 'myScript.ps1'
    }

    $Global:SRXEnv = @{
        ReportEmail      = ''
        ResultEmail      = ''
        ResultHtml       = ''
        ResultList       = New-Object -TypeName 'System.Collections.ArrayList'
        ResultList2      = New-Object -TypeName 'System.Collections.ArrayList'
        ResultMessage    = ''
        ResultObjectJSON = $null
        SRXActionID      = 42
        SRXCommandPath   = $cmdPath
        SRXDisplayName   = 'Name of the current Action'
        SRXFilterValue   = ''
        SRXStarted       = Get-Date
        SRXStartedBy     = $me
        SRXStartedIP     = $ipaddress
        SRXStartedReason = "TicketID $((Get-Date).Ticks)"
        SRXStartedVia    = "Interactive by `"$($me)`" ($($Host.Name))"
    }
    Write-Verbose ($Global:SRXEnv | Out-String)
}

New-Alias -Name Reset-SRXEnv -Value Reset-SRXEnvironment -Scope Global -Option Constant, AllScope -Force

Reset-SRXEnvironment

Export-ModuleMember -Variable 'SRXEnv' -Function 'Reset-SRXEnvironment' -Alias 'Reset-SRXEnv'

# SIG # Begin signature block
# MIIZYQYJKoZIhvcNAQcCoIIZUjCCGU4CAQExDzANBglghkgBZQMEAgEFADB5Bgor
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG
# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCBQrfPSadAyc3Zg
# FFRnHNQYppFP95XXXKrLjO7h+TGvfqCCCWUwggSZMIIDgaADAgECAhBxoLc2ld2x
# r8I7K5oY7lTLMA0GCSqGSIb3DQEBCwUAMIGpMQswCQYDVQQGEwJVUzEVMBMGA1UE
# ChMMdGhhd3RlLCBJbmMuMSgwJgYDVQQLEx9DZXJ0aWZpY2F0aW9uIFNlcnZpY2Vz
# IERpdmlzaW9uMTgwNgYDVQQLEy8oYykgMjAwNiB0aGF3dGUsIEluYy4gLSBGb3Ig
# YXV0aG9yaXplZCB1c2Ugb25seTEfMB0GA1UEAxMWdGhhd3RlIFByaW1hcnkgUm9v
# dCBDQTAeFw0xMzEyMTAwMDAwMDBaFw0yMzEyMDkyMzU5NTlaMEwxCzAJBgNVBAYT
# AlVTMRUwEwYDVQQKEwx0aGF3dGUsIEluYy4xJjAkBgNVBAMTHXRoYXd0ZSBTSEEy
# NTYgQ29kZSBTaWduaW5nIENBMI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