In the previous tip we illustrated how to use the UPnP.UPnPDeviceFinder to find devices on your network. You already learned how to enumerate all root devices (“upnp:rootdevice”), and how to directly access a device via its unique device identifier.
$UPnPFinder = New-Object -ComObject UPnP.UPnPDeviceFinder $UPnPFinder.FindByType("upnp:rootdevice", 0) | Out-GridView
In this part, let’s complete the search types, and look at how to enumerate all devices (not just root devices), and how to enumerate groups of device types.
To list all devices, use “ssdb:all” instead of “upnp:rootdevice”:
$UPnPFinder = New-Object -ComObject UPnP.UPnPDeviceFinder $UPnPFinder.FindByType("ssdp:all", 0) | Out-GridView
The result includes root devices (“IsRootDevice” is $true, and “ParentDevice” is empty) as well as all child devices (“IsRootDevice” is $false and “ParentDevice” points to the device this device is chained to).
In “UniqueDeviceName”, you find the unique device name that can be used to directly access the device:
$UPnPFinder = New-Object -ComObject UPnP.UPnPDeviceFinder $UPnPFinder.FindByUDN("uuid:...", 0)
Each device belongs to a category which is exposed in “Type”. To see a list of types, try this:
$UPnPFinder = New-Object -ComObject UPnP.UPnPDeviceFinder $UPnPFinder.FindByType("ssdp:all", 0) | Select-Object -ExpandProperty Type | Sort-Object -Unique
The result varies depending on the devices found in your network. Here is the list I got:
urn:dial-multiscreen-org:device:dial:1 urn:schemas-upnp-org:device:Basic:1 urn:schemas-upnp-org:device:InternetGatewayDevice:1 urn:schemas-upnp-org:device:MediaRenderer:1 urn:schemas-upnp-org:device:WANConnectionDevice:1 urn:schemas-upnp-org:device:WANDevice:1
To find all devices of a specific type, use the type with FindByType():
$UPnPFinder = New-Object -ComObject UPnP.UPnPDeviceFinder $UPnPFinder.FindByType("urn:schemas-upnp-org:device:InternetGatewayDevice:1", 0)
A final note: whether a device responds to a group search or even “upnp:rootdevice” depends on the device and its implementation. In my scenario, I was unable to get results for the groups “Basic” and “WANDevice” even though there were devices of that type.
If you can’t find a particular device, try the only search that works for all devices, and list them all via “ssdp:all”. If the device shows up now, you can either use “ssdp:all” and client-side filtering via Where-Object, or speed up the search considerably by finding out the unique device identifier and access a particular device via its UDN and FindByUDN() directly.:
You are a PowerShell Professional, passionate about improving your code and skills? You take security seriously and are always looking for the latest advice and guidance to make your code more secure and faster? You’d love to connect to the vibrant PowerShell community and get in touch with other PowerShell Professionals to share tricks and experience? Then PowerShell Conference EU 2020 might be just the right place for you: https://psconf.eu (June 2-5, 2020 in Hanover, Germany).
It’s a unique mixture of classic conference with three parallel tracks filled with fast-paced PowerShell presentations, and advanced learning class with live discussions, Q&A and plenty of networking.
Secure your seat while they last: https://psconf.eu/register.html. Help build the agenda and make this “your” event by submitting hypothetical sessions you’d like to hear: https://powershell.one/psconfeu/psconf.eu-2020/reverse-cfp. And if you’d like to present yourself and join the psconf.eu speakers’ team, submit proposals: https://sessionize.com/psconfeu/.