好吧,我正在向 Chris Titus Tech 的 Ultimate Windows Toolkit 提出拉取請求,我想做一些檢查它是否更新的東西。但是當我嘗試運行時:
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.
}
}
uj5u.com熱心網友回復:
我不完全確定您實際上想要比較什么,但這里是您如何測驗您所擁有的是否是最新的,而無需將任何內容下載到您的磁盤上,在這種情況下,我相信您需要使用IO.MemoryStream來獲取遠程的哈希檔案。
可能有更好的方法,還請注意,此代碼使用UTF8帶有 BOM 的編碼來獲取遠程檔案位元組,您需要確保編碼正確,即:如果您需要UTF8 沒有 BOM,請[System.Text.UTF8Encoding]::new().GetBytes(...)改用。
$uri = 'https://raw.githubusercontent.com/fgclue/etcher/master/desktop.ini'
$theHashIHave = Get-FileHash myfilehere.ext -Algorithm SHA256
try {
$content = Invoke-RestMethod $uri
$memstream = [System.IO.MemoryStream]::new(
[System.Text.Encoding]::UTF8.GetBytes($content)
)
$thisFileHash = Get-FileHash -InputStream $memstream -Algorithm SHA256
if($theHashIhave.Hash -eq $thisFileHash.Hash) {
"all good"
}
else {
"should update here"
}
}
finally {
$memstream.foreach('Dispose')
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/462208.html
