Author Posts

March 6, 2018 at 8:22 am

Hello PowerShell Experts,

I have the following code in a PowerShell script.
 
###########################################################
# HEADER IMAGE
###########################################################
 
$Img1 = [system.drawing.image]::FromFile(".\images\001.png")
$PictureBox1 = New-Object Windows.Forms.PictureBox
$PictureBox1.Location = New-Object System.Drawing.Size(0,0)
$PictureBox1.Size = New-Object System.Drawing.Size(1200,400)
$PictureBox1.Image = $Img1
 
When I execute it via ISE – I get an error, the form loads but the image doesn't
Exception calling "FromFile" with "1" argument(s): ".\images\001.png"
 
Oddly if I open a cmd window, navigate to the forms directory, run PowerShell and execute it from there it loads fine – ever come across this type of thing before?
 
What I don't want is the form to error during a “deployment” of it via SCCM if that makes sense.

Regards, Darren

March 6, 2018 at 2:27 pm

Can you paste the actual exception text here but my first strong guess is that it is simply that you are trying to use a relative path for the image and it is throwing the exception of "not found" when using the ISE but works in shell because you are then executing where the relative path will work. Have you simply tried changing your png to the full path?