Private/Get-EscapedString.ps1

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
function Get-EscapedString {
    <#
.SYNOPSIS
Outputs escaped string value.
 
.DESCRIPTION
Wrapper for the System.Uri EscapeDataString method.
When provided with an input string, an escaped string will be output.
This can be used for forming URLs and query strings where spaces are not allowed.
 
.PARAMETER inputString
String to escape
 
.EXAMPLE
"Safe Name" | Get-EscapedString
 
.INPUTS
String Value
 
.OUTPUTS
Escaped String Value
#>

    [CmdletBinding()]
    [OutputType('System.String')]
    param(
        [parameter(
            Mandatory = $true,
            ValueFromPipeline = $true
        )]
        [string]$inputString

    )

    Begin {}

    Process {

        #Output escaped string
        [System.Uri]::EscapeDataString($inputString)

    }

    End {}

}