question

GoceDimitroski-4791 avatar image
0 Votes"
GoceDimitroski-4791 asked SumanthMarigowda-MSFT edited

Powershell invoke-command open jpeg minimised

Hello,
I have written a PS script that opens and closes jpg in a directory via the invoke-command. (this is cause Azure File \Sync breaks images Thumbnail's )
But I want to do it so that it opens the jpg minimised

[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null

$folderForm = New-Object System.Windows.Forms.Form
$pathTextBox = New-Object System.Windows.Forms.TextBox
$selectButton = New-Object System.Windows.Forms.Button
$folderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
$openButton = New-Object System.Windows.Forms.Button
$okButton = New-Object System.Windows.Forms.Button
$cancelButton = New-Object System.Windows.Forms.Button
$finishButton = New-Object System.Windows.Forms.Button

<#
$formtext = New-Object System.Windows.Forms.Form
$formtext.Text = "Please Select the Directory that have the Pictures"
$formtext.Location = '20,45'
$formtext.KeyPreview = $True

$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Select the Directory"

$objForm.Size = New-Object System.Drawing.Size(300,200)

$objForm.StartPosition = "CenterScreen"

$objForm.KeyPreview = $True

>





$pathTextBox.Location = '23,23'
$pathTextBox.Size = '150,40'
$pathTextBox.ReadOnly = $true

$selectButton.Text = 'Select'
$selectButton.Location = '196,23'
$selectButton.Add_Click({
$folderBrowser.ShowDialog()
$pathTextBox.Text = $folderBrowser.SelectedPath
})

$openButton.Location = '40,90'
$openButton.text = 'Open Photo'
$openButton.Add_Click({

$PathsToSearch = @("C:\Temp")

$PathsToSearch = $folderBrowser.SelectedPath
$FailedItems = @()

$PathsToSearch | ForEach-Object {



 $Path = $_
 $JPGs = Get-ChildItem $Path | Where-Object { $_.Extension -eq ".jpg" -or $_.Extension -eq ".tif" } | Select-Object fullname -ExpandProperty fullname
 $Counter = 0

 Write-Host "Found $($JPGs.count) JPG files in ""$Path""" -ForegroundColor Green

 $JPGs | ForEach-Object {
 $Counter = $Counter + 1
 $JPG = $_
    
 #Open the picture

         Try{

             Invoke-Item $JPG -erroraction stop
                                
         }
         Catch{
             #write-host "Failed to open ""$JPG"". Skipping...." -foregroundcolor red
             $FailedItems += $JPG
         }
 
     Start-Sleep -Seconds 1

     #close the picture
     try {
         <# Kill TimerEmail Process as script is being attended to #>

         $process = Get-Process Microsoft.Photos -ErrorAction SilentlyContinue 
         $process.kill()
       #  Write-Warning "`t""$JPG"" closed."
     }
     catch {
      }
 
 }

}
Write-Host " PHOTOs are brought back . Please close the Application "

})



$cancelButton.Text = 'Cancel'
$cancelButton.Location = "56,215"
$finishButton.Text = 'Finish'
$finishButton.Location = "56,180"

$folderForm.CancelButton = $cancelButton
$folderForm.CancelButton = $finishButton

$folderForm.Text = 'Retrive Photo from Archive'
$folderForm.Controls.Add($pathTextBox)
$folderForm.Controls.Add($selectButton)
$folderForm.Controls.Add($openButton)
$folderForm.controls.Add($cancelButton)
$folderForm.controls.Add($finishButton)
$folderForm.ShowDialog()

END

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

Using Invoke-Item is the same as double-clicking the JPG file, and you have no control over how that works.

If you want to manage the window size you should be using Start-Process with the -WindowStyle parameter.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

GoceDimitroski-4791 avatar image
0 Votes"
GoceDimitroski-4791 answered GoceDimitroski-4791 commented

I did try it with start-process $ JPG -windowstyle minimised
but it still bring up the image.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

My guess is that you're still using the "Photos" application in Windows 10. While that runs as a window, it runs as part of dllhost.exe. Try running some other application that runs on its own to show that jpg.

0 Votes 0 ·

Tthe reason why I have selected MS photos is casue it is built into every Pc here.
But if it cant be done thats ok. The image comes up for less than a 1sec. I have adjusted the time.

0 Votes 0 ·