-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathConvertFrom-HexString.ps1
61 lines (53 loc) · 1.6 KB
/
ConvertFrom-HexString.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
function ConvertFrom-HexString {
<#
.SYNOPSIS
Convert a hex string or array of hex string to text
.DESCRIPTION
Convert a hex string or array of hex string to text
.PARAMETER HexString
An array of hex strings that need to be converted back to text. Values can be passed from the pipeline.
.PARAMETER IncludeInput
Switch indicating that you want the input to be included in the output
.EXAMPLE
ConvertFrom-HexString -HexString '434241'
CBA
.EXAMPLE
414243 | ConvertFrom-HexString
ABC
.EXAMPLE
ConvertFrom-HexString -HexString '414243', '434241' -IncludeInput
HexString String
--------- ------
414243 ABC
434241 CBA
#>
#region Parameter
[CmdletBinding(ConfirmImpact = 'Low')]
[OutputType('string')]
Param(
[Parameter(Mandatory, HelpMessage='Enter a hex string', Position = 0, ValueFromPipeline)]
[string[]] $HexString,
[switch] $IncludeInput
)
#endregion Parameter
begin {
Write-Verbose -Message "Starting [$($MyInvocation.Mycommand)]"
}
process {
foreach ($Line in $HexString) {
$Hexarray = $Line -split '(?<=\G.{2})(?=.)'
$ReturnVal = ($Hexarray | foreach-object { ([char] ([int] ('0x{0}' -f $_))) }) -join ''
if ($IncludeInput) {
New-Object -TypeName psobject -Property ([ordered] @{
HexString = $Line
String = $ReturnVal
})
} else {
$ReturnVal
}
}
}
end {
Write-Verbose -Message "Ending [$($MyInvocation.Mycommand)]"
}
}