Loading theme from published folder


Like with the cascading style sheet is there a way to load a theme file from a published folder?

When I do the following it gives me an error:

New-UDDashboard -Title ‘Home’ -theme @("/themes/Theme.ps1") -Content {

Theme.ps1 tested in 2 formats

$theme = @{}


Also tried loading like (. “/themes/theme.ps1”)

This is the error I am getting:

Cannot process argument transformation on parameter ‘Theme’. Cannot convert the “System.Object[]” value of type “System.Object[]” to type “System.Collections.Hashtable”.

Snippit form the theme file:

light = @{
palette = @{
Common = @{
black = ‘#000
white = ‘#fff
primary = @{
main = ‘#939b38
light = ‘#7986cb
dark = ‘#303f9f
contrastText = ‘#fff

Have you tried

Get-Content '/themes/Theme.ps1' -Raw

Also, this^ is an array


^ this is a string


^ this is also a string

$(Get-Content -Path “/themes/theme.ps1” -Raw)

^ this will load the contents of the file into the temporary variable $()
If you just want to use the filename, you do not need to surround it in anything.
That is why you’re receiving this error:

Is an array of objects

The -Theme parameter is expecting a hashtable so you will need to convert the string content from the theme into a hashtable.

Using a published folder isn’t really necessary here. You could instead use Import-PowerShellDataFile to load the file from disk.

$Theme = Import-PowerShellDataFile -Path "$PSScriptRoot\Themes\Theme.ps1"

If you want to load it via the published folder, you will have to load it with Invoke-WebRequest.

$Response = Invoke-WebRequest "http://localhost:5000/themes/theme.ps1" 
$Theme = Invoke-Expression $Response.Content

Thank you for this very helpful!!

Got a strange issue with the above.

Loading the file as such:

$Theme = Import-PowerShellDataFile -Path “$PSScriptRoot\Themes\Theme.ps1”

Works no problem.

Loading the Theme

$Response = Invoke-WebRequest “http://localhost:5000/themes/theme.ps1
$Theme = Invoke-Expression $Response.Content

Gives me a diffrent color for the main even though its set correctl

I deleted and readded the published folder incase it was cached and restarted the service. Nothing changed that.

Browsing to the file shows it correct too.

What happens when you output the $Theme returned by Invoke-Expression?

Maybe something like:

Show-UDToast -Duration 10000 -Message ($Theme | ConvertTo-Json)

I did that it looks correct and has all the same values.


Strange. I would suggest going the local file route then over the published folder since there is something that isn’t quite right there.

1 Like