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 / How to prevent the con...
Power Automate
Answered

How to prevent the conversion of formatting in Power Automate

(0) ShareShare
ReportReport
Posted on by 20

Hi Folks,

 

I set up the following PowerShell script as a variable in Power Automate and need to execute it as an input. But Power Automate always converts this script into one line so that this script can be run because of syntax error. Is there a way to prevent Power Automate to stop the conversion of formatting? Thanks

$AzureSQLServerName = "%CurrentItem['serverName']%"
$AzureSQLDatabaseName = "%CurrentItem['dbName']%"


$clientID = "ee5982fb-a92e-4bb9-9543-79b6fc7e2740"

Connect-AzAccount -Identity -AccountId $clientID

Write-Output "Authentication complete..."

$accessToken = (Get-AzAccessToken -ResourceUrl https://database.windows.net).Token

Write-Output "Executing query..."

$SQLOutput = $(Invoke-Sqlcmd -ServerInstance $AzureSQLServerName -Database $AzureSQLDatabaseName -AccessToken $accessToken -Query "exec [dbo].[AzureSQLMaintenance] @Operation='statistics' ,@LogToTable=1" -QueryTimeout 65535 -ConnectionTimeout 60 -Verbose) 4>&1

Write-Output $SQLOutput
Write-Output "Executing query complete."

 

setup_variable.pngInput.pngOneline.png

 

 

I have the same question (0)
  • OkanMTL Profile Picture
    703 Super User 2024 Season 1 on at

    Hi,

     

    A solution for this problem is to format your powershell code in one line within power automate. 

    Powershell statements can be formatted in one line by separating each line with a semi colon.

    For example, your first two lines would be:

    $AzureSQLServerName = "%CurrentItem['serverName']%";$AzureSQLDatabaseName = "%CurrentItem['dbName']%";.....//the rest of the code

     

    You could technically also split your string in separate strings and append each line to your powershell runbook.

     

    Good luck.

    I am interested in other solutions as well. 

     

     

  • Verified answer
    rwebox Profile Picture
    20 on at

    Wow, it is an unexpected prompt response!!!

     

    I will try it and thank you a bunch!

     

    Ray

  • rwebox Profile Picture
    20 on at

    Just tested. This solution works!!!

     

    Thank you, OkanAT, agin!

  • OkanMTL Profile Picture
    703 Super User 2024 Season 1 on at

    No problem,

     

    You might want to answer my answer as a solution for others to see 🙂

  • rwebox Profile Picture
    20 on at

    Sorry, this is my first time posting a question. Do I just click on "Accept as Solution"?

     

    Thanks

  • Verified answer
    OkanMTL Profile Picture
    703 Super User 2024 Season 1 on at

    Indeed.

  • rwebox Profile Picture
    20 on at

    Done and thanks

  • OkanMTL Profile Picture
    703 Super User 2024 Season 1 on at

    You're welcome,

     

    Keep us updates on any problems 🙂

  • rwebox Profile Picture
    20 on at

    Power Automate is a great idea but currently there are so many bugs. I have been learning it in the past couple of weeks. Sometimes I feel so frustrated when I use it. For example, the same action worked yesterday but it reports an error today. Hopefully, it will get better soon. 

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 July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 272 Super User 2026 Season 2

#2
trice602 Profile Picture

trice602 147 Super User 2026 Season 2

#3
11manish Profile Picture

11manish 146 Super User 2026 Season 2

Last 30 days Overall leaderboard