-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNinjaModule.psm1
More file actions
80 lines (76 loc) · 2.85 KB
/
Copy pathNinjaModule.psm1
File metadata and controls
80 lines (76 loc) · 2.85 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
76
77
78
79
80
function Get-NinjaPropertyBool {
param(
[Parameter(Mandatory=$true)]
[string]$Field
)
try {
return $(Ninja-Property-Get $Field) -eq "1"
} catch {
Write-Host "An error occurred in function ""Get-NinjaPropertyBool"", exiting with exception message ""$($_.Exception.Message)"""
exit 1
}
}
#returns string or $null
#If Ninja-Property-Get is available but the field doesn't exist, it outputs "Unable to find the specified field." without a newline character,
#there is currently nothing I can do to prevent this without affecting the output
function Get-NinjaPropertyString {
param(
[Parameter(Mandatory=$true)]
[string]$Field
)
try {
$value = Ninja-Property-Get $Field
if ($value -is [System.String] -and $value -ne "") {
return $value
} else {
return $null
}
} catch {
Write-Host "An error occurred in function ""Get-NinjaPropertyString"", exiting with exception message ""$($_.Exception.Message)"""
exit 1
}
}
#returns array
#Ninja usage implies string array as there are no other custom field types which return an array
#If Ninja-Property-Get is available but the field doesn't exist, it outputs "Unable to find the specified field." without a newline character,
#there is currently nothing I can do to prevent this without affecting the output
#TODO: Consider running trim on each array element.
function Get-NinjaPropertyStringArray {
param(
[Parameter(Mandatory=$true)]
[string]$Field
)
try {
$value = Ninja-Property-Get $Field
if ($value -is [System.Array]) {
return $value
} elseif ($value -is [string] -and $value -ne "") {
return @($value)
} else {
return @()
}
} catch {
Write-Host "An error occurred in function ""Get-NinjaPropertyStringArray"", exiting with exception message ""$($_.Exception.Message)"""
exit 1
}
}
#returns string or exits if string is empty or not found.
#If Ninja-Property-Get is available but the field doesn't exist, it outputs "Unable to find the specified field." without a newline character,
#there is currently nothing I can do to prevent this without affecting the output
function Get-NinjaPropertyStringExitIfMissingOrEmpty {
param(
[Parameter(Mandatory=$true)]
[string]$Field
)
try {
$value = Ninja-Property-Get $Field
if ($value -is [System.String] -and $value -ne "") {
return $value
} else {
Write-Host """Get-NinjaPropertyStringExitIfMissingOrEmpty"": Unable to find field ""$Field"" or string was empty. Exiting."
}
} catch {
Write-Host "An error occurred in function ""Get-NinjaPropertyString"", exiting with exception message ""$($_.Exception.Message)"""
}
exit 1
}