waypoint debug
This commit is contained in:
@@ -5,10 +5,15 @@ param(
|
|||||||
[Parameter(Position = 0, ParameterSetName = 'Match', ValueFromPipeline = $true)]
|
[Parameter(Position = 0, ParameterSetName = 'Match', ValueFromPipeline = $true)]
|
||||||
[string[]]$FilePath,
|
[string[]]$FilePath,
|
||||||
|
|
||||||
# Output file (-o / -OutFile)
|
# Custom output file (-f / -OutFile)
|
||||||
|
[Parameter(Mandatory = $false, ParameterSetName = 'Generate')]
|
||||||
|
[Alias('f')]
|
||||||
|
[string]$OutFile,
|
||||||
|
|
||||||
|
# Auto output file switch (-o)
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = 'Generate')]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Generate')]
|
||||||
[Alias('o')]
|
[Alias('o')]
|
||||||
[string]$OutFile,
|
[switch]$AutoOut,
|
||||||
|
|
||||||
# File containing checksums to verify (-c / -Check)
|
# File containing checksums to verify (-c / -Check)
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = 'Verify')]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Verify')]
|
||||||
@@ -44,7 +49,7 @@ NAME
|
|||||||
checksum - Compute and verify message digests / file checksums
|
checksum - Compute and verify message digests / file checksums
|
||||||
|
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
.\checksum.ps1 [-FilePath] <string[]> [-o [<string>]] [-Algorithm <string>] [-r]
|
.\checksum.ps1 [-FilePath] <string[]> [-o] [-f <string>] [-Algorithm <string>] [-r]
|
||||||
.\checksum.ps1 [-FilePath] <string[]> -Match <string> [-Algorithm <string>] [-r]
|
.\checksum.ps1 [-FilePath] <string[]> -Match <string> [-Algorithm <string>] [-r]
|
||||||
.\checksum.ps1 -Check <string> [-Algorithm <string>] [-r]
|
.\checksum.ps1 -Check <string> [-Algorithm <string>] [-r]
|
||||||
.\checksum.ps1 -Help
|
.\checksum.ps1 -Help
|
||||||
@@ -58,40 +63,43 @@ PARAMETERS
|
|||||||
-FilePath <string[]>
|
-FilePath <string[]>
|
||||||
Specifies the target file(s) or wildcard pattern (*).
|
Specifies the target file(s) or wildcard pattern (*).
|
||||||
|
|
||||||
-o, -OutFile <string>
|
-o, -O
|
||||||
Enables auto-saving checksum results to file(s).
|
Auto-saves checksum results. (Takes no arguments).
|
||||||
- If passed with an argument (e.g. -o custom.txt), writes to 'custom.txt'.
|
- If input filename contains a wildcard (*), saves to 'checksums.<algo>'.
|
||||||
- If passed with NO argument (or empty string ""), automatically outputs to 'checksums.<algo>'.
|
- If input filename does NOT contain a wildcard, saves to '<filename>.<algo>'.
|
||||||
When combined with -r and *, recursively auto-generates checksum files per directory.
|
When combined with -r and *, recursively auto-generates checksums per directory.
|
||||||
|
|
||||||
-c, -Check <string>
|
-f, -F, -OutFile <string>
|
||||||
|
Saves checksum results to a specific custom filename.
|
||||||
|
Overrides the auto-naming behavior of -o if both are passed.
|
||||||
|
|
||||||
|
-c, -C, -Check <string>
|
||||||
Reads hashes from a specified checksum file and verifies target files on disk.
|
Reads hashes from a specified checksum file and verifies target files on disk.
|
||||||
If -r is specified, recursively looks for and validates checksum files by name across subdirectories.
|
If -r is specified, recursively looks for and validates checksum files by name across subdirectories.
|
||||||
|
|
||||||
-m, -Match <string>
|
-m, -M, -Match <string>
|
||||||
Compares the computed hash of target file(s) directly against a given hash string.
|
Compares the computed hash of target file(s) directly against a given hash string.
|
||||||
|
|
||||||
-a, -algo, -Algorithm <string>
|
-a, -A, -Algo, -Algorithm <string>
|
||||||
Specifies the hash algorithm to use.
|
Specifies the hash algorithm to use.
|
||||||
Supported options: SHA1, SHA256 (default), SHA384, SHA512, MD5.
|
Supported options: MD5, SHA1, SHA256 (default), SHA384, SHA512.
|
||||||
In -c or -m mode, auto-detects algorithm from hash length if omitted.
|
In -c or -m mode, auto-detects algorithm from hash length if omitted.
|
||||||
|
|
||||||
-r, -Recursive <switch>
|
-r, -R, -Recursive <switch>
|
||||||
Processes target files or verification files recursively across directory structures.
|
Processes target files or verification files recursively across directory structures.
|
||||||
|
|
||||||
-h, -Help <switch>
|
-h, -H, -Help <switch>
|
||||||
Displays this help documentation.
|
Displays this help documentation.
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
1. Compute SHA256 for a single file:
|
1. Compute SHA256 for a single file and auto-save as 'myfile.iso.sha256':
|
||||||
.\checksum.ps1 myfile.iso
|
.\checksum.ps1 myfile.iso -o
|
||||||
|
|
||||||
2. Compute SHA512 checksums recursively and auto-save (prompts for filename, hit Enter for auto):
|
2. Compute SHA512 recursively and auto-save as 'checksums.sha512' in each folder:
|
||||||
.\checksum.ps1 * -r -o -a SHA512
|
.\checksum.ps1 * -r -o -a SHA512
|
||||||
.\checksum.ps1 * -Recursive -OutFile "" -Algorithm SHA512
|
|
||||||
|
|
||||||
3. Compute SHA256 checksums and save to custom file:
|
3. Compute SHA256 checksums and save to a specific custom file:
|
||||||
.\checksum.ps1 * -o my_hashes.txt
|
.\checksum.ps1 * -f my_hashes.txt
|
||||||
|
|
||||||
4. Verify checksums against a verification file:
|
4. Verify checksums against a verification file:
|
||||||
.\checksum.ps1 -c checksums.sha256
|
.\checksum.ps1 -c checksums.sha256
|
||||||
@@ -296,10 +304,11 @@ process {
|
|||||||
if ([string]::IsNullOrWhiteSpace($Algorithm)) {$Algorithm = 'SHA256';
|
if ([string]::IsNullOrWhiteSpace($Algorithm)) {$Algorithm = 'SHA256';
|
||||||
};
|
};
|
||||||
|
|
||||||
$wantOutFile =$PSBoundParameters.ContainsKey('OutFile');
|
$wantCustomOut =$PSBoundParameters.ContainsKey('OutFile');
|
||||||
$isAutoFile = [string]::IsNullOrWhiteSpace($OutFile);
|
$wantAutoOut =$AutoOut.IsPresent;
|
||||||
|
|
||||||
if ($wantOutFile) {
|
if ($wantCustomOut -or$wantAutoOut) {
|
||||||
|
# Recursive wildcard auto-saves per directory
|
||||||
if ($Recursive -and$isWildcardGlobal) {
|
if ($Recursive -and$isWildcardGlobal) {
|
||||||
$groupedItems =$allItems | Group-Object DirectoryName;
|
$groupedItems =$allItems | Group-Object DirectoryName;
|
||||||
|
|
||||||
@@ -307,10 +316,9 @@ process {
|
|||||||
$dirPath =$group.Name;
|
$dirPath =$group.Name;
|
||||||
$filesInDir =$group.Group;
|
$filesInDir =$group.Group;
|
||||||
|
|
||||||
if ($isAutoFile) {
|
if ($wantCustomOut) {$currentOutFile = Join-Path -Path ($dirPath) -ChildPath ($OutFile);
|
||||||
$currentOutFile = Join-Path -Path ($dirPath) -ChildPath "checksums.$($Algorithm.ToLower())";
|
|
||||||
} else {
|
} else {
|
||||||
$currentOutFile = Join-Path -Path ($dirPath) -ChildPath ($OutFile);
|
$currentOutFile = Join-Path -Path ($dirPath) -ChildPath "checksums.$($Algorithm.ToLower())";
|
||||||
};
|
};
|
||||||
|
|
||||||
$linesToWrite = @();
|
$linesToWrite = @();
|
||||||
@@ -326,9 +334,12 @@ process {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ($isAutoFile) {$singleOutFile = "checksums.$($Algorithm.ToLower())";
|
# Custom file OR Auto file with a wildcard
|
||||||
} else {
|
if ($wantCustomOut -or ($wantAutoOut -and$isWildcardGlobal)) {
|
||||||
|
if ($wantCustomOut) {
|
||||||
$singleOutFile =$OutFile;
|
$singleOutFile =$OutFile;
|
||||||
|
} else {
|
||||||
|
$singleOutFile = "checksums.$($Algorithm.ToLower())";
|
||||||
};
|
};
|
||||||
|
|
||||||
$linesToWrite = @();
|
$linesToWrite = @();
|
||||||
@@ -346,8 +357,28 @@ process {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Set-Content -Path ($singleOutFile) -Value$linesToWrite -Encoding utf8;
|
Set-Content -Path ($singleOutFile) -Value$linesToWrite -Encoding utf8;
|
||||||
|
}
|
||||||
|
# Auto file for explicit individual files (No wildcard)
|
||||||
|
else {
|
||||||
|
foreach ($item in ($allItems)) {$hash = (Get-FileHash -Path ($item.FullName) -Algorithm ($Algorithm)).Hash.ToLower();
|
||||||
|
|
||||||
|
$relativePath = Resolve-Path -Path ($item.FullName) -Relative -ErrorAction 'SilentlyContinue';
|
||||||
|
if (-not $relativePath) { $relativePath =$item.Name; };
|
||||||
|
if ($relativePath.StartsWith(".\") -or $relativePath.StartsWith("./")) {
|
||||||
|
$relativePath =$relativePath.Substring(2);
|
||||||
|
};
|
||||||
|
|
||||||
|
$outputLine = "${hash}${relativePath}";
|
||||||
|
Write-Output $outputLine;
|
||||||
|
|
||||||
|
# Save directly next to the original file: <filename>.<algo>
|
||||||
|
$itemOutFile = "$($item.FullName).$($Algorithm.ToLower())";
|
||||||
|
Set-Content -Path ($itemOutFile) -Value$outputLine -Encoding utf8;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
# Standard console output (No save flags passed)
|
||||||
else {
|
else {
|
||||||
foreach ($item in ($allItems)) {$hash = (Get-FileHash -Path ($item.FullName) -Algorithm ($Algorithm)).Hash.ToLower();
|
foreach ($item in ($allItems)) {$hash = (Get-FileHash -Path ($item.FullName) -Algorithm ($Algorithm)).Hash.ToLower();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user