Splashscreen in project

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 10 months and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Mekac_CZ
Posts: 9
Last visit: Fri May 19, 2023 6:13 am

Splashscreen in project

Post by Mekac_CZ »

Hello,
i made a GUI for managing exchange quarantine.

In startup.pss I added connection to Exchange Online. The connection needs to be done before main form appear (viewtopic.php?t=16278) .

I want to add a splashscreen for the duration of the connection (it takes few seconds).
Bonus: would be great if it shows the connection progress for the connect-exchangeonline cmdlet
VERBOSE: Exporting cmdlet 'Find-Package'.
VERBOSE: Exporting cmdlet 'Find-PackageProvider'.
VERBOSE: Exporting cmdlet 'Get-Package'.
..

I tried to create simple form in startup.pss

Code: Select all

$form1.ShowDialog() | Out-Null
connect-exchangeonline @params
$form1.close() | Out-Null

.. but the connection wont happen while custom splash form is opened (blocked by showdialog() method).

I also tried the tool "Form - splash screen" but it only adds to MainForm.psf ..

A little guidenance would help..
User avatar
Mekac_CZ
Posts: 9
Last visit: Fri May 19, 2023 6:13 am

Re: Splashscreen in project

Post by Mekac_CZ »

Oh wait.. just realized im back to this problem:
Windows Forms threading model and the Microsoft Exchange PowerShell module are not compatible.
Generally the consensus is that you need to establish this connection before you initialize your form.

So.. I am screwed.
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Splashscreen in project

Post by Alexander Riedel »

Nah. Just need to get out of the box. Launch an external process with your splash screen and kill it once you are finished loading.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
Mekac_CZ
Posts: 9
Last visit: Fri May 19, 2023 6:13 am

Re: Splashscreen in project

Post by Mekac_CZ »

Alexander Riedel wrote: Thu May 18, 2023 11:33 am Nah. Just need to get out of the box. Launch an external process with your splash screen and kill it once you are finished loading.
Thanks for tip.

Ended up (for now) with this solution

Code: Select all

$scriptblock = {...} #contains form dialog with property   $form1.Text = "ExO Quarantine Manager" 

$Runspace = [runspacefactory]::CreateRunspace()
$Runspace.Open()
$PowerShell = [powershell]::Create()
$PowerShell.Runspace = $Runspace
$PowerShell.AddScript($ScriptBlock)
$PowerShell.BeginInvoke()

Connect-ExchangeOnline -ShowBanner:$false @connectsplat -verbose
## kill the form dialog
$process = get-process | ?{ $_.mainwindowtitle -eq "ExO Quarantine Manager" }
$process.CloseMainWindow()
This topic is 10 months and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked