locked
Powershell: Simple script not working after RS5 upgrade RRS feed

  • Question

  • Since the latest upgrade to windows RS5, the following script has stopped working:

    Get-ChildItem -Recurse c:\images -Filter *.jpg | % {

        $image = [System.Drawing.Image]::FromFile($_.FullName)

        if ($image.width -gt 500 -and $image.height -gt 500) {

            New-Object PSObject -Property @{

                                  height_pixels = $image.Height

                                  width_pixels = $image.Width

                                  dpi = $image.HorizontalResolution

                                  megapixels = ($image.Height * $image.Width)/1000/1000

                                  megabytes = (($_.Length)/1024)/1024

                                  name = $_.Name

                                  fullname = $_.Fullname

                                  date = $_.LastWriteTime

            }

        }

    } | Export-Csv 'c:\images\img.csv' -NoTypeInformation

    Here is the error:

    Unable to find type [System.Drawing.Image].
    At line:2 char:14
    +     $image = [System.Drawing.Image]::FromFile($_.FullName)
    +              ~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (System.Drawing.Image:TypeName) [], RuntimeException

    Any help would be appreciated.

    Monday, October 29, 2018 5:45 PM

Answers

  • Does adding "add-type -assemblyname system.drawing" to the beginning of the script work?


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Monday, October 29, 2018 6:45 PM

All replies

  • Does adding "add-type -assemblyname system.drawing" to the beginning of the script work?


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Monday, October 29, 2018 6:45 PM
  • ***RESOLVED***

    Yes it did!!

    Thanks you.

    • Marked as answer by mediumRare13 Tuesday, October 30, 2018 4:13 PM
    • Unmarked as answer by mediumRare13 Tuesday, October 30, 2018 4:13 PM
    Monday, October 29, 2018 8:01 PM
  • Hi,

    Was your issue resolved? 
    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    Best Regards,

    Lee


    Just do it.

    Tuesday, October 30, 2018 3:06 AM
  • Thanks, I did.

    Tuesday, October 30, 2018 4:13 PM