Last active
November 10, 2022 15:08
-
-
Save mcc85s/5a8f25313ba0cb7e622e0aaab5d27ce5 to your computer and use it in GitHub Desktop.
For downloading any file, assuming a default location, and immediately obtaining and displaying the SHA256 output of said file once it is downloaded
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Gather-Download | |
{ | |
[CmdLetBinding()]Param( | |
[ValidateNotNullOrEmpty()] | |
[Parameter(Position=0,Mandatory)][String]$URL, | |
[Parameter(Position=1)][String]$Path="$Home\Downloads", | |
[Parameter(Position=2)][String]$Info=$URL, | |
[Parameter(Position=3)][Switch]$Hash) | |
Import-Module BitsTransfer | |
$Current = [Net.ServicePointManager]::SecurityProtocol | |
[Net.ServicePointManager]::SecurityProtocol = 3072 | |
$File = @{ | |
Source = $URL | |
Destination = "$Path\{0}" -f $URL.Split('/')[-1]| | |
Description = $Info | |
} | |
Start-BitsTransfer @File | |
$File | ? JobState -match "(Transferring|Connecting)" | % { Start-Sleep -M 150 } | |
Switch ($File.JobState) | |
{ | |
Transferred | |
{ | |
Complete-BitsTransfer -BitsJob $File | |
} | |
Error | |
{ | |
$File | Format-List | |
} | |
} | |
[Net.ServicePointManager]::SecurityProtocol = $Current | |
Return [Ordered]@{ | |
Item = $File.Description | |
URL = $File.Source | |
Save = $File.Destination | |
Hash = If ($Hash) { Get-FileHash $File.Destination -Algorithm SHA256 | % Hash } Else { $Null } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment