-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisualCronAPI.psm1
245 lines (189 loc) · 6.16 KB
/
VisualCronAPI.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# NOTES:
# The VisualCron API uses WCF which isn't available in .NET Core so
# the PowerShell code must be run under Windows PowerShell and
# not PowerShell Core (pwsh).
#
<#
.SYNOPSIS
Fetch a VisualCron API Connection object.
.DESCRIPTION
Create the VisualCron API Connection object with the supplied params.
.PARAMETER Address
The VisualCron server's address.
.PARAMETER Port
The port number to connect on.
.PARAMETER ConnectionType
The connection type is either 'Remote' or 'Local'.
.PARAMETER UserName
User to connect as.
.PARAMETER Password
The password for the user account.
.PARAMETER SecurePassword
The password for the user account as a SecureString.
.PARAMETER Credential
The PSCredential for the service account.
.PARAMETER Local
A switch for when you only want to connect to your local server anonymously.
.PARAMETER UseADLogon
A switch for when you need to use Active Directory logon.
UserName and Password will be ignored.
Do not specify at the same time as the Local flag as it isn't supported.
.INPUTS
None.
.OUTPUTS
VisualCronAPI.Connection.
.EXAMPLE
PS> Get-VcConnection '10.110.0.135' 16444 'Remote' -UserName 'svc-user' -Password 'ar2@#$3'
The complete set of positional parameters for when you have the plain-text password.
.EXAMPLE
PS> Get-VcConnection -Address 'ServerName' -UserName 'svc-user' -Password 'ar2@#$3'
As the previous example but now rely on the default values.
.EXAMPLE
PS> Get-VcConnection -Address $Address -UserName $UserName -SecurePassword $SecurePassword
Call with pre-existing variables and the SecureString password.
.EXAMPLE
PS> Get-VcConnection '10.110.0.135' -Credential (Get-Credential)
The PSCredential for the service account, entered into a dialog box.
.EXAMPLE
PS> Get-VcConnection -Local
A switch for when you only want to connect to your local server anonymously.
.LINK
https://www.visualcron.com/doc/HTML/powershell.html
#>
function Get-VcConnection {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', 'Password', Justification = "It's not me, it's you.")]
param (
[Parameter(Position = 0)]
[string] $Address = $Env:COMPUTERNAME,
[Parameter(Position = 1)]
[int] $Port = 16444,
[Parameter(Position = 2)]
[string] $ConnectionType = 'Remote',
[Parameter(Mandatory, Position = 3, ParameterSetName = 'Password')]
[Parameter(Mandatory, Position = 3, ParameterSetName = 'SecurePassword')]
[string] $UserName,
[Parameter(Mandatory, ParameterSetName = 'Password')]
[string] $Password,
[Parameter(Mandatory, ParameterSetName = 'SecurePassword')]
[SecureString] $SecurePassword,
[Parameter(Mandatory, ParameterSetName = 'Credential')]
[System.Management.Automation.PSCredential] $Credential,
[Parameter(ParameterSetName = 'Local')]
[switch] $Local,
[Parameter(ParameterSetName = 'UseADLogon')]
[switch] $UseADLogon)
if ($SecurePassword) {
$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $SecurePassword
}
if ($Credential) {
$Password = $Credential.GetNetworkCredential().Password
$UserName = $Credential.UserName
}
$props = @{
Address = $Address
Port = $Port
ConnectionType = $ConnectionType
}
if ($Local -eq $false -and $UseADLogon -eq $false) {
$props["UserName"] = $UserName
$props["PassWord"] = $Password
}
if ($UseADLogon -eq $true) {
$props["UseADLogon"] = $true
}
New-Object VisualCronAPI.Connection -Property $props
}
<#
.SYNOPSIS
Connect to a VisualCron API Server.
.DESCRIPTION
Create the VisualCron API Server object with the supplied Connection object.
.INPUTS
VisualCronAPI.Connection.
.OUTPUTS
VisualCronAPI.Server.
.EXAMPLE
PS> $server = $connection | Connect-VcServer
.LINK
https://www.visualcron.com/doc/HTML/powershell.html
#>
function Connect-VcServer {
param (
[Parameter(Mandatory, ValueFromPipeline)]
[VisualCronAPI.Connection] $Connection)
(New-Object VisualCronAPI.Client).Connect($Connection, $true)
}
<#
.SYNOPSIS
Fetch all the Jobs from a VisualCron API Server.
.DESCRIPTION
Fetch all the Jobs from the supplied Server.
.INPUTS
VisualCronAPI.Server.
.OUTPUTS
VisualCronAPI.Jobs list.
.EXAMPLE
PS> $jobs = $server | Get-VcJob
.LINK
https://www.visualcron.com/doc/HTML/powershell.html
#>
function Get-VcJobs {
param (
[Parameter(Mandatory, ValueFromPipeline)]
[VisualCronAPI.Server] $server,
[switch] $active)
$server.Jobs.GetAll() `
| Where-Object { !($active) -or $_.Stats.Active }
}
<#
.SYNOPSIS
Fetch all the Tasks from a VisualCron API Server.
.DESCRIPTION
Fetch all the Tasks from the supplied Server.
The Tasks are decorated with the Job Name and Job Group.
.INPUTS
VisualCronAPI.Server.
.OUTPUTS
VisualCronAPI.Tasks list.
.EXAMPLE
PS> $tasks = $server | Get-VcTasks
.LINK
https://www.visualcron.com/doc/HTML/powershell.html
#>
function Get-VcTasks {
param (
[Parameter(Mandatory, ValueFromPipeline)]
[VisualCronAPI.Server] $server,
[switch] $active)
Get-VCJobs @psBoundParameters `
| ForEach-Object {
$job = $_
$_.Tasks `
| Where-Object { !($active) -or $_.Stats.Active } `
| Sort-Object Order `
| ForEach-Object { Add-Member NoteProperty Job -InputObject $_ $job -PassThru } `
| ForEach-Object { Add-Member ScriptProperty JobName -InputObject $_ { $this.Job.Name } -PassThru } `
| ForEach-Object { Add-Member ScriptProperty Group -InputObject $_ { $this.Job.Group } -PassThru }
}
}
function Get-UserVariable {
param (
[Parameter(Mandatory, ValueFromPipeline)]
[VisualCronAPI.Server] $server,
[string] $variableName)
$server.Variables.GetGenericVariable('{uservar(' + $variableName + ')}')
}
function Get-ServerVariable {
param (
[Parameter(Mandatory, ValueFromPipeline)]
[VisualCronAPI.Server] $server,
[string] $variableName)
$server.Variables.GetGenericVariable('{server(' + $variableName + ')}')
}
function Get-Variable {
param (
[Parameter(Mandatory, ValueFromPipeline)]
[VisualCronAPI.Server] $server,
[string] $variableName)
$server.Variables.GetGenericVariable('{' + $variableName + '}')
}