Skip to content

Instantly share code, notes, and snippets.

@FooBartn
Last active April 6, 2017 21:38
Show Gist options
  • Select an option

  • Save FooBartn/5ea2c79c305ccfd50a01b93115716536 to your computer and use it in GitHub Desktop.

Select an option

Save FooBartn/5ea2c79c305ccfd50a01b93115716536 to your computer and use it in GitHub Desktop.

Revisions

  1. FooBartn revised this gist Apr 6, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Get-ImageTakenDate.ps1
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ function Get-ImageTakenDate {

    } catch {
    if ($_.Exception -like '*Property cannot be found*') {
    Write-Error 'Unable to get creation date from image.'
    Write-Error 'Could not find date image was taken.'
    } else {
    Write-Error $_
    }
  2. FooBartn revised this gist Apr 6, 2017. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions Get-ImageTakenDate.ps1
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,9 @@ function Get-ImageTakenDate {
    )

    try {
    $DrawingLibrary = [reflection.assembly]::loadfile( "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll")
    $ImageBitmap = New-Object System.Drawing.Bitmap($Path) -ErrorAction Stop
    $DrawingLibrary = [reflection.assembly]::LoadWithPartialName("System.Drawing");
    $FullObjectPath = (Get-Item $Path -ErrorAction Stop).FullName
    $ImageBitmap = New-Object System.Drawing.Bitmap($FullObjectPath) -ErrorAction Stop
    [byte[]]$ByteDate = $ImageBitmap.GetPropertyItem(36867).Value
    [string]$DateString,[string]$TimeString = [System.Text.Encoding]::ASCII.GetString($ByteDate).Split(' ')

  3. FooBartn created this gist Apr 6, 2017.
    39 changes: 39 additions & 0 deletions Get-ImageTakenDate.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    function Get-ImageTakenDate {
    [CmdletBinding()]
    param (
    # Path
    [Parameter(Mandatory)]
    [string]
    $Path
    )

    try {
    $DrawingLibrary = [reflection.assembly]::loadfile( "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll")
    $ImageBitmap = New-Object System.Drawing.Bitmap($Path) -ErrorAction Stop
    [byte[]]$ByteDate = $ImageBitmap.GetPropertyItem(36867).Value
    [string]$DateString,[string]$TimeString = [System.Text.Encoding]::ASCII.GetString($ByteDate).Split(' ')

    $Year,$Month,$Day = $DateString.Split(':')
    $Hour,$Minute,$Second = $TimeString.Split(':')

    $DateTimeParams = @{
    Year = $Year
    Month = $Month
    Day = $Day
    Hour = $Hour
    Minute = $Minute
    Second = $Second
    }

    Get-Date @DateTimeParams

    } catch {
    if ($_.Exception -like '*Property cannot be found*') {
    Write-Error 'Unable to get creation date from image.'
    } else {
    Write-Error $_
    }
    } finally {
    $ImageBitmap.Dispose()
    }
    }