-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathGet-InvalidFileCharacter.ps1
72 lines (65 loc) · 1.69 KB
/
Get-InvalidFileCharacter.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
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
function Get-InvalidFileCharacter {
<#
.SYNOPSIS
Gets invalid filename characters
.DESCRIPTION
Gets invalid filename characters. Function aliased to 'Show-InvalidFileCharacter'
for backward compatibility.
.PARAMETER IncludeValues
Switch indicating that decimal and hexadecimal representations of characters are to be included in output
.PARAMETER Printable
Switch indicating that only printable characters are to be in the output
.EXAMPLE
Get-InvalidFileCharacter -Printable
Would return
"
<
>
|
:
*
?
\
/
.EXAMPLE
Get-InvalidFileCharacter -Printable -IncludeValues
Would return
Char Dec Hex
---- --- ---
" 34 22
< 60 3c
> 62 3e
| 124 7c
: 58 3a
* 42 2a
? 63 3f
\ 92 5c
/ 47 2f
#>
[CmdletBinding(ConfirmImpact='None')]
[alias('Show-InvalidFileCharacter')] #FunctionAlias
[OutputType([char[]])]
Param (
[switch] $IncludeValues,
[switch] $Printable
)
begin {
Write-Verbose -Message "Starting [$($MyInvocation.Mycommand)]"
}
process {
$Invalid = [System.IO.Path]::GetInvalidFileNameChars() | Select-Object -Property @{Name='Char';Expr={$_.ToString()}},
@{Name='Dec';Expr={[int][char] $_}},
@{Name='Hex';Expr={'{0:x}' -f ([int][char] $_)}}
if ($Printable) {
$Invalid = $Invalid | Where-Object {$_.Dec -gt 32}
}
if ($IncludeValues) {
Write-Output -InputObject $Invalid
} else {
Write-Output -InputObject $Invalid.Char
}
}
end {
Write-Verbose -Message "Ending [$($MyInvocation.Mycommand)]"
}
}