Cmdlets

Choose a cmdlet from the list on the left or search for a specific cmdlet. Choose a cmdlet from the list or search for a specific cmdlet.
About Help  Providers
 

ConvertTo-Base64

ConvertTo-Base64

pscx.dll

Synopsis

PSCX Cmdlet: Converts byte array or specified file contents to base64 string.

Syntax

ConvertTo-Base64 [-Path] [-NoLineBreak] [-Stream] [<CommonParameters>]

ConvertTo-Base64 [-InputObject] [-NoLineBreak] [-Stream] [<CommonParameters>]

ConvertTo-Base64 [-LiteralPath] [-NoLineBreak] [-Stream] [<CommonParameters>]

Detailed Description

Converts byte array or specified file contents to base64 string. By default, this cmdlet inserts line breaks every 76 characters and outputs the result in a single string. For very large files, you may run into OutOfMemoryExceptions. In this case, use the -Stream parameter which will generate multiple string outputs that, combined together, result in the equivalent base 64 text.

Parameters

-LiteralPath <String[]>

Aliases

None

Required?

true

Position

1

Default value

None

Accept pipeline input?

true (ByPropertyName)

Accept wildcard characters?

false

-Path <String[]>

Aliases

None

Required?

true

Position

1

Default value

None

Accept pipeline input?

true (ByPropertyName)

Accept wildcard characters?

true

-InputObject <PSObject>

Aliases

None

Required?

true

Position

named

Default value

None

Accept pipeline input?

true (ByValue)

Accept wildcard characters?

false

-NoLineBreak <SwitchParameter>

Suppress line breaks that are added by default every 76 characters.

Aliases

None

Required?

false

Position

named

Default value

false

Accept pipeline input?

false

Accept wildcard characters?

false

-Stream <SwitchParameter>

Outputs multiple strings for the base 64 encoded data. By default, the bytes are accumulated and encoded as a single string which can generate OutOfMemoryExceptions for very large files.

Aliases

None

Required?

false

Position

named

Default value

false

Accept pipeline input?

false

Accept wildcard characters?

false

Input Type




Return Type


Notes

Examples

-------------------------- EXAMPLE 1 --------------------------

This buffers up the steam of bytes and then outputs the base64 string.

[byte[]](1..127) | ConvertTo-Base64

-------------------------- EXAMPLE 2 --------------------------

This outputs the base64 string based on the byte array passed into the InputObject parameter.

$arr = [byte[]](1..127); ConvertTo-Base64 -Inp $arr

-------------------------- EXAMPLE 3 --------------------------

Converts the specified file (read as binary) to a base 64 string.

$b64 = ConvertTo-Base64 Foo.dll -NoLineBreak

-------------------------- EXAMPLE 4 --------------------------

When dealing with large files it is usually better to pass the path to ConvertTo-Base64.

ConvertTo-Base64 $PSHome\PowerShell.exe -stream > b64.txt

ConvertFrom-Base64