Skip to content

Instantly share code, notes, and snippets.

@FooBartn
Last active April 6, 2017 21:38
Show Gist options
  • Save FooBartn/5ea2c79c305ccfd50a01b93115716536 to your computer and use it in GitHub Desktop.
Save FooBartn/5ea2c79c305ccfd50a01b93115716536 to your computer and use it in GitHub Desktop.
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