-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReset-ToValidString.ps1
More file actions
52 lines (48 loc) · 1.31 KB
/
Reset-ToValidString.ps1
File metadata and controls
52 lines (48 loc) · 1.31 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
<#
.SYNOPSIS
Returns a string with fixing the single quote or empty string converting $Value.
.DESCRIPTION
Returns a string with fixing the single quote or empty string converting $Value
.PARAMETER Value
String or $null value.
.OUTPUTS
string
.EXAMPLE
Reset-ToValidString -Value "I'm here!"
#>
function Reset-ToValidString() {
[cmdletbinding()]
Param (
$Value
)
Begin {
$result = '';
}
Process {
try {
if ($null -ne $Value -and $Value.Length -gt 0) {
# replace any single quote in the string with **TWO** single quotes
$result = $Value -replace "'", "''"
}
else {
if ($null -eq $Value) {
# If the value was null then set the result to an empty string
$result = ''
}
else {
# if the result is already and empty string, then leave it alone.
$result = $Value
}
}
return $result
}
catch {
Write-Exception -ErrorObj $_ -Message "Throws an exception in 'Reset-ToValidString'" -Stop $false
return ''
}
finally {
}
}
End {
}
}