# Add-VaultTab Adding a new Tab for a specific entity type to the Vault Explorer with an Action that is called when the Tab is clicked or the selection changes in Vault.\ The cmdlet provides the possibility to define a user interface for the registered Tab. ## Syntax ```powershell Add-VaultTab -Name -EntityType -Action [] ``` ## Parameters | Type | Name | Description | Default Value | Optional | |-------------------------------------------|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|----------| | String | Name | Label of the Tab displayed in the Vault Explorer. | | no | | [VaultTabEntityType](commandlets/add-vaulttab:vaulttabentitytype) | EntityType | The entity type for which the Tab should be displayed. | | no | | Scriptblock / String | Action | Script block or function that gets executed for the currently selected entity in the Vault Client (`$selectedEntity`) if the Tab is activated.
This can be used to define or update the Tab interface by simply returning a [WPF Control](https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.control?view=netframework-4.5) from the script block or function. | | no | (commandlets/add-vaulttab:vaulttabentitytype)= ### VaultTabEntityType **Enum values:** | Name | Description | |---------------|--------------------------------------| | File | Tab gets displayed for Files. | | Item | Tab gets displayed for Items. | ## Return type **empty** ## Remarks The Cmdlet extends the Vault Client's user interface with a new tab with the specified **-Name** as its label.\ When multiple tabs with the same *-Name* for the same *-EntityType* are registered, only the latest registered tab is displayed. The script block or the function name passed as **-Action** parameter is invoked with an [powerVault entity]() that represents the element that is selected in the Vault Client.\ If multiple entities are selected, the first selected entity will be used. Depending on the *[EntityType](commandlets/add-vaulttab:vaulttabentitytype)* of the Tab, the passed object can be either a [file]() or an [item]().\ The *Action* is executed every time the Vault user changes a selection while the Tab is visible, or when the Tab is activated by the user. The tab content is **cleared** and the log provides information when: - unhandled terminating exceptions occur on the hosting applications (Vault Client) UI thread - the _Action_ returns an invalid [WPF Control](https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.control?view=netframework-4.5) :::{note} - The cmdlet can **only be used** when running directly in a **Vault Explorer** process. - Created tabs remain available as long as this process exists and disappear again when the Vault Client is restarted. - Only the use of the cmdlet in client customization [scripts]() ensures that the tab is displayed in every Vault Client session. - The Vault Client remembers activated Tabs (based on their position) even after a restart. In this case, the passed *-Action* gets invoked immediately after [LoginVault]() event registrations. ::: ## Examples **Adds a Tab for files displaying a DataGrid with their FileBom rows:** ```{image} /img/Add_VaultTab_SampleFileBOM.png :align: right :width: 40% ``` ```powershell Add-VaultTab -EntityType File -Name 'Sample File BOM' -Action { param($selectedFile) $fileBom = Get-VaultFileBOM -File $selectedFile._FullPath if(-not $fileBom) { return BuildFromXaml @' '@ } #Print BOM data as Table like in Inventor $bomrows_table = BuildFromXaml @' '@ $bomrows_table.ItemsSource = @($fileBom | sort-object {[int]$_.Bom_PositionNumber}) return $bomrows_table } function BuildFromXaml([xml]$xaml){ $xamlReader = New-Object System.Xml.XmlNodeReader $xaml return [Windows.Markup.XamlReader]::Load($xamlReader) } ``` **Adds a Tab for items that displays their Thumbnail image:** ```powershell Add-VaultTab -EntityType Item -Name 'Thumbnail' -Action 'DisplayItemThumbnail' function DisplayItemThumbnail($selectedItem){ $imageControl = New-Object System.Windows.Controls.Image $imageControl.Source = $selectedItem._Thumbnail.Image return $imageControl } ```