Public/Get-WFListViewItem.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function Get-WFListViewItem
{
    <#
        .SYNOPSIS
            Function to get item(s) from a ListView Control
 
        .DESCRIPTION
            Function to get item(s) from a ListView Control
             
        .EXAMPLE
            Get-WFListViewItem -ListView $ListView1 -SelectedItem
             
            This will return all the selected item in the list view $listview1
 
        .NOTES
            Author: Francois-Xavier Cat
            Twitter:@LazyWinAdm
            www.lazywinadmin.com
            github.com/lazywinadmin
         
            VERSION HISTORY
                1.0 2014/07/03 Initial Version
    #>

    [CmdletBinding()]
    PARAM (
        [ValidateNotNull()]
        [Parameter(ParameterSetName = "All",
                   Mandatory)]
        [Parameter(ParameterSetName = "Selected",
                   Mandatory)]
        [System.Windows.Forms.ListView]$ListView,
        
        [Parameter(ParameterSetName = "Selected",
                   Mandatory)]
        [switch]$SelectedItem,
        
        [Parameter(ParameterSetName = "All",
                   Mandatory)]
        [switch]$All
    )
    
    IF ($PSBoundParameters['All']) { $ListView.Items }
    IF ($PSBoundParameters['SelectedItem']) { $ListView.SelectedItems }
}