Protect-UDSection ActiveDirectory.ps1


I would like to create a RBAC Menu for a Single Dashboard for everyone in IT.
I am modifying the Sample: ActiveDirectory.ps1
When I try to Protect a menu item it is hidden from everyone when the page loads.
If I add -LoadNavigation at the bottom, the page loads with this error.

Any help is appreciated.



  $Navigation = @(
    New-UDListItem -Label 'Users' -Icon (New-UDIcon -Icon 'User') -Children {
      New-UDListItem -Label 'Search Users' -Icon (New-UDIcon -Icon 'Search') -Href '/search-users' -Nested
      New-UDListItem -Label 'Inactive Users' -Icon (New-UDIcon -Icon 'Stop') -Href '/inactive-users' -Nested
      New-UDListItem -Label 'Reset Password' -Icon (New-UDIcon -Icon 'Key') -Href '/reset-password' -Nested
      New-UDListItem -Label 'Restore Deleted User' -Icon (New-UDIcon -Icon 'Trash') -Href '/restore-deleted-user' -Nested
    New-UDListItem -Label 'Groups' -Icon (New-UDIcon -Icon 'Users') -Children {
      New-UDListItem -Label 'Search Groups' -Icon (New-UDIcon -Icon 'Search') -Href '/groups' -Nested
      New-UDListItem -Label 'Group Membership' -Icon (New-UDIcon -Icon 'Users') -Href '/group-membership' -Nested
    Protect-UDSection -Content {
     New-UDListItem -Label 'Infrastructure' -Icon (New-UDIcon -Icon 'Server') -Children {
      New-UDListItem -Label 'Search Computers' -Icon (New-UDIcon -Icon 'Search') -Href '/Search-Computers' -Nested
      New-UDListItem -Label 'Domain Controllers' -Icon (New-UDIcon -Icon 'Database') -Href '/Domain-Controllers' -Nested
  } -Role 'Administrator'
    New-UDListItem -Label 'Object Search' -Icon (New-UDIcon -Icon 'Search') -Href '/object-search'
  New-UDDashboard -Title "Active Directory Tools" -Pages @(
    Get-UDPage -Name "Domain Controllers"
    Get-UDPage -Name "Groups"
    Get-UDPage -Name "Group Membership"
    Get-UDPage -Name "Object Info"
    Get-UDPage -Name "Object Search"
    Get-UDPage -Name "Search Computers"
    Get-UDPage -Name "Search Users"
    Get-UDPage -Name "Reset Password"
    Get-UDPage -Name "Restore Deleted User"
    Get-UDPage -Name 'Inactive Users'
  ) -NavigationLayout Permanent -LoadNavigation $Navigation

You need to change the navgiation variable from an array to a script block.

 $Navigation = {
 ##  navigation code

The reason is that we invoke the scriptblock when the user visits the page.

1 Like

Thanks Adam!
That did it!! :smile: