Collect-MiracastCapabilities.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<#PSScriptInfo
 
.VERSION 1909.8.1
 
.GUID 30a2eb9a-8ae0-4811-bc0c-9a17644878d1
 
.AUTHOR Tim Small
 
.COMPANYNAME Smalls.Online
 
.COPYRIGHT 2019
 
.TAGS Miracast systeminformation
 
.LICENSEURI
 
.PROJECTURI https://github.com/Smalls1652/Collect-MiracastCapabilities
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
1909.08.01 - Initial release.
 
.PRIVATEDATA
 
#>
 



<#
.SYNOPSIS
    Collect Miracast capabilities for the system.
.DESCRIPTION
    Collect Miracast capabilities for the system by analyzing the network adapters, graphics cards, and if Miracast is HDCP capable.
.PARAMETER AllPhysicalAdapters
    Collect all physical network adapters, rather than just wireless network adapters.
.EXAMPLE
    Collect-MiracastCapabilities.ps1
     
    CapableNetAdapters CapableGraphicsCards MiracastCapable HdcpCapable
    ------------------ -------------------- --------------- -----------
    Intel(R) Dual Band Wireless-AC 8265 Intel(R) UHD Graphics 620 True True
 
    (Collects Miracast information for the system.)
.EXAMPLE
    PS C:\> Collect-MiracastCapabilities.ps1 -AllPhysicalAdapters
 
    CapableNetAdapters CapableGraphicsCards MiracastCapable HdcpCapable
    ------------------ -------------------- --------------- -----------
    {Intel(R) Dual Band Wireless-AC 8265, Intel(R) Ethernet Connection (4) I219-LM} Intel(R) UHD Graphics 620 True True
 
    (Collects Miracast information for the system, but includes all capable physical network adapters.)
#>

[CmdletBinding()]
param(
    [switch]$AllPhysicalAdapters
)

begin {
    <#
    The filter for collecting network adapters follows two conditions by default:
    1. If the NdisVersion of the adapter is greater than 6.30.
    2. If the network adapter is wireless.
 
    If the switch parameter '-AllPhysicalAdapters' is provided, then it will return any capable network adapter.
    #>

    switch ($AllPhysicalAdapters) {
        $true {
            Write-Verbose "Config Setting - Collecting all network adapters"
            filter NdisFilter {
                if ((([version]$PSItem.NdisVersion) -ge [version]"6.30")) {
                    $PSItem.InterfaceDescription
                }
            }
        }

        Default {
            Write-Verbose "Config Setting - Only collecting wireless network adapters"
            filter NdisFilter {
                if ((([version]$PSItem.NdisVersion) -ge [version]"6.30") -and ($PSItem.InterfaceName -like "wireless*")) {
                    $PSItem.InterfaceDescription
                }
            }
        }
    }

    <#
    This function runs DxDiag and saves it to a temporary XML file.
     
    DxDiag has information regarding if the system is Miracast capable or not.
    #>

    function Collect-DxDiagInfo {
        $TempFile = New-TemporaryFile
        $null = Start-Process -FilePath "dxdiag" -ArgumentList @("/dontskip", "/whql:off", "/x $($TempFile.FullName)") -Wait -NoNewWindow
        $DxDiagXml = [xml](Get-Content -Path $TempFile.FullName -Raw)
        $null = Remove-Item -Path $TempFile -Force

        return $DxDiagXml
    }
}

process {
    Write-Verbose "Collecting Miracast capable network adapters."
    $NetAdapters = Get-NetAdapter -Physical | NdisFilter

    switch ($NetAdapters) {
        #If there are no network adapters
        {($NetAdapters | Measure-Object | Select-Object -ExpandProperty "Count") -eq 0} {
            $NetAdapters = "N/A"
        }
    }

    Write-Verbose "Collecting system information from 'dxdiag'."
    $DxDiag = Collect-DxDiagInfo

    Write-Verbose "Finding Miracast capable graphics cards."
    #Utilizing the data from DxDiag, this will check which graphics cards are Miracast capable and store them in the variable.
    $GraphicsCards = foreach ($Display in $DxDiag.DxDiag.DisplayDevices) {
        if ($Display.DisplayDevice.Miracast -eq "Supported") {
            $Display.DisplayDevice.CardName
        }
    }

    switch ($GraphicsCards) {
        #If there are no capable graphics cards
        { ($GraphicsCards | Measure-Object | Select-Object -ExpandProperty "Count") -eq 0 } {
            $GraphicsCards = "N/A"
            $MiracastCapable = $false
            $HdcpCapable = $false
        }

        #If there are capable graphics cards
        Default {
            Write-Verbose "Parsing system information from 'dxdiag' for Miracast support status."
            switch ($DxDiag.DxDiag.SystemInformation.Miracast) {
                #If the 'Miracast' field has 'Available' in it's string
                { $PSItem -like "Available*" } {
                    $MiracastCapable = $true

                    Write-Verbose "Checking if Miracast is HDCP capable."
                    switch ($PSItem) {
                        #If the 'Miracast' field has 'with HDCP' in it's string.
                        { $PSItem -like "*with HDCP" } {
                            $HdcpCapable = $true
                        }

                        #If the 'Miracast' field does not.
                        Default {
                            $HdcpCapable = $false
                        }
                    }
                }

                #If the 'Miracast' field does not.
                Default {
                    $MiracastCapable = $false
                    $HdcpCapable = $false
                }
            }
        }
    }

    #Building the return object with all collected data.
    $ReturnObj = [pscustomobject]@{
        "CapableNetAdapters"   = $NetAdapters;
        "CapableGraphicsCards" = $GraphicsCards;
        "MiracastCapable"      = $MiracastCapable;
        "HdcpCapable"          = $HdcpCapable
    }
}

end {
    return $ReturnObj
}