【问题标题】:PowerShell report on applied windows updates after a datePowerShell 报告某个日期后应用的 Windows 更新
【发布时间】:2013-11-21 14:21:49
【问题描述】:

我正在尝试从给定日期通过 SCCM v12 获取有关在 Windows Server 2003 和 2008 服务器上安装了哪些 Windows 更新的信息。为此,我使用 PowerShell 的 Get-Hotfix cmdlet。

但是我遇到了一个问题,现在我将解释:

Get-HotFix -ComputerName SERVER01 | where-object {$_.hotfixid -ne "file 1"}  | Select description,hotfixid,installedby,InstalledOn | sort installedon

返回修补程序,但没有很多日期。我知道这是一个问题,所以要解决这个问题,您需要像这样运行它:

Get-HotFix -ComputerName SERVER01 | where-object {$_.hotfixid -ne "file 1"}  | Select description,hotfixid,installedby,@{l="InstalledOn";e={[DateTime]::Parse($_.psbase.properties["installedon"].value,$([System.Globalization.CultureInfo]::GetCultureInfo("en-US")))}}  | sort installedon

然后返回大多数日期......但不是全部。所以接下来我想只从某个日期安装更新,所以我运行它来做到这一点。

$date = Get-Date '26/07/2013'

Get-HotFix -ComputerName SERVER01 | where-object {$_.hotfixid -ne "file 1"}  | where "InstalledOn" -gt $date  | Select description,hotfixid,installedby,@{l="InstalledOn";e={[DateTime]::Parse($_.psbase.properties["installedon"].value,$([System.Globalization.CultureInfo]::GetCultureInfo("en-US")))}} | sort installedon

但这不会返回任何更新或错误。但是,我知道自此日期以来已经应用了更新,因为我在第二个命令结果中看到了这些更新。

所以问题是我做错了什么?还有其他方法可以通过 SCCM 吗?

【问题讨论】:

  • where "InstalledOn" -gt $date 应该是 "InstalledOn" -le $date 所在的位置,您将找不到比今天晚安装的数据。
  • 谢谢,但输出全部。我需要在 $date 之后安装 HotFixes

标签: windows powershell report updates


【解决方案1】:

我认为你可能过于复杂了:

get-hotfix | Where-Object {$_.installedon -gt (get-date).addmonths(-2)} | Sort-Object -property installedon -Descending

【讨论】:

    【解决方案2】:
    Get-HotFix -ComputerName SERVER01 | where-object {$_.hotfixid -ne "file 1"} | Select description,hotfixid,installedby,@{l="InstalledOn";e={[DateTime]::Parse($_.psbase.properties["installedon"].value,$([System.Globalization.CultureInfo]::GetCultureInfo("en-US")))}} | where-object {$_.installedon –gt $date} | sort installedon -descending
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-26
      • 1970-01-01
      • 2014-07-25
      • 1970-01-01
      • 2013-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多