Product: PowerShell Universal
Version: 5.5.1
I love the software, it’s great! I am having a probably simple issue that I can’t seem to find any documentation about. I have an app with dashboard code in the Code section:
I would like to add a page to navigate to so I created a page in the Pages header:
If I add code to that page and try to view the page I get a “Page Not Found” error. If I try to navigate to it from the original app I also get a page not found error. How do I get that page to actually work?
Thanks!
Did you use
Get-UDPage
while setting up your App?
Otherwise you cannot redirect to it and it will show the “Page Not Found” message
I’m a long time user of PSU (years) and I’m actually having the same experience in PSU v5 with the new Pages functionality, I just tried created a new app, and added a new page, when clicking to view the page i got the same error - mind you, I havent added any additional code so it may be to do with the fact there’s no authentication defined or something like that (though I have authentication to the app itsself, nothing granular on the pages).
Though I don’t typically use the ‘Pages’ tab within PSU (so this isnt an issue for me), I think they’re trying to make this product more and more no/low code (or just generally making it more seamless and easier to use), and so putting much of the features into the GUI that have typically just been code based before.
You’re probably better looking to the documentation here first:
Apps | PowerShell Universal
You’ll want to define your pages in the code of your dashboard. The way that I do this is by storing my pages as separate ps1 scripts, and then dot source those into the dashboard code so it’s a little more organized.
Some feedback, from my experience using Apps and their Pages. There are many ways to deploy an app. A key aspect is navigation. Do you want a navigation pane on the left like PSU’s admin pages? Or, do you want navigation menu at the top like many web sites? Perhaps its a one page app with no navigation. When you create a page on the Pages tab, it makes the page available, it doesn’t automatically load it. That’s good.
Below uses a PSU-Like Nav pane on the left that is open by clicking the three bars in the top left of the app.
I usually add pages like this in the Code tab:
Create navigation options/menu
$navigation = {
New-UDListItem -Label “Home” -Icon (New-UDIcon -Icon Home -Color “#FFBA33”) -Href “/home”
New-UDListItem -Label “Search” -Id ‘searchbtn’ -Icon (New-UDIcon -Icon Search) -Children {
New-UDListItem -Label “AD Inventory” -Icon (New-UDIcon -Icon RectangleAd -Color “##82FC4E”) -Nested -Children {
# New-UDListItem -Label “AD Master Inventory” -Icon (New-UDIcon -Icon LaptopHouse -Color “##82FC4E”) -Href “/searchADMaster” -Nested
New-UDListItem -Label “Domain A” -Icon (New-UDIcon -Icon RectangleAd -Color “##82FC4E”) -Href “/searchapplnk” -Nested
New-UDListItem -Label “Domain B” -Id ‘goldlnk’ -Icon (New-UDIcon -Icon RectangleAd -Color “##82FC4E”) -Href “/searchDomainB” -Nested
}
}
Use a different theme from the default
$theme = Get-UDTheme -Name ‘MaterialDesign’
Create an array of the pages to make available in the app.
$Pages = @()
$Pages += Get-UDPage -Name ‘HomePage’
$Pages += Get-UDPage -Name ‘ADMasterInventory’
$Pages += Get-UDPage -Name ‘DomainA’
$Pages += Get-UDPage -Name ‘DomainB’
Create the Main dashboard
New-UDDashboard -Title ‘Search Inventory’ -Pages $Pages -Logo ‘/images/Logo.png’ -LoadNavigation $navigation -HideUserName -Theme $theme
The example assumes these pages were created on the Pages tab:
HomePage, ADMasterInventory, DomainA, and DomainB
Example also assumes the logo.png file is available in a configured Published Folder.
Last note: Instead of creating PowerShell modules to contain common functions, I create them in a script file (Automation>Scripts) and load them on-demand using dot sourcing (load the functions into memory, don’t run them) Example:
This will load the functions within each script for the page where they are called.
.$Repository/PsuCoreFunctions.ps1
.$Repository/GridFunctions.ps1
All good advice - I think the confusion is likley the assumption the UI gives new users, there’s a cross over between what we can do in the GUI vs in code though in the majority of cases both are still required. Though historically I’ve always done everything in code.
To add to pages, I load mine dynamically by using get-childitem on my dashboard folder and iterating through subfolders to get all the ps1 files.
I also put a commented out but uniquely tagged line at the top of each page, which contains the JSON required to populate a splat for New-UDPage cmdlet (with an additional propery for excluding items from the nav menu), that way everything is contained in the pages if i need to update the title, permissions etc, rather than split between dashboard.ps1 and page.ps1.
$RootPath = "$Repository\dashboards\dashboardName\"
$Pages = @()
$MenuExclusions = @()
$PageFiles = Get-ChildItem "$RootPath/content" -filter "*.ps1" -Recurse
Foreach ($PageFile in $PageFiles){
$PageMeta = Get-Content $PageFile -first 1
if($PageMeta -like "#META#`*"){
$PageSplat = $PageMeta.Substring(6) | ConvertFrom-Json | ConvertTo-HashTable
if($PageSplat.ContainsKey('ExcludeFromMenu')){
if($PageSplat.ExcludeFromMenu){
$MenuExclusions += $PageSplat.Name
}
$PageSplat.Remove('ExcludeFromMenu')
}
$Pages += New-UDPage @PageSplat -Content {
. $PageFile.FullName
}
}
}