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?
Is there any script, that can search whole local network for UPnP devices?
Asked Answered
Check out my comment, you are not getting 2nd level plus devices with your code. Level meaning deeper than 2nd level nested. –
Rubirubia
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
}
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. –
Rubirubia
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.
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)
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. –
Sectorial
© 2022 - 2024 — McMap. All rights reserved.