
我正在嘗試自動化我工作的圖書館的整個更新過程。我編寫了一個簡單的腳本,讓我可以使用 Chocolatey 更新所有軟體包並使用 PSWindowsUpdate 模組執行 Windows 更新。但是,在使用 PSWindowsUpdate 隱藏 Windows 更新時,我遇到了一些困難。根據我讀過的各種線上文章/文檔,這似乎很簡單,但由於某種原因對我不起作用。我有特別參考過這個 Stackoverflow 問題並嘗試應用已接受的答案作為我的解決方案,但沒有牛肉。這裡的答案也沒有完全達到我想要完成的目標。首先讓我提供一些背景:
背景
我有 5 個 Windows 10 Pro 系統和 11 個 Windows 7 Pro 系統。全部都是 64 位元。 Windows 7系統先前已全部更新至WMF 5.1。我正在使用遠端桌面企業版同時在多台電腦上執行腳本,以幫助我簡化更新過程。
我嘗試過的
我花了相當多的時間試圖透過各種 Google 搜尋以及對 PS 腳本的反覆試驗來解決我自己的問題。當我在遠端電腦上執行腳本時,一切都運行和更新得很好。正如我已經提到的,問題在於它並不總是隱藏我指定的 Windows 更新(因為我可能在某個地方搞砸了哈哈)。這是我的腳本:
#This script will update all chocolatey packages and will also download install any new Windows Updates
#Begin ExecutionPolicy Set
Echo "Setting Execution Policy Settings"
Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy RemoteSigned -Force -Confirm:$false
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force -Confirm:$false
Echo "Initializing Unattended Update Automation Powershell Script"
#Begin Chocolatey Update
Echo "Updating Chocolatey Packages"
#Remove Java and reinstall 64-bit only
cuninst jre8 -y
cinst jre8 -PackageParameters "/exclude:32" -y
#Queries Chocolatey.org database for updates to locally installed packages and updates them if necessary
cup all -y --ignore-checksums
#Begin Windows Update
Echo "Enabling Windows Update Services"
Get-Service bits, wuauserv | Set-Service -StartupType manual
Echo "Copying Module PSWindowsUpdate to PowerShell Modules Folder"
#Grabs copy of PSWindowsUpdate Module and copies it to remote machine
Copy-Item -Path \\DIROFFICE\WindowsUpdate\PSWindowsUpdate -Destination C:\Windows\System32\WindowsPowerShell\v1.0\Modules -recurse -force
Echo "Importing Powershell Module PSWindowsUpdate"
Import-Module -Name PSWindowsUpdate -force
refreshenv
Echo "Enabling updates for additional Microsoft components and software"
Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d -Confirm:$false
Echo "Querying Microsoft Update Server for Windows Updates"
Get-WUList -MicrosoftUpdate
Echo "Hiding Unnecessary Updates"
Hide-WUUpdate -Title "Update for Microsoft OneDrive" -HideStatus:$true -Confirm:$false
Echo "Downloading and Installing Windows Updates"
Get-WUInstall -MicrosoftUpdate -acceptall
Echo "Stopping Windows Update Services"
Get-Service bits,wuauserv | Stop-Service
Echo "Setting CurrentUser Execution Policy Back to RemoteSigned"
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force -Confirm:$false
問題/問題
我想要最終完成的是根據更新標題中出現的某些關鍵字隱藏某些更新。例如,我們在所有電腦上安裝了 Microsoft 2016,但我希望能夠隱藏 W10 和 W7 電腦上的所有 Outlook、OneDrive、Visio 和 Skype 更新,以及 W7 電腦上的 Microsoft Security Essentials。有沒有有效的方法可以使用 PSWindowsUpdate 模組來隱藏包含某些單字的更新?
補充筆記
我的腳本中隱藏更新部分下列出的一小行程式碼僅用於測試目的。我最初嘗試使用所述更新的完整標題來隱藏更新。例如,Outlook 2016 有許多更新,其標題要么是“Microsoft Outlook 2016 的安全性更新”,要么只是簡單的“Microsoft Outlook 2016 的更新”。我嘗試使用Hide-WUUpdate -Title "Update for Microsoft Outlook" -HideStatus:$true -Confirm:$false
以及Hide-WUUpdate -Title "Security update for Microsoft Outlook" -HideStatus:$true -Confirm:$false
。這似乎不起作用,因為當我查看已安裝的更新時,它顯示已安裝 4 或 5 個 Microsoft Outlook 更新。
我也嘗試過使用通配符(*),但我認為我並不完全理解它是如何工作的。我嘗試了一些類似Hide-WUUpdate -Title "Update for Microsoft Outlook*" -HideStatus:$true -Confirm:$false
和 的事情Hide-WUUpdate -Title "Outlook*" -HideStatus:$true -Confirm:$false
。我什至嘗試使用雙通配符,例如Hide-WUUpdate -Title "*Microsoft Oulook*" -HideStatus:$true -Confirm:$false
.
根據我在 TechNet 和 MSDN 上讀到的內容,(*) 通配符將匹配從指定位置開始的字元。如果包含空格的話會崩潰嗎?
使用知識庫文章 ID 不是我的首選方法,因為每次我都必須使用需要隱藏的新知識庫 ID 來更新腳本。如果可能的話,我更喜歡關鍵字方法。我確實嘗試使用上面 Stackoverflow 參考中列出的方法,只是為了咧嘴一笑,但這並不是我現在正在尋找的最終解決方案。
答案1
Hide-WUUpdate
可能不支援一次更新多筆記錄。
在 Powershell 中,常見的方法是縮小管道前面的物件範圍,然後將它們傳送到管道末端的操作(例如Get-Process notepad | Stop-Process
)。如果Hide-WUUpdate
接受物件作為輸入,這僅適用於這種情況。它可能不會,只允許與其-Title
標誌一起使用,這可能不支援多個條目。