Skip to content

Invoke-NBInBranch

Since

v4.4.10.0

SYNOPSIS

Executes a script block within a branch context.

SYNTAX

Invoke-NBInBranch [-Branch] <String> [-ScriptBlock] <ScriptBlock> [-ProgressAction <ActionPreference>]
 [<CommonParameters>]

DESCRIPTION

Temporarily enters a branch context, executes the provided script block, and then automatically exits the branch context. This provides exception-safe branch handling similar to using Push-Location/Pop-Location with try/finally.

The branch context is always restored even if an error occurs in the script block.

EXAMPLES

EXAMPLE 1

Invoke-NBInBranch -Branch "feature/test" -ScriptBlock {
    New-NBDCIMDevice -Name "test-server" -DeviceType 1 -Site 1
}
Create a device within a branch.

EXAMPLE 2

$results = Invoke-NBInBranch -Branch "staging" -ScriptBlock {
    Get-NBDCIMDevice -Status "planned"
    Get-NBIPAMAddress -Status "reserved"
}
Execute multiple operations and capture results.

PARAMETERS

-Branch

The name of the branch to execute within.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ScriptBlock

The script block to execute within the branch context.

Type: ScriptBlock
Parameter Sets: (All)
Aliases:

Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ProgressAction

{{ Fill ProgressAction Description }}

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

[object] Returns whatever the script block returns.

NOTES

AddedInVersion: v4.4.10.0

Common parameters

common request params

Enter-NBBranch Exit-NBBranch