[英]Install Windows Updates from a folder & return the status installed or not
我需要幫助來驗證從文件夾安裝的更新的狀態,這是下面的腳本。
# Specify the location of the *.msu files
$updatedir = "C:\install\hvpatches"
foreach ($msu in $msus)
{
write-host "Installing update $msu ..."
$fullname = $msu.fullname
# Need to wrap in quotes as folder path may contain spaces
$fullname = "`"" + $fullname + "`""
###
$files = Get-ChildItem $updatedir -Recurse
$msus = $files | ? {$_.extension -eq ".msu"}
# Specify the command line parameters for wusa.exe
$parameters = $fullname + " /quiet /norestart"
# Start wusa.exe and pass in the parameters
$install = [System.Diagnostics.Process]::Start( "wusa",$parameters )
$install.WaitForExit()
write-host "Finished installing $msu"
}
Windows更新是從上面的腳本安裝的,我想要的是一種驗證這些更新是否正確安裝或在安裝失敗時提供狀態的方法。
我希望我們一些強大的專家幫助我:)
謝謝,Vinith!
我幾乎不是PS專家,但是前段時間我在不同背景下檢查更新,所以也許我的建議對您有用。
要點。 嘗試調用我之前寫下的代碼段:
$session = New-Object -ComObject Microsoft.Update.Session
$searcher = $session.CreateUpdateSearcher()
$result = $searcher.Search("IsInstalled=1 and Type='Software'" )
$result.Updates | get-member
一段時間后(有點慢),您將獲得可以檢查的內容列表。 我不知道關於正在安裝的這些更新有什么信息,但是這里有些有用的信息,例如Title
或KBArticleIDs
號(希望包含一些相關信息)。 然后,將最后一行替換為所需的內容,例如
$result.Updates | select Title
並與有關最近安裝的更新的數據進行比較。
抱歉,答案不完整-我當前的Windows框出現了一些問題,上述代碼無法像我所記得的那樣正常工作。 請毫不猶豫地指出是否完全錯誤,這是人道的錯誤! ;)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.