Display PowerShell Remote Session Connection progress in a startup splash form

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
MDinice
Posts: 20
Joined: Sat Apr 30, 2016 10:53 am

Display PowerShell Remote Session Connection progress in a startup splash form

Post by MDinice » Fri Mar 23, 2018 1:47 pm

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: PowerShell Studio 2018 v5.5.150
32 or 64 bit version of product: 64 bit
Operating system: Win 10
32 or 64 bit OS: 64 bit


*** Please add details and screenshots as needed below. ***

I have a multi-form project that manages On-Prem and Office 365 Exchange. I would like to be able to load a splash form and display the progress of the PowerShell Modules loading for the remote session and have the session available to the main form.

Splash.PNG
Splash.PNG (7.45 KiB) Viewed 1555 times

The splash form will close when loading is complete and if no errors will load the main form where actions would be performed on objects in the session. I have a couple of issues.
1. The progress bar does not display the full 100% even thought the calculation gets to 100%.
2. loading exchange online throws an access denied error when tried in PS Studio but when the same code is run in my powershell profile in a console window it connects fine using the same credentials.

Any insight on whether or not what I am trying to do is possible or i'm just missing something. I am sort of faking the progress because it is not easily available when the modules actually load (or at least i'm not sure how to get it) by loading the modules wrapped in a measure command and calculating percentage off of the Milliseconds like the following:

$Prog = Measure-Command {
Import-Module ActiveDirectory -ErrorAction Stop | Out-Null
}

$MS = $Prog.Milliseconds

# Update Progress Bar Values
For($X = 0; $X -lt $MS; $X++) {
Start-Sleep -Milliseconds 15

$Pct = [int](($X/$MS) * 100)
$progbarInitProgress.Value = $Pct
}

$progbarInitProgress.Value = 100

I have a zip file of the scaled down project to show what i'm trying to do if you have somewhere where I can upload it. I don't really want to attach it here. I will if necessary.

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: Display PowerShell Remote Session Connection progress in a startup splash form

Post by davidc » Mon Mar 26, 2018 9:43 am

You can zip and upload files using the following link:

https://www.sapien.com/support/upload

Or attached them directly to this topic.

As for your questions:

1. Since the process bar is animated, it might take a little time before the animation completes. This also depends on how you are handling the loop with the progress bar. Refer to the following article:

https://info.sapien.com/index.php/guis/ ... sive-loops

You can try adding a little delay after the progress is set to 100% by using a timer control to close the form.

https://info.sapien.com/index.php/guis/ ... er-control


2. Make sure you are running the script with elevation and that you are using the same platform settings (x86 vs x64):
Elevate.png
Elevate.png (6.34 KiB) Viewed 1408 times
Some cmdlets may require you to run them in Job otherwise they may get hung up. I'm not sure if these cmdlets are affected, but if they are, try using the Job Tracker control set. Refer to the following article for more details:

https://info.sapien.com/index.php/guis/ ... sive-forms
David
SAPIEN Technologies, Inc.