Last active
April 6, 2017 21:38
-
-
Save FooBartn/5ea2c79c305ccfd50a01b93115716536 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-ImageTakenDate { | |
[CmdletBinding()] | |
param ( | |
# Path | |
[Parameter(Mandatory)] | |
[string] | |
$Path | |
) | |
try { | |
$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(' ') | |
$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 'Could not find date image was taken.' | |
} else { | |
Write-Error $_ | |
} | |
} finally { | |
$ImageBitmap.Dispose() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment