Skip to content

Functions

The Functions region is used to define all PowerShell functions that are used throughout the ScriptoForm script. If no functions are used within the ScriptoForm, this region can be removed from the script file.

This region is denoted with the #region Functions tag and occurs between the Forms and Handlers regions in the ScriptoForm script.

PowerShell
#region Functions
function Invoke-FormAction
{
param
(
[Parameter(Mandatory, Position = 0)] [ScriptBlock]$Action,
[Parameter(Position = 1)] [ScriptBlock]$Reset = $null,
[Parameter(Position = 2)] [String]$StatusText = "Working...please wait"
)
try
{
$ToolStripStatusLabelMain.Text = $StatusText
$FormMain.Controls | Where-Object {$PSItem -isnot [System.Windows.Forms.StatusStrip]} | ForEach-Object {$PSItem.Enabled = $false}
$FormMain.Cursor = [System.Windows.Forms.Cursors]::WaitCursor
[System.Windows.Forms.Application]::DoEvents()
& $Action
}
finally
{
$FormMain.Controls | ForEach-Object {$PSItem.Enabled = $true}
$FormMain.ResetCursor()
if ($Reset) {& $Reset}
$ToolStripStatusLabelMain.Text = "Ready"
$StatusStripMain.Update()
}
}
<#
Add function definitions here...
#>
#endregion

The Functions region in a newly provisioned ScriptoForm contains the following comment block:

Functions Region
<#
Add function definitions here...
#>

This comment block should be removed (or replaced with additional function definitions if needed), as it is intended only to provide an initial visual reminder.

Functions Region | Example
#region Settings
<#
Add function definitions here...
#>
function Format-FirstLetter
{
param
(
[Parameter(Mandatory)] [string]$Text
)
if ($Text)
{
return $Text[0].ToString().ToUpper() + $Text.Substring(1)
}
}
#endregion