Table of Contents

Pb. (dot-sourcing)

PowerShell supports dot-sourcing. You can type a dot (.) followed by a space, followed by a ps1 file name pointing to a script you want to include in the current script context.

InVision supports its own dot-sourcing where you can type Pb. followed by a space, followed by the name of a PowerShell or SQL script defined in the solution.

This will make code in another script available to you. This is useful if you want to call a function residing in another script.
In SaaS solutions, the Solution Devs will not be able to put a file on any disk. This feature meets the need to dot-source a script without requiring access to disk.

Note
If a PowerShell Script and a SQL Script have the same name, you can specify the type after the comma (i.e. Pb. ‘MyScript, SQL’ or ‘MyScript, Pwsh’). Hence comma is not an allowed character in the names of scripts that are to be referred via Pb.

Example 1

Embed PowerShell Script

We need to import data from several Excel worksheets, so We create a PowerShell script that implements a generic import of Excel data.
We call this script Excel Impl. It has functions that do the work of bulk copying Excel Worksheet data into a SQL Server table.

Then we create a script that will be a function library that works as a layer between the implementation and the scripts that are going to use the functions.
We call this script Excel Functions.

Lastly, we create the script that needs to import data from Excel worksheets into SQL server tables.
We call this script Pb. Example Excel.


dot-sourcing


Excel Impl has the reference to Sql Server.


dot-sourcing


It also contains code that will be used by the Excel Functions script.


dot-sourcing


Excel Functions uses Pb. 'Excel Impl' to enable use of the Import-ExcelData function inside Excel Impl


dot-sourcing


Finally We use Pb. Excel Functions to enable use of the PbImport-Excel function inside the Excel Functions.


dot-sourcing



Example 2

Embed SQL Script

We have a SQL Script called Sql w macro.

dot-sourcing

It has a macro defined.

dot-sourcing

We make a PowerShell script called Test macro.
In this script we add a reference to the NuGet Package Microsoft.Data.SqlClient.

dot-sourcing


We add the following script where I use Pb. 'Sql w macro' to embed the SQL Script called Sql w macro.

dot-sourcing