-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTM1ps_Process.psm1
75 lines (59 loc) · 2.33 KB
/
TM1ps_Process.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
# ======================================================================================================
# _____ _ _ ___ __
# | | | |\/| / | | |_) ( (`
# |_| |_| | |_| |_| _)_)
#
# Functions to handel processes:
# 'Get-Tm1Processes',
# 'Test-Tm1Process',
# 'Invoke-Tm1Process'
# ======================================================================================================
function Invoke-Tm1Process {
<#
.SYNOPSIS
...
.DESCRIPTION
...
.PARAMETER Tm1ConnectionName
Parameter 1
.PARAMETER Tm1ProcessName
Parameter2
.PARAMETER Tm1ProcessParameters
Parameter3
.INPUTS
None. You cannot pipe objects to this function.
.OUTPUTS
...
.EXAMPLE
Invoke-Tm1Process -Tm1ConnectionName 'connection01' -Tm1ProcessName '}bedrock.server.wait' -Tm1ProcessParameters @{pLogOutput = 0; pWaitSec = 8 }
.LINK
https://github.com/ichermak/TM1ps
#>
[CmdletBinding()]
PARAM (
[Parameter(Mandatory = $true, Position = 1)] [string]$Tm1ConnectionName,
[Parameter(Mandatory = $true, Position = 2)] [string]$Tm1ProcessName,
[Parameter(Mandatory = $false, Position = 3)] [hashtable]$Tm1ProcessParameters
)
TRY {
# Build the rest request url
$Tm1RestRequest = "Processes('$tm1ProcessName')/tm1.ExecuteWithReturn"
# Build the body
$Tm1RestBody = '{"Parameters":['
foreach ($Item in $Tm1ProcessParameters.GetEnumerator()) {
[string]$Tm1ParamName = $($Item.Key)
[string]$Tm1ParamValue = $($Item.Value)
$Tm1RestBody = $Tm1RestBody + '{"Name":"' + $Tm1ParamName + '", "Value":"' + $Tm1ParamValue + '"}, '
}
$Tm1RestBody = $Tm1RestBody.Substring(0, ($Tm1RestBody.Length - 2))
$Tm1RestBody = $Tm1RestBody + ']}'
# Execute the rest request
$Tm1RestMethod = 'POST'
$Tm1ProcessExecuteResult = Request-Tm1Rest -Tm1ConnectionName $Tm1ConnectionName -Tm1RestMethod $Tm1RestMethod -Tm1RestRequest $Tm1RestRequest -Tm1RestBody $Tm1RestBody
}
CATCH {
Write-Error "$($_.Exception.Message)"
Break
}
return $Tm1ProcessExecuteResult
}