Anyway to keep spaces and line breaks in UD?

Hey Everyone,

Am I missing something… is there a way to keep spaces and line breaks in UD? When I try and create any string with line breaks or multiple spaces UD removes them all.

Example

Automation Job Output in PS

image

  • Sorry for double post, only allowed to upload 1 image at a time :expressionless:

then the same result in UD

Hmmm. Seems like it should account for this.

You might be able to get around this by doing something like this. This replaces the new line characters with the HTML
tag.

$Html = New-UDHtml "<div>$($AzureRMAutomationJobOutput.Replace('`n', '<br/>'))"
New-UDCard -Content { $Html }

Thanks Adam - I just tired it quickly and getting the same result. Ill spend some time with it later to see if it was my copy/paste skills.

I’ve preserved formatting in Cards using Here Strings before and it worked.

$body = @"
This is line 1

Testing:
This is a paragraph
            
"@

New-UDCard  -Title "Test" -Text $body
1 Like

Alright I’m stumped here as well. I’ve tried all the suggestions here and more and it won’t put the output on a individual line.

Code (Main Dashboard)

$MyDashboard = New-UDDashboard -Title "Test Form" -Content {
   
    New-UDInput -Title "Pre-Verify Build" -Id "Form" -Content {
        New-UDInputField -Type 'textbox' -Name 'vc' -Placeholder 'vSphere'
        New-UDInputField -Type 'textbox' -Name 'cluster' -Placeholder 'Cluster'
        New-UDInputField -Type 'textbox' -Name 'template' -Placeholder 'Template'

        } -Endpoint {
            param($vc, $cluster, $template)

            New-UDInputAction -Content @(
                New-UDCard -Title 'Input' -Content {
                    New-UDParagraph -Text "$vc"
                    New-UDParagraph -Text "$cluster"
                    New-UDParagraph -Text "$template"
                } -Links @(
                    New-UDLink -Text 'Resubmit a preverification' -Url '#!'
                )
                New-UDCard -Title “Results” -Endpoint {.\script.ps1 -vc $vc -cl $cluster -template $template} -fontcolor 'black'
            )

$cert = ( Get-ChildItem -Path cert:\LocalMachine\My\cert )

Get-UDDashboard | Stop-UDDashboard
Start-UDDashboard -Port 8080 -Dashboard $MyDashboard -Certificate $cert

Powershell File being called:

        [CmdletBinding()]
        param
        (
            [Parameter(Mandatory=$true)][string]$vc,
            [Parameter(Mandatory=$true)][string]$cl,
            [Parameter(Mandatory=$true)][string]$template
        )
          
        echo "Connecting to vSphere $vc`n"

# I have code in here doing stuff

        echo "Cluster input is $cl`n"
      
        echo "Template input is $template`n"

This will only output “Connecting to vSphere $vc” on the Card and nothing else. I would like it to echo out that output of what the script is doing in real time on the card. I’ve tried all the suggestions here and no luck. Please advise. It has to be possible as it’s doing the first one there already. If I put a comma after the first one it does put them together but again no line breaks. Anything I try won’t put the next echo on a new line. @adam any suggestions? Any help greatly appreciated.

After much troubleshooting I was able to figure it out. It simply started working when I changed each echo statement to one of these:

New-UDParagraph -Text "Connecting to vSphere $vc"

I also noticed doing this it doesn’t write the live output what the script is doing, will only output everything when it’s all done. I guess that’s fine, would be cooler if it was live. Any tricks to get the live output?

If not I’m having a hard time figuring out progress bars in UD, I’ll type another post for that so we don’t start mixing threads. That thread here: Progress Bar Examples

A quick and easy way for line break is to insert a break element too. just add:

New-UDElement -Tag 'br'

And it will insert a line break.

2 Likes

I’ve tried that first but that didn’t work for whatever reason only UDParagraph did.

The reason why most line breaks generated in powershell dont forward to universal dashboard is because powershell uses a different line break method than was is used to process the dashboard. I have not been able to figure out what it is though and its pretty anoying. But there are a few round about methods. the first is using a “New-UDParagraph” for each new line that you want, this is what i used to get a normal looking text file extract rather than one massive string

foreach($line in Get-Content $txtpath) {New-UDParagraph -Content {"$line"}