-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathps-syntax-test.ps1
More file actions
75 lines (61 loc) · 1.99 KB
/
ps-syntax-test.ps1
File metadata and controls
75 lines (61 loc) · 1.99 KB
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
# cn-example.ps1
#
# CertNanny PowerShell Example keystore implementation
#
# This script demonstrates how variables can be assigned
# and modified in PowerShell.
#
############################################################
# Fetch command line arguments and data passed on input
############################################################
# command line arguments
Param (
$Command # API Command to be run
)
# $params contains the input parameters from CertNanny that
# is passed as JSON and converted here into a native object
# variable.
#$params = $input | ConvertFrom-Json
# Apparently, reading $input does not work in PS 5...
$params = [Console]::In.ReadToEnd()|ConvertFrom-Json
############################################################
# Test/Example Commands
############################################################
# This example shows how to add a member to the native object
# returned by ConvertFrom-Json.
function test_1 {
$params | Add-Member -Type NoteProperty -Name "key2" -Value "value 2"
ConvertTo-Json -Compress $params
}
# This example shows how to create a new hash map and later add a member
function test_3 {
$result = @{ "key3"="value 3" }
$result += @{ "key4"="value 4" }
ConvertTo-Json -Compress $result
}
# This example shows how to throw an error that is added to the input
# params object for debugging purposes
function test_err {
$params | Add-Member -Type NoteProperty -Name "Error" -Value "Expected error"
ConvertTo-Json -Compress $params
Exit 1
}
function get-subcall-1 {
Write-Output "this is the subcall-1"
}
function test_subcall {
Write-Output "outer; $(get-subcall-1)"
}
############################################################
# MAIN - Process API Command
############################################################
Switch -Regex ($Command)
{
'^test_.*$' {& $Command; Break}
Default {
$err = @{ "Error"="Unsupported API command '$command'" }
ConvertTo-Json $err
Exit 1
Break
}
}