【问题标题】:Powershell Win32Reg_AddRemovePrograms getting date outputPowershell Win32Reg_AddRemovePrograms 获取日期输出
【发布时间】:2013-12-26 10:45:27
【问题描述】:

如何让Win32Reg_AddRemovePrograms 中的InstallDate 按日/月/年显示?

这是我需要使用的命令

get-wmiobject -Class Win32Reg_AddRemovePrograms -ComputerName A电脑|其中 {$_.DisplayName -notlike "hotfix" -and $_.DisplayName -notlike "Security Update" -and $_.DisplayName -notlike "*Update for Windows *"} |选择显示名称、版本、发布者、安装日期

【问题讨论】:

    标签: date powershell output


    【解决方案1】:

    如果 InstallDate 看起来像 Win32_Product 类的 InstallDate(例如 20131209):

    [DateTime]::ParseExact('20131209','yyyyMMdd',$null).ToString('dd/MM/yyyy')
    

    【讨论】:

    • 感谢谢伊。正如我从另一个回复中看到的,这不会从 64 位安装的软件中获取信息。所以我想如果这是比使用 Win32_Product 更快的方法,我将需要从注册表中获取此信息。
    • 无论如何,据我所知,日期值的格式相同。
    【解决方案2】:

    只是为了让您知道 Win32Reg_AddRemovePrograms 类不是普通类,它是由 SMS/SCCM 添加的。它也只显示与 32 位程序相关的信息。 Source
    出于这个原因,我在车站没有可用的课程,也无法为您提供确切的步骤。请提供此命令的输出:

    $item = $gwmi Win32Reg_AddRemovePrograms | select -first 1
    $item.InstallDate
    $item.InstallDate.GetType().fullname
    

    【讨论】:

    • 感谢您指出它不会从 64 位程序中获取信息。
    【解决方案3】:

    一种方法是像下面的示例那样格式化日期。

    $date=Get-Date
    

    2013 年 12 月 9 日星期一上午 5:29:50

    $date.ToString("dd/MM/yyyy") 
    

    2013 年 9 月 12 日

    编辑: 我无权访问 Win32Reg_AddRemovePrograms,因此未经过测试。
    尝试将其添加到末尾:

       | %{ $_.InstallDate = ($_.InstallDate.tostring("dd/MM/yyyy") ); $_ }
    

    所以最后:(为换行添加了`)

    get-wmiobject -Class Win32Reg_AddRemovePrograms -ComputerName AComputer| `  
    where {$_.DisplayName -notlike "hotfix" -and $_.DisplayName -notlike "Security Update" -and $_.DisplayName -notlike "*Update for Windows *"} | `  
    select DisplayName,Version,Publisher,InstallDate | `  
    %{ $_.InstallDate = ($_.InstallDate.tostring("dd/MM/yyyy") ); $_ }
    

    或者如果它是像 Shay 提到的日期格式,

    | %{ $_.InstallDate = ([DateTime]::ParseExact($_.InstallDate,'yyyyMMdd',$null).ToString('dd/MM/yyyy')) ;$_}
    

    完整脚本:

    get-wmiobject -Class Win32Reg_AddRemovePrograms -ComputerName AComputer| `  
    where {$_.DisplayName -notlike "hotfix" -and $_.DisplayName -notlike "Security Update" -and $_.DisplayName -notlike "*Update for Windows *"} | `  
    select DisplayName,Version,Publisher,InstallDate | `  
    %{ $_.InstallDate = ([DateTime]::ParseExact($_.InstallDate,'yyyyMMdd',$null).ToString('dd/MM/yyyy')) ;$_}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-25
      • 1970-01-01
      • 2013-11-04
      • 1970-01-01
      • 1970-01-01
      • 2012-08-12
      相关资源
      最近更新 更多