Private/Get-ByteArray.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
Function Get-ByteArray {
    <#
.SYNOPSIS
Get a file as a ByteArray

.DESCRIPTION
Outputs a file to a ByteArray

.PARAMETER Path
The File to Read as a ByteArray

.EXAMPLE
Get-ByteArray -Path "C:\SomeFile.zip"

#>

    [CmdletBinding()]
    [OutputType('System.Byte[]')]
    Param(
        # The File to Convert to a ByteArray
        [Parameter(
            Mandatory = $true,
            ValueFromPipeline = $true
        )]
        [ValidateNotNullOrEmpty()]
        [ValidateScript( { Test-Path -Path $_ -PathType Leaf})]
        [String]
        $Path
    )

    Begin {}

    Process {
        [System.IO.File]::ReadAllBytes($Path)
    }

    End {}

}