Function Get - TextFromImage {

param (

[ Parameter ( Mandatory = $ true ) ] [ string ] $ File

)

# Requires 32bit Powershell Session

# Requires Office 2003 or 2007 Installation

Try {

$ FileObj = Get - ChildItem $ File

$ FilePath = $ FileObj . Fullname

If ( $ FileObj . Extension - ne ".jpg" - or ".jpeg" - or ".bmp" ) {

Write - Warning "$File does not have a known working extension, trying anyway..."

}

} Catch {

Write - Error "Error Retrieving $File:"

Write - Error $ _

Exit 1

}

Try {

$ MODIObj = New - Object - ComObject MODI . Document

} Catch {

Write - Error "Could not load MODI Com Object. Make sure you are running a 32bit Powershell sessio and have MS Office 2003/2007 installed."

Write - Error "If you have MS Office 2010, try this: http://support.microsoft.com/kb/982760"

Write - Error $ _

Exit 2

}

Try {

$ MODIObj . Create ( $ FilePath )

$ MODIObj . OCR ( )

$ Output = $ MODIObj . Images . Item ( 0 ) . Layout . Text . ToString ( ) . Trim ( )

Write - Output $ Output | Tee - Object - File $ ( $ FilePath + ".ocr.txt" )

} Catch {

Write - Error "Failed to process file:"

Write - Error $ _

Exit 3

}