Restrict Pages to Roles

Is it possible to restrict roles to specific pages or prevent them from accessing a page from view?
I tried to do this:

if ($Roles -notcontains 'Monitoring') {
    $Pages += New-UDPage -Name 'Example' -Content { 
       ..... code  here .....

Even though the user is in the Monitoring Role, the page link is still shown for them. I know I can probably wrap the code inside the page to display not authorized message, but it would be better not even give the user the option to clicking it.

Product: PowerShell Universal
Version: 2.0.3

You should be able to just do:

   $Pages += New-UDPage -Name 'Example' -Role "Monitoring" -Content { 
       ..... code  here .....
1 Like

Hey @adam,

Thank you for replying.
Wouldn’t that only allow the page to be visible to the Monitoring role? Can I specify multiple roles?

I had tried this:

if ($Roles -notcontains 'Monitoring') {
    $Pages += New-UDPage -Name 'Advanced Reporting' -Content {

For multiple role, I define it like this.

-Role @(‘Monitoring’,‘Administrator’,‘Monitoring2’)