So well, I am making a pull request to Chris Titus Tech's Ultimate Windows Toolkit, and I wanna make something that checks if it's updated. But when I try running:
Get-FileHash -Algorithm SHA256 https://raw.githubusercontent.com/fgclue/etcher/master/desktop.ini
It just says:
Get-FileHash: Cannot find drive. A drive with the name 'https' does not exist. And I want to make it look something like this:
$hash = Get-FileHash -Algorithm SHA256 URL
$chash = Get-FileHash -Algorithm SHA256 win10debloat.ps1
if ($hash -ne $chash){
Write-Host "There is an update!"
Write-Host "Update?"
$Opt = Read-Host "Choice"
if (Opt -ne y){
exit
}
if (Opt -ne yn){
Start-Process "https://github.com/ChrisTitusTech/win10script/"
Write-Host Please download the new version and close this windows.
}
}
You can use the WebResponseObject.RawContentStream
Property from the object outputted by Invoke-WebRequest
to check if the remote file and the local file are the same:
$uri = 'https://raw.githubusercontent.com/fgclue/etcher/master/desktop.ini'
$req = Invoke-WebRequest $uri
# get the hash of the local file
$localHash = Get-FileHash myfilehere.ext -Algorithm SHA256
# get the remote file hash
$remoteHash = Get-FileHash -InputStream $req.RawContentStream -Algorithm SHA256
# and compare
if($localHash.Hash -eq $remoteHash.Hash) {
'all good'
}
else {
'should update here'
}