How to use intellisense and debug Vault tabs that were added with Add-VaultTab cmdlet
Description
In order to develop PowerShell scripts efficiently it is essential to have access to intellisense and break points and be able to run written code immediately.
As the Add-VaultTab cmdlet handles the creation of the UI in Vault client only it is necessary to write some debug code that enables this in VsCode.
How it works
In order to test Add-VaultTab code in VsCode we need to override the cmdlet. The screenshot below shows a Debugging region.
Line 2: First it checks if it runs in powerEvents. If it does the debugging code is not run.
Line 3 - 8: Modules are imported and connections established
Line 10 - 23: The override for Add-VaultTab is initialized. This function creates its own window in PowerShell and embeds the control that is returned in line 52
Line 31: The code to create the control in the Add-VaultTab script is copied here to enable intellisense while scripting
Now when running the script in PowerShell a new window is opened that contains the control that is returned by the -Action script block
As the variable $PSScriptRoot is used the whole script must be run with F5. $PSScriptRoot is $null if a selection is run with F8.
Specific parts can be run of course if the necessary objects have been created.
This also enables you to set break points anywhere in that script block and react to UI input.
It is possible to set a break point in an event and then use intellisense to simplify writing after it has been hit.
Downloads