一种方法是像下面的示例那样格式化日期。
$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')) ;$_}