src/Utilities/Get-XrmBase64.ps1
|
<# .SYNOPSIS Get base 64 from file content. .DESCRIPTION Read given file and return its content as base64 content. .PARAMETER FilePath Full file path. A relative path is read from the PowerShell location. .OUTPUTS System.String. The file content encoded in base 64. .EXAMPLE $content = Get-XrmBase64 -FilePath "C:\Temp\contoso_logo.png"; .LINK https://github.com/AymericM78/PowerDataOps/blob/main/documentation/commands/Get-XrmBase64.md #> function Get-XrmBase64 { [CmdletBinding()] [OutputType([String])] param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [ValidateScript( { Test-Path $_ })] [string] $FilePath ) begin { $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); } process { # Relative to the PowerShell location, not to the folder of the process (M25) if ($FilePath) { $FilePath = Resolve-XrmPathInternal -Path $FilePath; } $content = [System.IO.File]::ReadAllBytes($FilePath); $content64 = [System.Convert]::ToBase64String($content); $content64; } end { $StopWatch.Stop(); Trace-XrmFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch; } } Export-ModuleMember -Function Get-XrmBase64 -Alias *; |