FabricTools v0.33.0 Public Preview

Convert-ToBase64

Encodes the content of a file into a Base64-encoded string.

Syntax

Convert-ToBase64 [-filePath] <string> [<CommonParameters>]

Description

The Convert-ToBase64 function takes a file path as input, reads the file's content as a byte array, and converts it into a Base64-encoded string. This is useful for embedding binary data (e.g., images, documents) in text-based formats such as JSON or XML.

Examples

Example 1

Output: VGhpcyBpcyBhbiBlbmNvZGVkIGZpbGUu

Convert-ToBase64  -filePath "C:\Path\To\File.txt"

Example 2

This saves the Base64-encoded content of the image to a text file.

$encodedContent = Convert-ToBase64  -filePath "C:\Path\To\Image.jpg

$encodedContent | Set-Content -Path "C:\Path\To\EncodedImage.txt" This saves the Base64-encoded content of the image to a text file.

Parameters

NameTypeReq.Pos.PipelineDescription
-filePath string ✓Required 0 –

The full path to the file whose contents you want to encode into Base64.

This cmdlet also supports the common parameters, such as -Verbose and -ErrorAction. See about_CommonParameters.

Outputs

System.String

{{ Fill in the Description }}

Notes

  • Ensure the file exists at the specified path before running this function.
  • Large files may cause memory constraints due to full loading into memory.

Author: Tiago Balabuch