Private/ConvertFrom-UnixTime.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Function ConvertFrom-UnixTime {
<#
.SYNOPSIS
  ConvertFrom-UnixTime converts Unix timestamps to a PowerShell datetime object.
.PARAMETER UnixTime
  And integer representing the unix formatted time.
.EXAMPLE
  1489664257 | ConvertFrom-UnixTime
.EXAMPLE
  ConvertFrom-UnixTime -UnixTime 1489664257
.LINK
  https://gallery.technet.microsoft.com/scriptcenter/Write-Log-PowerShell-999c32d0
#>
  
    Param(
        [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
        [Int32]$UnixTime
    )

    BEGIN {
        $StartDate = Get-Date â€“Date '01/01/1970' 
    }
    PROCESS {
        $TimeSpan = New-Timespan -Seconds $UnixTime
        $StartDate + $TimeSpan
    }
}