如何在 powershell windows 7 中使用 Microsoft.Update.Session()?

发布于 2025-01-18 10:18:07 字数 424 浏览 3 评论 0原文

我想从Windows导出更新历史记录(已安装的KB)列表。 对于Windows 10,我发现了正在打击的代码:

$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$Searcher.QueryHistory(0, $Searcher.GetTotalHistoryCount()) | Export-Csv -Encoding UTF8 -Path D:\$env:computername+KB.csv -NoTypeInformation

但是,由于某些代码错误,我无法在Windows 7下使用它。

有人知道如何修复在Windows 7下运行的代码吗? 还是还有其他方法可以获取已安装的KB列表?

I want to export the update history(installed KB) list from Windows.
To Windows 10, I found the code under blow:

$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$Searcher.QueryHistory(0, $Searcher.GetTotalHistoryCount()) | Export-Csv -Encoding UTF8 -Path D:\$env:computername+KB.csv -NoTypeInformation

However, I can't use it under Windows 7, because of some code error.

Does anyone know how to repair the code to run under Windows 7 ?
or have any other way to get the installed KB list ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别靠近我心 2025-01-25 10:18:07

通过 Google 快速搜索,DISM 也适用于 Window 7。它可以以列表格式输出。

如果您以管理员身份打开 PowerShell 窗口,则可以运行:

PS C:\image_build> dism /format:Table /online /Get-Packages

Deployment Image Servicing and Management tool
Version: 10.0.22000.653

Image Version: 10.0.22000.978

Packages listing:


---------------------------------------------------------------------------------------------------- | ---------- | --------------- | ------------------
Package Identity                                                                                     | State      | Release Type    | Install Time
---------------------------------------------------------------------------------------------------- | ---------- | --------------- | ------------------
Microsoft-OneCore-ApplicationModel-Sync-Desktop-FOD-Package~31bf3856ad364e35~amd64~~10.0.22000.675   | Superseded | OnDemand Pack   | 12/05/2022 3:45 AM
Microsoft-OneCore-ApplicationModel-Sync-Desktop-FOD-Package~31bf3856ad364e35~amd64~~10.0.22000.918   | Installed  
....
/truncated/
....

我不确定 DISM 是否默认随 Windows 7 一起提供。您可能需要下载和/或启用它。

注意:上面的命令和输出来自 Windows 11,而不是 Windows 7。

From a quick Google search DISM is available for Window 7 as well. It can output in a list format.

If you open a PowerShell windows as Administrator, you can run:

PS C:\image_build> dism /format:Table /online /Get-Packages

Deployment Image Servicing and Management tool
Version: 10.0.22000.653

Image Version: 10.0.22000.978

Packages listing:


---------------------------------------------------------------------------------------------------- | ---------- | --------------- | ------------------
Package Identity                                                                                     | State      | Release Type    | Install Time
---------------------------------------------------------------------------------------------------- | ---------- | --------------- | ------------------
Microsoft-OneCore-ApplicationModel-Sync-Desktop-FOD-Package~31bf3856ad364e35~amd64~~10.0.22000.675   | Superseded | OnDemand Pack   | 12/05/2022 3:45 AM
Microsoft-OneCore-ApplicationModel-Sync-Desktop-FOD-Package~31bf3856ad364e35~amd64~~10.0.22000.918   | Installed  
....
/truncated/
....

I'm not sure if DISM comes with Windows 7 by default. You may need to download and/or enable it.

NOTE: The command and output above are from Windows 11 and not Windows 7.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文