Quantcast
Channel: PowerShell Studio - SAPIEN Blog
Viewing all 246 articles
Browse latest View live

Progress Bar Series (Part 1) – Displaying Script Progress in GUI Applications

$
0
0

This is the first in a series of articles covering the topic of Progress Bars.

Sometimes a script can take time to complete a task and we need a way to display this in our GUI application. We can add a visual aid to help us see the progress of our script.

There are a number of ways to accomplish this:

  • Write the results to a text file.
  • Write the results to a database table.
  • Display the results in a text or label box in our GUI form.

You can also use the available progress control objects and script commands in your solution:

  • Progress Bar Control
  • Progress Bar Overlay Control
  • ToolStrip Control
  • StatusStrip Control
  • Write-Progress (non-graphical progress bar for console scripting)

All of these controls enable the GUI application to display the progress of the script during execution.

Once you learn to use one, it is easy to use the others since they have most of the same .NET properties and methods for handling the progress bar animation.

To learn more about these properties and methods, check out the following article on the ProgressBar Control.

Progress Bar Display Options

The following images show some options for using the progress bar controls. These can be the starting point for building either simple or complex forms. The complexity is up to you—be creative!

Using the “Progress Bar” control in it’s simplest form, and in a multi-task progress:

     

Using the “Progress Bar Overlay” control gives a better notion of completion by adding text to the progress bar:

       

All of the above GUI forms were created manually. The GUI templates provided with PowerShell Studio can save development time and can also provide ready-to-use code that can be easily modified.

The images below provide examples of the progress bar control added to a pre-existing template.

When you use either the “StatusStrip” or “ToolStrip” control, the progress bar will be added to a specific location on the form. When the “StatusStrip” control is used, the Progress Bar is placed at the bottom of the form:

When the “ToolStrip” control is used, the Progress Bar is placed at the top of the form:

Using either the “Progress Bar” or “Progress bar Overlay” control gives you the ability to add the control anywhere on the form:

If you want to provide a non-graphical progress bar for a console script solution, use the “Write-Progress” cmdlet.  For more information and an example, run the following command:

Get-Help Write-Progress -detailed

Keep in mind that using the “Write-Progress” cmdlet is host dependent—when packaging the application, it won’t work when using either “Silent Engine” or “Windows Form” in a GUI application.

By using any of these controls (or cmdlet) and a few lines of code, we can add the visual aid to help us see what’s going on with our script progress.

Notice that when executing the progress bar in a GUI application, it will become unresponsive until it completes processing the code behind the control. If there is a requirement to give a user the ability to interrupt or cancel the progress operation, you need to build a responsive form.

Check out these articles for information on making a responsive GUI:

I will provide an example of a “Responsive Form” in Part 5 of this series—”Handling Steps Progress with a Background Job in a GUI Application”.

What’s next?

In the upcoming series we will explore some progress bar scenarios, including notion of completion, status notification, and steps progress. Up next is Part 2 where we will cover the progress bar use for notion of completion.

Progress Bar series topics:

Related Articles

Feedback

As always, if you have any ideas, comments, or feedback, please visit our feedback forum and reference this post.

 

Max Trinidad is a Technology Evangelist at SAPIEN Technologies Inc., and a Microsoft PowerShell MVP. You can reach him at maxt@sapien.com


Progress Bar Series (Part 2) – Handling Progress with Notion of Completion in a GUI Application

$
0
0

This article is Part 2 in our Progress Bar series. In this article, we cover handling a script’s task progress with the notion of completion by using a “Progress Bar” control in a GUI application to provide a visual presentation of what is processing.

Backup Files GUI Scenario

In this scenario, we will develop a GUI application that creates a backup folder that will copy a series of files from a selected folder. This application will include a progress bar to visually show the progress while copying the files.

This application will prompt the user to select the location of the folder containing all text files to be backed up, and it will automatically create the backup folder in the selected folder. “Progress Bar” and “RichTextBox” controls have been added to the form to show what is going on during the process.

The combination of using both controls gives us the notion of completion in our GUI application.

“Select Folder” Button Control

To make the progress bar work, we added the necessary code behind the “Select folder” button control event.  The GUI application will prompt to select the folder containing the files to backup before starting the backup step. These files will be copied to a predefined backup folder-name in the chosen folder location.

After selecting the folder, we save the total number of files.

:
#Get all the text files in the folder
$files = Get-ChildItem $selectedPath -Filter *.txt;
:

Next, we use the saved total files to initialize the progress bar Maximum property. Then we initialize all other properties before starting to display the progress activity.

#Initialize the Progress Bar
$progressbar1.Maximum = $files.Count;
$progressbar1.Step = 1;
$progressbar1.Value = 0;

The progress bar will start with Value property = 0, and use the Step property to increment that Value by 1 when executing the for-each loop. The progress bar will start to increment.

#Copy the files and update the progress bar
$cnt = 1;
foreach ($file in $files)
{
Copy-Item ('{0}\\{1}' -f $selectedPath, $file) -Destination $destination;
$copiedfiles = "$cnt - $($file.name) - copied from $($selectedPath) to $($destination).";
$richtextbox1.AppendText(($copiedfiles | Out-String -Width 1000));
$cnt++;

## - Progress bar method to increment the slider:
$progressbar1.PerformStep();

};

Inside the foreach(..) loop logic, every time the PerformStep() method executes after the copy step the progress bar will increment by 1, as defined in the Step property.

While the GUI application is executing, we can see the progress bar increment as the files are copied to the selected backup folder. At the same time, we can see the information being updated in the RichTextBox area:

  

All of this done is done with just a few lines of code.

Summary

To make the progress bar work, we need to initialize the Maximum value to the total amount of the files being copied. Then we use the PerformStep() method to increment the progress bar.

Below is a general view of the logic used in the progress bar sample:

Download Progress Bar sample form: ProgressBarSimpleTask02.zip

What’s next?

Next up is Part 3 where we will demonstrate the use of the “Progress Bar Overlay” control.

Progress Bar series topics:

Related Articles

Feedback

As always, if you have any ideas, comments, or feedback, please visit our feedback forum and reference this post.

 

 

SAPIEN Technologies at the Orlando .NET User Group Open Mic Night

$
0
0

On Thursday, March 14, I had the pleasure of participating in the Orlando .NET User Group (ONETUG) Open Mic Night on the eve of their upcoming Orlando Code Camp 2019 event.

This is a dedicated user group with about 15 professionals seeking interesting topics and staying current with the latest technology.

The Open Mic Night had the following three topics:

PowerShell Core – Introduction to SQL Server” – by Maximo Trinidad, SAPIEN Technologies Evangelist.

Kubernetes for .NET developers” – by Facundo Gauna, Software Engineer at Nebbia Technology.

Angular Authentication with Azure AD” – by Phil Hagerman, Full Stack Developer and Front End Enthusiast.

The open mic was fast-paced, with 20-minute time slots allotted for each presenter. The blend of topics provided an opportunity to see how these technologies interact with each other. I enjoyed showing SAPIEN Technologies’ PowerShell Studio 2019 editor working with PowerShell Core from within WSL (Windows Subsystem for Linux) and Docker Containers.

The Orlando .NET User Group meets in the Melrose Tech Center, on the 2nd floor of the Orlando Public Library. You can connect with ONETUG via their MeetUp group.

SAPIEN Technologies strives to enhance the productivity of system administrators and DevOps developers by continually adding new features to our products. Check out our software options and feel free to contact me (maxt@sapien.com) or SAPIEN Sales (sales@sapien.com) with any questions.

 

Event and User Group Sponsorship

SAPIEN Technologies is proud to support the PowerShell Community. Feel free to reach out and contact us for event and user group sponsorship by sending an email to usergroups@sapien.com.

 

Max Trinidad is a Technology Evangelist at SAPIEN Technologies Inc., and a Microsoft PowerShell MVP. You can reach him at maxt@sapien.com

Progress Bar Series (Part 3) – Handling Progress Status Information in a GUI Application

$
0
0

In Part 3 of the Progress Bar series, we are going to take a more in-depth look at the “Progress Bar Overlay” control. This control allows us to display text in the progress bar while processing the script in the application.

Getting Computer Information Scenario

In this GUI application, we will retrieve some system information and at the same time display each data collection step of the process by using the “Progress Bar Overlay” control.

As the script steps execute, the TextBox control will show the computer name for the data that is being collected. Next, the progress bar will increment as the different script steps complete, and then the RichTextBox control will display the results.

“Get Info” Button Control

The “Progress Bar Overlay” control contains the TextOverlay property, where you can add a text string that will display as the progress bar increments during script execution.

The script’s processing takes place in the code behind the “Get Info” button control. The text box will display the system from which the data is being collected. The computer names are stored in a string array, and then the for-each loop will pick one computer name at a time.

In this scenario, to get the progress bar Maximum property value, we get the total count of items in the array and then multiply by the number of steps. The Step property is set to 1 which will allow the Perform() method to increment the bar by 1.  Using the Start-Sleep cmdlet helps to provide a delay of 1 second to display the “Processing…” text in the progress TextOverlay property, which allows us to see the progress bar increment while executing the script steps in the for-each loop logic.

:
## - Set list of systems:
$svrList = @("$($env:COMPUTERNAME)", "$($env:COMPUTERNAME)");

## - TextOverlay before executing function:(Array count * number of steps)
$progressbaroverlay1.Maximum = $svrList.Count * 3;
$progressbaroverlay1.Step = 1;
$progressbaroverlay1.Value = 0;
$progressbaroverlay1.TextOverlay = "Processing...";
Start-Sleep -Seconds 1;
:

Then, inside the for-each loop in each of the script step’s sections, the following progress bar actions are performed:

  1. The progress bar TextOverlay property displays the step text.
  2. The script step executes.
  3. The progress bar PerformStep() method visually increments the bar.
  4. The Start-Sleep cmdlet at the end of each step gives a slight delay allowing the progress bar to display the script step text.
:
## - Foreach to get system information:
$global:SvrObj += foreach ($name in $svrList)
{
## - Get Computername:
$textbox1.Text = "Collecting information from Computer - $name";

## - Script Step 1:
$progressbaroverlay1.TextOverlay = "Step 1: Get Server Operating System Info...";
$x = get-wmiObject -Class Win32_OperatingSystem -Computername $name `
-ErrorAction 'SilentlyContinue' -ErrorVariable MyError;

$progressbaroverlay1.PerformStep();
Start-Sleep -Seconds 1;

## - Script Step 2:
$progressbaroverlay1.TextOverlay = "Step 2: Get Server Computer System Info...";

$x1 = get-wmiObject -Class Win32_ComputerSystem -Computername $name `
-ErrorAction 'SilentlyContinue' -ErrorVariable MyError;

$progressbaroverlay1.PerformStep();
Start-Sleep -Seconds 1;
## - Script Step 3:
$progressbaroverlay1.TextOverlay = "Step 3: Create $name PSObject ...";

## - Build PSCustomObject:
[PSCustomObject]$SystemInfo = New-Object PSObject -Property @{
ComputerName = $x.csname;
OperatingSystem = $x.Name.Split('|')[0];
LastBootUpTime = $x.ConvertToDateTime($x.LastBootUpTime);
Status = "Success";
Manufacturer = $x1.manufacturer;
SystemModel = $x1.model;
'PhysicalMemory(GB)' = [float]($x1.TotalPhysicalMemory/1gb);
} -ErrorVariable MyError; $SystemInfo

$progressbaroverlay1.PerformStep();
Start-Sleep -Seconds 1;
};
:

  

Now we can see the progress bar increment and display the text for the script step that has executed.

Another variation for this scenario is to use multiple progress bars while executing a series of script steps. This involves modifying the form to display overall progress and also individual step progress while collecting information from each system.

  

As you can see, there are different ways that your application can display progress.

Summary

The scenario outlined above follows the same coding approach as the previous post in the series, except here we are executing a series of script steps. Additionally, using the progress bar overlay allows us to provides details about what is happening by displaying text as the progress bar increments.

Here is a general view of the logic used in the progress bar overlay sample:

Download Progress Bar Overlay sample form: ProgressOverlayMultiTask01.zip

Here is the multi-steps progress bar code overview:

Download the multi-steps progress bar sample form: ProgressOverlayMultiTask02.zip

What’s next?

Next in the series is “Part 4 – Handling Steps Progress with a Background Job in a GUI Application” where we will use a “Progress Bar” control in a “responsive” GUI application with the ability to stop a process.

Progress Bar series topics:

Related Articles

Feedback

As always, if you have any ideas, comments, or feedback, please visit our feedback forum and reference this post.

SAPIEN Technologies at the Microsoft MVP Summit 2019

$
0
0

Every year Microsoft organizes the MVP Summit event in Redmond, WA. MVPs from around the world are invited to interact with Microsoft product teams during a full week of technical sessions.

This annual event provides the opportunity to collaborate with other MVPs on new and upcoming changes with Microsoft technologies.

 

This year the weather in Redmond was beautiful; warm and sunny with clear blue skies.

  

It was great to see many of my PowerShell, SQL Server, and other MVP friends. It was also nice to see Jeffrey Snover and the PowerShell Team—including Joey Aiello, Tyler Leonard, Steve Lee, and many others—as well as others no longer with Microsoft such as James Brundage and Bruce Payette.

Dinner with PowerShell MVPs: Bruce and James.

I was pleased with all of the session content and had the opportunity to learn new things.

MVPs pulling together for a special session “AutoRest PowerShell Cmdlet Generator” by Garret Serack (not NDA)

PowerShell is clearly not slowing down as evidenced by the strength of its use in many Microsoft products, and also by its crossover to many Linux distributions and MacOS.

If you have the need for PowerShell training please contact me (maxt@sapien.com) or SAPIEN Sales (sales@sapien.com) for information on our upcoming training schedule. Also be sure to check out our software options.

Event and User Group Sponsorship

SAPIEN Technologies is proud to support the PowerShell Community. Feel free to reach out and contact us for event and user group sponsorship by sending an email to usergroups@sapien.com.

 

Max Trinidad is a Technology Evangelist at SAPIEN Technologies Inc., and a Microsoft PowerShell MVP. You can reach him at maxt@sapien.com

 

Progress Bar Series (Part 4) – Handling Steps Progress with a Background Job in a GUI Application

$
0
0

In Part 4 of the Progress Bar series, we integrate a progress bar control in a GUI application that submits a job for background processing. We also demonstrate how to interrupt the running job.

GUI Application for Listing PDF Documents

In this scenario, we show the use of the progress bar while processing a background job. This application is an example of a “responsive” form which prevents the form from freezing during job execution. The form also provides an option to interrupt the job at any time and includes a time-lapse display.

“Start Job” Button Control

In the “Start Job” button control script block, we add the code to initialize the progress bar properties after a folder is selected.

After selecting a folder containing PDF files, we get the total number of files and use that in the Progress Bar Maximum property. Then we initialized both Step and Value properties to 1.

#Initialize the Progress Bar
$progressbar1.Maximum = $files.Count;
$progressbar1.Step = 1;
$progressbar1.Value = 1;

In the “Start Job” button script block, we use our Add-JobTracker Helper function. The following parameters are defined in this function to handle the background job process:

  • Name – The Job-Name for the running job.
  • ArgumentList – (Optional) A single value or an array of values to pass as an Argument to the job.
  • JobScript  – The script code that will be sent to run the background job.
  • UpdateScript – The script code used to update what is going on with the background job.
  • CompletedScript – The script code that will execute when the background job completes processing.

A splatting variable is created holding the parameter’s value to be passed to the Add-JobTracker function:

#Initialize the Progress Bar
$progressbar1.Maximum = $files.Count;
$progressbar1.Step = 1;
$progressbar1.Value = 1;

## - Prepare Splatter variable to submit to background job:
$jobsplat = @{
	Name		    = 'MyJobName'
	ArgumentList    = $selectedPath
	JobScript	    = $jobScript
	UpdateScript    = $updateScript
	CompletedScript = $completedScript
}

At this point, the function will submit the job for processing in the background.

During Job Processing

While the job is processing in the background, the PDF files in the selected folder are being displayed in the output “RichTextBox” control, the timer is counting, and the progress bar increments while processing.

All of this action is being handled by the “UpdateScript” script block section in the Add-JobTracker function:

$updateScript = {
	Param ($Job)
	
	if ($Job.Name -eq 'GetFiles')
	{
		
		## - Grab results from background job:
		$results = Receive-Job -Job $Job
		$richtextbox1.Lines += $results | select -ExpandProperty Fullname
		
		## - Make the text scroll-up while processing:
		$richtextbox1.SelectionStart = $richtextbox1.Text.Length
		$richtextbox1.ScrollToCaret()
		
		## - Increment progress bar:
		$progressbar1.PerformStep();
		
	}
	
	#Animate the Button
	if ($null -ne $buttonStartJob.ImageList)
	{
		if ($buttonStartJob.ImageIndex -lt $buttonStartJob.ImageList.Images.Count - 1)
		{
			$buttonStartJob.ImageIndex += 1
			
			## - Code to Display Time Elapsed:
			$CurrentTime = $Script:Time.Elapsed;
			$DisplayTime = $([string]::Format("Time: {0:d2}:{1:d2}:{2:d2}",
					$CurrentTime.hours,
					$CurrentTime.minutes,
					$CurrentTime.seconds));
			$labelTime.Text = $DisplayTime;
			
		}
		else
		{
			$buttonStartJob.ImageIndex = 0
		}
	}
}

In this section, the progress bar method PerformStep() will trigger the bar to increment.

When the background job ends, the “CompletedScript” script block section executes.  At this point, the total number of PDF files found will display in the “RichTextBox” output area, the total duration of the process will be displayed, and the progress bar will increment to completion.

$completedScript = {
	Param($Job)
	
	if ($Job.Name -eq 'GetPDFFiles')
	{
		## - Get Background Job results:
		$results = Receive-Job -Job $Job;
		$richtextbox1.Lines += $results | select -ExpandProperty Fullname;
		
		## - Display Process Stopped text:
		$richtextbox1.AppendText(("`r`n`r`n*** Process Completed ***`r`n"));
		
		## - Display processing time:
		$richtextbox1.AppendText("`r`n" + "Total Processing $($labelTime.Text)" + "`r`n");
		
		## - Scroll top end of lines:
		$richtextbox1.SelectionStart = $richtextbox1.Text.Length + 4;
		$richtextbox1.ScrollToCaret();
		
		## - Progress Bar fill to end:
		$progressbar1.Increment($richtextbox1.Text.Length);
		$progressbar1.PerformStep();

   }
    
	#Enable the Button
	$buttonStartJob.ImageIndex = -1
	$buttonStartJob.Enabled = $true
	
}

In this section, we use the progress bar method PerformStep() to help complete the bar.

Interrupt the Job

This application includes the ability to stop the job with the “Stop Job” button control. When the job is stopped, the progress bar will stay idle without any increments.

In the “Stop Job” control, both progress bar Value and Step properties are set to 0:

$buttonStopJob_Click = {
	
	Stop-JobTracker
        $this.Enabled = $false
	$buttonStartJob.Enabled = $false
	
	## - Progress bar stop and reset values to 0:
	$progressbar1.Value = 0;
	$progressbar1.Step = 0;
	
	## - Process Abort text:
	$richtextbox1.AppendText(("`r`n`r`n*** Process Stopped ***`r`n"));
}

As you can see, it was simple to integrate the progress bar properties in the Add-Tracker function script block with the button controls.

Summary

We have shown how to integrate the progress bar in a “responsive” application that is handling a background job, with the ability to interrupt the job.

Below is a general view of the logic used in this GUI application sample:

Download Progress Bar sample form: ProgressBarJobTracker_wStopOption1.zip

What’s next?

Next in the series is “Part 5 – Display Progress in a Script (non-GUI) solution”, where will be using the “Write-Progress” cmdlet.

Progress Bar series topics:

Related Articles

Feedback

As always, if you have any ideas, comments, or feedback, please visit our feedback forum and reference this post.

 

Max Trinidad is a Technology Evangelist at SAPIEN Technologies Inc., and a Microsoft PowerShell MVP. You can reach him at maxt@sapien.com

SAPIEN Technologies at the Orlando Code Camp 2019

$
0
0

SAPIEN Technologies is proud to be a repeat sponsor of the Orlando Code Camp event organized by ONETUG (Orlando .NET User Group).

 

The event had 621 registered attendees, with 90 speakers and 92 sessions.

The speaker dinner party the night before the event was well attended:

I appreciate the opportunity to speak before John Papa’s keynote speech.

  

A large percentage of people attended the event for the first time—during my PowerShell session, most of the attendees were new to PowerShell! It is great to see people interested in learning new technologies.

 

Thanks to the ONETUG organizers for having us as a sponsor: Chelsea Costner, Santosh Hari, Rush Frisby, Esteban Garcia, Brian Mishler, and volunteers.

If anyone wants to join the Orlando .NET User Group (ONETUG), check out their MeetUp group.

Event and User Group Sponsorship

SAPIEN Technologies is proud to support the PowerShell Community. Feel free to reach out and contact us for event and user group sponsorship by sending an email to usergroups@sapien.com.

 

Max Trinidad is a Technology Evangelist at SAPIEN Technologies Inc., and a Microsoft PowerShell MVP. You can reach him at maxt@sapien.com

Progress Bar Series (Part 5) – Display Progress in a non-GUI Script

$
0
0
In Part 5 of the Progress Bar series we take a look at the Write-Progress cmdlet, which can be used to display task progress in a non-GUI script. This cmdlet is available in Windows PowerShell and PowerShell Core (cross-platform). There…

New Video – Handling Progress with a Background Job in a GUI Application

$
0
0
This article presents the instructional video for creating a similar GUI application that was covered in our recent post: Handling Steps Progress with a Background Job in a GUI Application. This GUI application displays the list of all PDF documents…

Need help? There’s a support group for that!

$
0
0
Need help with one of our products or with PowerShell scripting in general? There is a support group for that on our forums! How to get help and quick! The easiest way to get to customer support is by using…

PowerShell Studio: Working with Images in a RichTextBox Control

$
0
0
In this blog post we take a look at how to include images in a RichTextBox Control for a GUI application. This may be helpful if you have a scenario where you want to display a selected image with the…

SAPIEN at SoCal PowerShell User Group

$
0
0
I had the wonderful opportunity to speak to the SoCal PowerShell user group about our SAPIEN DevOps Suite and to demo the new features of PowerShell Studio. The user group started with a round table where each member discussed their…

Four ways to package a non-GUI PowerShell script as an executable file

$
0
0
In this article I will show four Script Packager options available for converting a non-GUI PowerShell script to a packaged executable that can be run from a console shell. The “Packager” option is available under the “Deploy” ribbon tab in…

New Video – Four ways to package a non-GUI PowerShell script as an executable file

$
0
0
This article presents the instructional video for our recent post: Four ways to package a non-GUI PowerShell script as an executable file. The video briefly covers the four script engine options: SAPIEN PowerShell Vx Host (Command Line)SAPIEN PowerShell Vx Host…

Creating an MSI Installer for a packaged script executable

$
0
0
In a previous blog post we covered some of the SAPIEN Packager script engines to create an executable. Next step is to create the application installer so we can deploy the packaged solution. We are going to take this further.…

SAPIEN Editors – Working with Git Repositories

$
0
0
This blog post will get you started working with Git repositories in either of our SAPIEN editors—PowerShell Studio or PrimalScript. In the following scenario, I will use an existing Git repository stored in Azure DevOps to demonstrate the process of…

32-bit product versions discontinued in 2020

$
0
0
With the release of the 2020 versions of our products, we will no longer produce 32-bit versions of them. While we are aware that some of you still need to support 32-bit OS installations, development machines are all 64-bit now,…

Create a script executable solution to map a shared folder

$
0
0
In a previous article we demonstrated a number of script packager solutions. In this post we show other ways to provide information to a script executable. The sample script is used to map a network drive to an existing shared…

New Video – Creating an MSI Installer for a packaged script executable

$
0
0
This article presents the instructional video for our recent post Creating an MSI Installer for a packaged script executable. Build Installer The video briefly covers the four script engine options: Changes to the script Two additional scripts used in Custom…

SAPIEN Technologies at the South Florida Software Developers Conference 2020

$
0
0
Once again, SAPIEN Technologies is a proud sponsor of the South Florida Software Developers Conference 2020. Previously known as the South Florida Code Camp, the conference is in its 16th year. This event provides a free one-day geek fest with…
Viewing all 246 articles
Browse latest View live