How to get status update after executing command

Hi,

I have created a form which takes input (like server name, file name, share location, etc) and based on the input values it runs a PowerShell script on mentioned server and create a file backup to the required share.
Logic I used is when one submit the form its input action is to show a card, listing all the input values(for verification) and a button which when clicked run the script, perform its task and logs entry in the database about success or fail. It is working fine.

My aim is to show some kind of status update when script is complete. Progress bar would be great. If not any indication when script starts and complete. I am new to PowerShell so not able to understand how to use new-udpreloader here. Tried to create a model or table inside the card which check for log entry in database every 5 seconds and display it but able to get it work.

Right now its confusing for user to know whether script is running or not.

In case it is not possible from what I have done, is there any other approach to get this done? i.e. take input run script and get update.

In the form endpoint, could you put a loop that periodically checks the database for status, and exits when completed, showing a toast or @psDevUK’s Sweetalert with the result?

A loop in the endpoint should leave the form with a spinning loading icon until completed.

For my dashboards that have long load times I have made a dynamic loader based on phase of the loading page. when each phase is started the loader description changes.

First I create a New-UDElement and define my loaders (see example)

New-UDElement -Id 'CloudLoadingMessage' -Tag div -Endpoint {
            if ($CloudCostSummaryLoading -eq $true) {
            New-UDColumn -Size 12 -LargeOffset 3 -Content {
                New-UDHeading -Text "Loading Clouds" -Size 6
				New-UdRow {
				New-UDColumn -LargeOffset 1 -Content {
					New-UDImage -Url "url-to-gif/loading.gif" -Width 67 -Height 20
                }
			   }
             }
            } elseif ($GetAccountsAPILoading -eq $true) {
            New-UDColumn -Size 12 -LargeOffset 3 -Content {
                New-UDHeading -Text "Loading Accounts" -Size 6
				New-UdRow {
				 New-UDColumn -LargeOffset 1 -Content {
					New-UDImage -Url "url-to-gif/loading.gif" -Width 67 -Height 20
				 }
				}
             }
            } else {}
        }

Then within each phase of the page ( in my page I have 6-7 different tables that load data from different APIs) so within each column containing the related table I have set the loaders variable to $true ($CloudCostSummaryLoading = $true) and then a Sync-UDElement -id ‘CloudLoadingMessage’ which forces the New-UDElement from above to go through the if/elseif changing the loader text for each phase.

At the end of the Colunm I set the loader variable to $false so when the Sync-UDElement is loaded again in the next phase the correct loader message will appear.

Hope this helps.

6 Likes

Neat! That looks great!

That’s really cool and thanks for sharing the code!!

Hi All,

Sorry I was away couldn’t reply soon.
@PorreKaj : I already tired this but it didn’t work. Earlier my database table didn’t had any unique ID as I need to retrieve rows related to particular session so created one unique value column (Request No) still I was not able to get it work.
@mylabonline: This is great view but the concern is I am not pulling any data at first. Initially I am executing a PS script. I tried to use it but it get display after script execution is complete and loading data takes few millisecond so its not working for me.

It might be my skill level I am not able to implement your ideas. :slight_smile:

However for now I have created another button “Status” next to “Backup” button. Backup button trigger the script to take backup and Status button to display final status. I had to create dynamic page in order to pass Request No to database query.
Now If I click Backup Button first and then Status Button in order and sit behind as soon as Backup script complete the status page is displayed. It might be due to that as both button are in same endpoint i.e. inside InputAction so the task get queue.

Currently it doesn’t show me any progress during script execution but I am getting the final status automatically.