-1

I am using a ssm command to describe instance patches, while getting the output the installedtime is in unspecified format, so how to convert it to the format of mm/dd/yy

aws ssm describe-instance-patches --instance-id "XXXXXX" --profile "XXXXXX" --region "us-west-2"  --max-results 10 --output table 

The default output of the ssm command is json

output:

|| Classification | InstalledTime | KBId | Severity | State | Title
|| CriticalUpdates | 1476770400.0 | KB3199209 | Unspecified | Installed | Update for Windows Server 2016 for x64-based Systems (KB3199209)
|| CriticalUpdates | 1479193200.0 | KB3199986 | Unspecified | Installed | Update for Windows Server 2016 for x64-based
  • 3
    Please [edit](https://stackoverflow.com/posts/63226852/edit) your question and show the output as formatted **text** instead of a link to a barely readable image. – Theo Aug 03 '20 at 10:04
  • 3
    You will need to give some specifications of the date format as e.g. whether the day is prior the month (or not). E.g.: '01-02-2020': **January 2nd** or **February 1st**? – iRon Aug 03 '20 at 10:06
  • 2
    Downvoted question until image is replaced with output. – Daniel Björk Aug 03 '20 at 10:14
  • Does this answer your question? [A Powershell function to convert unix time to string?](https://stackoverflow.com/questions/5779244/a-powershell-function-to-convert-unix-time-to-string) and [PowerShell date format](https://stackoverflow.com/q/23616614/1701026) – iRon Aug 03 '20 at 10:45

2 Answers2

0

Update your question with the output instead of an Image.

The dateformat is not unspecified format, it is Unix format.

To convert from Unix format to a DateTime variable do like this:

$oUNIXDate=(Get-Date 01.01.1970)+([System.TimeSpan]::fromseconds(1476770400))

I cant test this but you can probably do something like this to convert the output afterwards:

aws ssm describe-instance-patches --instance-id "XXXXXX" --profile "XXXXXX" --region "us-west-2"  --max-results 10 --output table | select-object Classification, @{ Name = 'TimeStamp'; Expression = {  ((Get-Date 01.01.1970)+([System.TimeSpan]::fromseconds($_.InstalledTime))) }}, KBId, Severity, State, Title
Daniel Björk
  • 2,475
  • 1
  • 19
  • 26
0

This script work like as expected

    $instances= aws ssm describe-instance-patches --instance-id "xxxxxxx" --profile "xxxxxxx" --region "us-west-2"  --max-results 50
$pathToOutputFile = "C:\Users\Documents\prod_instance_us_west_2.csv"
$array = ($instances| ConvertFrom-Json) | Select-Object -ExpandProperty Patches

$report = @()
foreach($a in $array)
{
    $report += New-Object psobject -Property @{Title=$a.Title;KBId=$a.KBId;Classification=$a.Classification;Severity=$a.Severity;State=$a.State;InstalledTime=[TimeZone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($a.InstalledTime))}
}
$report | export-csv $pathToOutputFile