如何检查PowerShell中在线文件的filehash?

dhxwm5r4  于 2023-04-21  发布在  Shell
关注(0)|答案(1)|浏览(122)

所以,我正在向Chris Titus Tech的Ultimate Windows Toolkit发出一个pull request,我想做一些检查它是否更新的东西。但是当我尝试运行时:

Get-FileHash -Algorithm SHA256 https://raw.githubusercontent.com/fgclue/etcher/master/desktop.ini

它只是说:
Get-FileHash:找不到驱动器。名称为“https”的驱动器不存在。我想让它看起来像这样:

$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.
     }
}
zbdgwd5y

zbdgwd5y1#

您可以使用Invoke-WebRequest输出的对象的WebResponseObject.RawContentStream属性来检查远程文件和本地文件是否相同:

$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'
}

相关问题