forked from BornToBeRoot/NETworkManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate-FileHash.ps1
More file actions
39 lines (31 loc) · 1.33 KB
/
Copy pathCreate-FileHash.ps1
File metadata and controls
39 lines (31 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$Path
)
$Path = $Path.TrimEnd("\")
if (-not (Test-Path -Path $Path -PathType Container)) {
Write-Error "Path does not exist or is not a directory: $Path"
return
}
# Get current date as version
$Now = Get-Date
$Version = "$($Now.Year).$($Now.Month).$($Now.Day).0"
# Create SHA256 file hashes
foreach ($Hash in Get-ChildItem -Path $Path | Where-Object { $_.Name.StartsWith("NETworkManager_") -and ($_.Name.EndsWith(".zip") -or $_.Name.EndsWith(".msi")) } | Sort-Object -Descending | Get-FileHash) {
"$($Hash.Hash) $([System.IO.Path]::GetFileName($Hash.Path))" | Out-File -FilePath "$Path\NETworkManager_$($Version)_SHA256SUMS" -Encoding utf8 -Append
}
$SumFile = Join-Path $Path "NETworkManager_$($Version)_SHA256SUMS"
if (Test-Path $SumFile) {
Remove-Item $SumFile
}
Get-ChildItem -Path $Path |
Where-Object { $_.Name.StartsWith("NETworkManager_") -and ($_.Name.EndsWith(".zip") -or $_.Name.EndsWith(".msi")) } |
Sort-Object -Descending |
Get-FileHash -Algorithm SHA256 |
ForEach-Object {
# Format: <hash><two spaces><filename> + LF ending
$Line = "$($_.Hash) $([System.IO.Path]::GetFileName($_.Path))"
# Use UTF-8 without BOM and LF line endings
[System.IO.File]::AppendAllText($SumFile, "$Line`n", [System.Text.UTF8Encoding]::new($false))
}