Powershell button image

button, image, powershell-3.0

Solution

You picked a cool language to do .Net development in!! It's a bit difficult though, since there is very little documentation to help out.

Instead of using System.Controls.Image, try System.Drawing.Image:

Add-Type -Assembly System.Drawing
$image = [System.Drawing.Image]::FromFile("C:\users\Administrator\Desktop\Avengers.jpg")
$button.Image = $image

Problem

I'm trying to use jpgs for button images in a Powershell form. I tried this code: ``` #Add Image to Button $image = New-Object System.Windows.Controls.Image $image.Source = "C:\users\Administrator\Desktop\Avengers.jpg" $image.Stretch = 'Fill' $button.Content = $image ``` From: http://learn-powershell.net/2012/10/01/powershell-and-wpf-buttons/ The script is throwing an error: Cannot find type[System.Controls.Image]: Make sure the assembly containing this type is loaded. I tried to use another assembly from the script to figure this one out: [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') I'm stuck on version, culture, and PublicKeyToken (I started the script in Powershell Studio, but I'm finishing it in Notepad++). How can I best get this information? Thank you.

Original source