4

So, I find some programs, that can search UPnP devices from local network, but I can't find the same realization in Powershell. Maybe someone can tell, how to write Powershell script using UPnP for searching devices?

Filburt
  • 17,626
  • 12
  • 64
  • 115
Vertigo
  • 141
  • 1
  • 5

3 Answers3

6

For this question I got help. So there is answer for my question, if someone need it. Code in PS should be like this:

$finder = New-Object -ComObject UPnP.UPnPDeviceFinder;
$devices = $finder.FindByType("upnp:rootdevice", 0)
foreach($device in $devices)
{
    Write-Host -ForegroundColor Red ---------------------------------------------
    Write-Host -ForegroundColor Green Device Name: $device.FriendlyName
    Write-Host -ForegroundColor Green Unique Device Name: $device.UniqueDeviceName
    Write-Host -ForegroundColor Green Description: $device.Description
    Write-Host -ForegroundColor Green Model Name: $device.ModelName
    Write-Host -ForegroundColor Green Model Number: $device.ModelNumber
    Write-Host -ForegroundColor Green Serial Number: $device.SerialNumber
    Write-Host -ForegroundColor Green Manufacturer Name: $device.ManufacturerName
    Write-Host -ForegroundColor Green Manufacturer URL: $device.ManufacturerURL
    Write-Host -ForegroundColor Green Type: $device.Type
}
Vertigo
  • 141
  • 1
  • 5
  • You do realize this will not give you devices located under the devices you are looping through? You only get devices one level deep. You need to do the same (as above) for each device, add them to your collection of devices, until no further device has a child device which hasn't been added. I've already done this in vb6 if you want the code. – Erx_VB.NExT.Coder Sep 04 '12 at 08:25
0

You would be interested in Microsoft UPnP API, specifically IUPnPDeviceFinder. I don't know enough about Powershell to tell whether you could use the APIs directly or you would need some glue .NET library like perhaps this one.

Pavel Zdenek
  • 7,146
  • 1
  • 23
  • 38
0

This code initiates the UPnPDeviceFinder object and starts a search over all available UPnP types:

# https://learn.microsoft.com/en-us/windows/win32/api/upnp/nf-upnp-iupnpdevicefinder-findbytype

$finder = New-Object -ComObject UPnP.UPnPDeviceFinder
$finder.FindByType('ssdp:all', 0)
Carsten
  • 1,612
  • 14
  • 21
  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – Donald Duck Dec 30 '20 at 13:07