Private/Get-TeamviewerDeviceProperty.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function Get-TeamviewerDeviceProperty
{
    [CmdletBinding(DefaultParameterSetName = 'remotecontrol_id')]
    param
    (        
        [Parameter(Mandatory=$true)]
        [string]$ComputerName,

        [Parameter(ParameterSetName = 'device_id')]
        [switch]$device_id,

        [Parameter(ParameterSetName = 'remotecontrol_id')]
        [switch]$remotecontrol_id,

        [Parameter(ParameterSetName = 'description')]
        [switch]$description

    )

    Begin 
    {
        Write-Verbose -Message 'Starting: Get Teamviewer Device Property'
        
        if (!(Test-Path variable:Global:TeamviewerDeviceList ) -and !($DeviceList))
        {
            throw 'No Teamviewer Access Token has been specified or set. Use Set-TeamviewerAccessToken to set your AccessToken or Initialize-Teamviewer to load Teamviewer Global Variables.'
        }
        elseif ((Test-Path variable:Global:TeamviewerDeviceList ) -and !($DeviceList))
        {
            $DeviceList = $Global:TeamviewerDeviceList
        } 
    }

    Process
    {
        $Property = $PSCmdlet.ParameterSetName
        Write-Verbose -Message "Device Property: [$($Property)]"
       
        $Devices = $DeviceList.devices | Where-Object { $_.'alias' -like "*$ComputerName*" }
        
        if ($Devices.count -eq 0)
        {
            Throw "No Device found for [$ComputerName]"
        }
        elseif ($Devices.count -gt '1')
        {
            Write-Verbose -Message "Multiple Names Matched, Prompting User for selection."

            $Selection = Get-TeamviewerChoice -Choices $Devices.alias
            $Device = $Devices[$Selection]

            $DeviceProperty = $Device.$Property
        }
        else
        {
            $DeviceProperty = $Devices.$Property
        }
        Write-Verbose -Message "Device [$($Property)] is [$($DeviceProperty)]"
    
        Return $DeviceProperty
    }

    End
    {
        
    }
}