< Back
Invoke-Script
Post
NAME Invoke-Script
SYNOPSIS
Invokes the supplied stages as a script.
SYNTAX
Invoke-Script [-Stages] <Stage[]> [-ProgressMode {None | Full | Compact}] [<CommonParameters>]
DESCRIPTION
Invokes the supplied stages as a script. This cmdlet is especially useful for
running scripts with a progress bar.
PARAMETERS
-Stages <Stage[]>
The stages to invoke as a script.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ProgressMode
The display mode to use for the progress bar.
Required? false
Position? named
Default value Full
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Invoke-Script @(New-Stage "Title" { Do-Work })
Invoke a simple, single-stage script.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Invoke-Script @(New-Stage "Title" { Do-Work }) -ProgressMode Compact
Invoke a simple, single-stage script with the compact progress bar.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Invoke-Script @(New-Stage "Title" { Do-Work }) -ProgressMode None
Invoke a simple, single-stage script with no progress bar being displayed.
-------------------------- EXAMPLE 4 --------------------------
>
Invoke-Script @(
$(New-Stage "Build" {
Update-Progress 0 "Building..."
dotnet publish Hello.dll
Update-Progress 100 "Build complete"
}),
$(New-Stage "Copy" {
Update-Progress 0 "Copying files to remote"
$Files = Get-ChildItem $Source -File -Recurse
for ($i = 0; $i -lt $Files.Count; $i++) {
$File = $Files[$i]
Update-Progress $($i / $Files.Count * 100) "Copying $File"
Copy-Item $File -Destination $Destination -ToSession $Session -Force
}
})
)
Invoke a script that builds a dotnet project in its first stage, then copies the
resulting files to a remote computer in its second stage; all with a progress bar
displaying the actions taking place.
RELATED LINKS
SYNOPSIS
Invokes the supplied stages as a script.
SYNTAX
Invoke-Script [-Stages] <Stage[]> [-ProgressMode {None | Full | Compact}] [<CommonParameters>]
DESCRIPTION
Invokes the supplied stages as a script. This cmdlet is especially useful for
running scripts with a progress bar.
PARAMETERS
-Stages <Stage[]>
The stages to invoke as a script.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ProgressMode
The display mode to use for the progress bar.
Required? false
Position? named
Default value Full
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Invoke-Script @(New-Stage "Title" { Do-Work })
Invoke a simple, single-stage script.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Invoke-Script @(New-Stage "Title" { Do-Work }) -ProgressMode Compact
Invoke a simple, single-stage script with the compact progress bar.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Invoke-Script @(New-Stage "Title" { Do-Work }) -ProgressMode None
Invoke a simple, single-stage script with no progress bar being displayed.
-------------------------- EXAMPLE 4 --------------------------
>
Invoke-Script @(
$(New-Stage "Build" {
Update-Progress 0 "Building..."
dotnet publish Hello.dll
Update-Progress 100 "Build complete"
}),
$(New-Stage "Copy" {
Update-Progress 0 "Copying files to remote"
$Files = Get-ChildItem $Source -File -Recurse
for ($i = 0; $i -lt $Files.Count; $i++) {
$File = $Files[$i]
Update-Progress $($i / $Files.Count * 100) "Copying $File"
Copy-Item $File -Destination $Destination -ToSession $Session -Force
}
})
)
Invoke a script that builds a dotnet project in its first stage, then copies the
resulting files to a remote computer in its second stage; all with a progress bar
displaying the actions taking place.
RELATED LINKS