PS> # works: PS> $switch.Children | Select-Object HasChildren, Children
HasChildren Children ------------------- True System.__ComObject
PS> # fails: PS> $switch.Children.HasChildren PS> $switch.Children.Children PS> $switch.Children[0].HasChildren Value does not fall within the expected range. PS> $switch.Children[0].Children Value does not fall within the expected range.
失败的原因是 COM 数组的一个特异性。它们使用一个非常规的枚举器,和普通的对象数组不同,所以 PowerShell 无法直接存取数组元素。一个简单的解决方案是使用 ForEach-Object:
$UPnPFinder = New-Object-ComObject UPnP.UPnPDeviceFinder # the UDN is unique, so you need to find out the UDN for your device first # you cannot use the UDN I used $myNetgearSwitch = $UPnPFinder.FindByUDN('uuid:4d696e69-444c-164e-9d42-3894ed0e1db5') $myNetgearSwitch
这次,几乎立即识别出我的设备。要列出它的服务,我只需要获取它的 “Services” 属性,并且 PowerShell 自动将该 COM 对象转为可见的属性:
1 2 3 4 5
PS> $myNetgearSwitch.Services
ServiceTypeIdentifier Id LastTransportStatus ------------------------------------------ urn:schemas-upnp-org:service:Layer3Forwarding:1 urn:upnp-org:serviceId:L3Forwarding1 0
Time : 9/10/2019 12:00:00 AM
Title : 2019-09 Security Update for Adobe Flash Player for Windows 10 Version 1903 for
x64-based Systems (KB4516115)
KB : KB4516115
Description : A security issue has been identified in a Microsoft software product that could
affect your system. You can help protect your system by installing this update
from Microsoft. For a complete listing of the issues that are included in this
update, see the associated Microsoft Knowledge Base article. After you install
this update, you may have to restart your system.
Severity : Critical
Time : 10/8/2019 12:00:00 AM
Title : Windows Malicious Software Removal Tool x64 - October 2019 (KB890830)
KB : KB890830
Description : After the download, this tool runs one time to check your computer for infection by specific, prevalent malicious software (including Blaster, Sasser,
and Mydoom) and helps remove any infection that is found. If an infection is found, the tool will display a status report the next time that you start your computer. A new version of the tool will be offered every month. If you want to manually run the tool on your computer, you can download a copy from the Microsoft Download Center, or you can run an online version from microsoft.com. This tool is not a replacement for an antivirus product. To help protect your computer, you should use an antivirus product.
Severity : normal
Time : 10/8/2019 12:00:00 AM
Title : 2019-10 Cumulative Update for .NET Framework 3.5 and 4.8 for Windows 10 Version
1903 for x64 (KB4524100)
KB : KB4524100
Description : Install this update to resolve issues in Windows. For a complete listing of the issues that are included in this update, see the associated Microsoft Knowledge Base article for more information. After you install this item, you may have to restart your computer.
Severity : normal
Time : 10/28/2019 12:00:00 AM
Title : Update for Windows Defender Antivirus antimalware platform - KB4052623 (Version 4.18.1910.4)
KB : KB4052623
Description : This package will update Windows Defender Antivirus antimalware platform’s components on the user machine.
Severity : normal
...