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 Select-VideoOSItem -Title "Select Microphone(s)" -AllowServers -HideGroupsTab -Kind ([VideoOS.Platform.Kind]::Microphone) |
            % { Send-MipMessage -MessageId 'Control.StartRecordingCommand' -DestinationEndpoint $_.FQID -UseEnvironmentManager }
 
        Launch the Item Picker and hide the Groups tab, showing only the system-definied hierarchy of servers under the Server tab, and
        filter the items to only Microphones. For each selected Microphone, send a manual "Start Recording" message.
    #>

    [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
            }
            else {
                Write-Output $form.ItemsSelected
            }
        }
    }
}