In the past I wrote numerous PowerShell scripts which involved the views. Now I finally found some time to create a function to get the folder hierarchy of a given View by it's ID (guid).
Why I never thought about solving it like this, i don't know, but it appeared to be not that hard. It's a simple recursive function.
In the future I'll update the existing scripts concerning the User Scopes and will also upload a nice script which shows a complete report about all the dependancies between Management Packs and their objects used in User Roles and Notifications. This comes in handy, when you want to phase out management packs but don't know whether there are User Roles and Notification Subscriptions involved.
Enjoy.
- $computerName should have a name of a valid Management Server
- $viewId needs to have a valid guid of an existing view in your SCOM environment.
New-SCOMManagementGroupConnection -ComputerName $computerName $mg = Get-SCOMManagementGroup function GetFolderHierarchy($folderId,$folderpath) { $parentfolderid = $null $tmpfolder = $mg.GetMonitoringFolder($folderId) $tmpfolderdisplayname = $tmpfolder.DisplayName if ($folderpath -eq "" -Or $folderpath -eq $null) { $folderpath = $tmpfolderdisplayname } else { $folderpath = $tmpfolderdisplayname + "\" + $folderpath } $parentfolderid = $tmpfolder.ParentFolder.id.Guid if ($parentfolderid -ne "" -And $parentfolderid -ne $null -And $tmpfolder.name -ne "Microsoft.SystemCenter.Monitoring.ViewFolder.Root") { GetFolderHierarchy $parentfolderid $folderpath } else { return $folderpath } } function GetViewHierarchy($viewId) { $tmpview = $mg.GetMonitoringView($viewId) $parentfolderid = $tmpview.ParentFolderIds.Guid | Select -First 1 if($parentfolderid -ne "" -And $parentfolderid -ne $null) { $fullpath = GetFolderHierarchy $parentfolderid return $fullpath + "\" + $tmpview.DisplayName } } GetViewHierarchy $viewId