web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Variables saved on two...
Power Automate
Answered

Variables saved on two lines

(0) ShareShare
ReportReport
Posted on by 73

Hi all, 

i am extracting the data from a webpage, storing the output in a 3-column data table. The third column contains an url.

i then run the following powershell script to extract part of the url, to obtain what it is the codenumber of the document.

I try to trim, to remove the newline chars, to check if the last charachter is a real charachter (see below).

 


$url = "%Lista[LIndex]['url']%"


$protocollo = $url.Substring($url.IndexOf("Protocollo=") + 11)  

$parte1 = $protocollo.Substring(7, 11).Trim()  
$parte2 = $protocollo.Substring(18, 7).Trim()  
  
$result = "$parte1 - $parte2".Trim()

$cuValue = $result

$cleaned = $cuValue.TrimEnd()

while (-not [char]::IsLetterOrDigit($cleaned[-1]) -and $cleaned.Length -gt 0) {
    $cleaned = $cleaned.Substring(0, $cleaned.Length - 1)
}

$cleaned += ".pdf"

Write-Output $cleaned

 

However, the resulting variable always consists of 2 rows:

nightfall_0-1696667274875.png

 

This creates issue when e.g. i want to save the document, as PAD will return an illegal name error.

To overcome this issue i've added the extension directly in the script, but it means that i need to create as many variables as the use i want to do with the original variable, which is quite inefficient.

 

Do you have any hints? 

 

thank you in advance!

 

I have the same question (0)
  • Verified answer
    Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    Hi @nightfall 

     

    I think why the extra new line is coming from powershell output, this may be because of Write-Output command it is creating one new line extra.

     

    So to avoid this, you can use .Trimmed function on the output variable.

     

    I have created a small example

     

    See below

    Nived_Nambiar_0-1696687923249.png

     

    I am running a powershell script Write-Output "data" whose output is stored in %PowershellOutput% variable.

    Now see the value of %PowershellOutput% in variables panel

    Nived_Nambiar_1-1696687998764.png

     

    It has one line extra.

     

    Now to remove that new line, use Trimmed method on %PowershellOutput% variable. i have set variable which saves the output of the trim action 

    Nived_Nambiar_3-1696688072751.png

     

    Now see variable NewVar

    Nived_Nambiar_4-1696688090903.png

     

    It does not have that extra line (new line)

     

    I hope this would resolve the issue.

     

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 252 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 169

#3
Haque Profile Picture

Haque 154

Last 30 days Overall leaderboard