Public/Get-OriAzBopFolderHash.ps1
<#
.SYNOPSIS Compute Hash of the folder .DESCRIPTION Compute Hash of the folder .PARAMETER Path The Path to folder to compute the Hash .PARAMETER ExcludePath Exclude Path is path to the Manifest file (.PSD1 suffix) .EXAMPLE Get-OriAzBopFolderHash ` -Path c:\temp\ # Should return something like this: # 5cfdcbf97b7a004f387c69d6b1dab25b #> function Get-OriAzBopFolderHash { [CmdLetBinding()] param ( [Parameter(Mandatory = $True, HelpMessage = "The Path to folder to compute the Hash")] [ValidateScript({Test-Path $_ })] [String] $Path, [Parameter(Mandatory = $False, HelpMessage = "Exclude Path is path to the Manifest file (.PSD1 suffix)")] [String[]] $ExcludePath ) $ErrorActionPreference = 'Stop' Write-Verbose "-- Get-OriAzBopFolderHash --" Write-Verbose "Path: $Path" Write-Verbose "ExcludePath: $ExcludePath" $ExcludePath += "*.tests.ps1" $files = Get-ChildItem -Path $Path -Recurse -Exclude $ExcludePath -File $allBytes = new-object System.Collections.Generic.List[byte] foreach ($file in $files) { $allBytes.AddRange([System.IO.File]::ReadAllBytes($file.FullName)) $allBytes.AddRange([System.Text.Encoding]::UTF8.GetBytes($file.Name)) } $hasher = [System.Security.Cryptography.MD5]::Create() $ToReturn = [string]::Join("",$($hasher.ComputeHash($allBytes.ToArray()) | ForEach-Object {"{0:x2}" -f $_})) Write-Verbose "hash of $Path is [$ToReturn]." Write-Verbose "-- End of Get-OriAzBopFolderHash --" return $ToReturn } |