ps/Modules/Alkami.DevOps.Common/Public/Get-FileContentHash.ps1
2023-05-30 22:51:22 -07:00

29 lines
817 B
PowerShell

function Get-FileContentHash {
<#
.SYNOPSIS
Retrieves a hash generated from a file's contents.
.DESCRIPTION
Use this command to generate a hash for use in determining if a file's text contents have changed.
.PARAMETER FilePath
[string] The full path (including file name) to the file to be hashed. Required.
.EXAMPLE
Get-FileContentHash "C:\Temp\File.txt"
.EXAMPLE
Get-FileContentHash -FilePath "C:\Temp\File.txt"
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[Alias("FilePath")]
[string]$file
)
$fileContent = [System.IO.File]::ReadAllBytes($file)
$convertedContent = [System.Text.Encoding]::GetEncoding(1252).GetString($fileContent);
return Get-UTF8ContentHash $convertedContent
}