Public/Tools/Select-VideoOSItem.ps1

function Select-VideoOSItem {
    <#
    .SYNOPSIS
        Offers a UI dialog for selecting items, similar to the item selection interface in Management Client.
 
    .DESCRIPTION
        This cmdlet implements the VideoOS.Platform.UI.ItemPickerUserControl in a custom form to allow the user to
        select one or more items of any kind using a friendly and customizable user interface.
     
    .PARAMETER Title
        Specifies the text in the title-bar of the Item Picker window. The default is "Select Item(s)".
 
    .PARAMETER Kind
        One or more Guids representing a type of object in Milestone. Use Get-Kind -List to see the available Kinds
        or use [VideoOS.Platform.Kind] to access a set of static Kind guids, such as [VideoOS.Platform.Kind]::Camera.
        Omitting a value means the list in the picker will be unfiltered.
 
    .PARAMETER Category
        One or more [VideoOS.Platform.Admin.Category] values representing the types of items to populate in the picker,
        such as [VideoOS.Platform.Admin.Category]::VideoIn. Omitting a value means the list in the picker will be unfiltered.
 
    .Parameter SingleSelect
        The ItemPicker allows for multiple items by default. Supply this parameter to force selection of a single item.
 
    .Parameter AllowFolders
        Device groups are considered folders and are not selectable by default. To allow for selecting many items with one click,
        include this parameter. Consider using this with the FlattenOutput switch unless you specifically need to select a folder
        item instead of it's child items.
 
    .Parameter AllowServers
        Supply this switch to enable selection of servers. You might choose to do this if you want to select Recording Servers,
        or you want to select all child items, such as cameras, from a server. Consider using this with the FlattenOutput switch
        unless you specifically need to select a server item instead of it's child items.
 
    .Parameter KindUserSelectable
        Supply this switch to enable a drop-down list in the UI for the user to filter the Kind themselves.
 
    .Parameter CategoryUserSelectable
        Supply this switch to enable a drop-down list in the UI for the user to filter the Category themselves.
 
    .Parameter FlattenOutput
        When you allow groups/folders to be selectable, the result will not directly include the child items of those folders
        unless you supply this switch.
 
    .Parameter HideGroupsTab
        Supply this switch to hide the Groups tab, leaving only the Server tab which shows the "SystemDefined" hierarchy.
 
    .Parameter HideServerTab
        Supply this switch to hide the Server tab, leaving only the Groups tab which shows the "UserDefined" hierarchy.
 
    .EXAMPLE
        PS C:\> Get-BankTable C:\MediaDatabase\4344cd14-0b12-4c18-8677-5d263c140af4 -DeviceId "94275fef-b977-43f6-bf78-210c615b2967" | Copy-Item -Destination C:\Temp -Container -Recurse -Force
 
        Copy all media database tables for device with ID 94275fef-b977-43f6-bf78-210c615b2967 to C:\Temp
    #>

    [CmdletBinding()]
    param (
        [Parameter()]
        [string]
        $Title = "Select Item(s)",
        [Parameter()]
        [guid[]]
        $Kind,
        [Parameter()]
        [VideoOS.Platform.Admin.Category[]]
        $Category,
        [Parameter()]
        [switch]
        $SingleSelect,
        [Parameter()]
        [switch]
        $AllowFolders,
        [Parameter()]
        [switch]
        $AllowServers,
        [Parameter()]
        [switch]
        $KindUserSelectable,
        [Parameter()]
        [switch]
        $CategoryUserSelectable,
        [Parameter()]
        [switch]
        $FlattenOutput,
        [Parameter()]
        [switch]
        $HideGroupsTab,
        [Parameter()]
        [switch]
        $HideServerTab
    )

    process {
        $form = [MilestonePSTools.UI.CustomItemPickerForm]::new();
        $form.KindFilter = $Kind
        $form.CategoryFilter = $Category
        $form.AllowFolders = $AllowFolders
        $form.AllowServers = $AllowServers
        $form.KindUserSelectable = $KindUserSelectable
        $form.CategoryUserSelectable = $CategoryUserSelectable
        $form.SingleSelect = $SingleSelect
        $form.GroupTabVisable = -not $HideGroupsTab
        $form.ServerTabVisable = -not $HideServerTab
        $form.Icon = [System.Drawing.Icon]::FromHandle([VideoOS.Platform.UI.Util]::ImageList.Images[[VideoOS.Platform.UI.Util]::SDK_GeneralIx].GetHicon())
        $form.Text = $Title

        if ($form.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
            if ($FlattenOutput) {
                Write-Output $form.ItemsSelectedFlattened -NoEnumerate
            }
            else {
                Write-Output $form.ItemsSelected -NoEnumerate
            }
        }
    }
}