Created
April 16, 2021 19:18
-
-
Save joshooaj/a6de7fcac7d366b006c2be22dcbe9051 to your computer and use it in GitHub Desktop.
Enumerate all device groups recursively and build up a hashtable object with the details about the device groups on the system, and all the devices added to those device groups.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Generic function which can take a device group from Get-DeviceGroup and go backwards to determine the full hierarchy of the device group path. | |
| function Resolve-DeviceGroupPath { | |
| [CmdletBinding()] | |
| param( | |
| [Parameter(Mandatory, ValueFromPipeline)] | |
| [VideoOS.Platform.ConfigurationItems.IConfigurationItem] | |
| $DeviceGroup | |
| ) | |
| process { | |
| $itemType = $DeviceGroup.Path -replace '(\w+)\[.+\]', '$1' | |
| $item = Get-ConfigurationItem -Path $DeviceGroup.Path | |
| $path = "" | |
| while ($true) { | |
| $path = "/$($item.DisplayName)" + $path | |
| if ($item.ParentPath -eq "/$($ItemType)Folder") { | |
| break; | |
| } | |
| $item = Get-ConfigurationItem -Path $item.ParentPath.Replace("/$($ItemType)Folder", "") | |
| } | |
| Write-Output $path | |
| } | |
| } | |
| $deviceGroupsByCategory = @{ | |
| Camera = $null | |
| Microphone = $null | |
| Speaker = $null | |
| Metadata = $null | |
| Input = $null | |
| Output = $null | |
| } | |
| $VerbosePreference = 'Continue' | |
| foreach ($category in $deviceGroupsByCategory.Keys | Select-Object) { | |
| $deviceGroupsByCategory.$category = @{ Groups = $null; Contents = $null } | |
| $deviceGroupsByCategory.$category.Groups = Get-DeviceGroup -DeviceCategory $category -Path / -Recurse | Resolve-DeviceGroupPath | Select-Object -Unique | |
| $deviceGroupsByCategory.$category.Contents = Get-DeviceGroup -DeviceCategory $category -Path / -Recurse | ForEach-Object { | |
| $groupPath = $_ | Resolve-DeviceGroupPath | |
| $_."$($category)Folder"."$($category)s" | Foreach-Object { | |
| $device = $_ | |
| [pscustomobject]@{ | |
| Group = $groupPath | |
| Device = $device.Name | |
| Id = $device.Id | |
| } | |
| } | |
| } | |
| } | |
| # Get the "path" of all camera groups. These represent the group name and the hierarchy and can be used to create new device groups | |
| $deviceGroupsByCategory.Camera.Groups | |
| # Get a report of all the camera groups and the devices inside them and their ID's | |
| $deviceGroupsByCategory.Camera.Contents | |
| # Same as above but for Microphones | |
| $deviceGroupsByCategory.Microphone.Contents |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment