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.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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.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 = $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()
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.
I did try it with start-process $ JPG -windowstyle minimised
but it still bring up the image.