Skip to content

Instantly share code, notes, and snippets.

@cbaragao
Created February 9, 2025 22:10
Show Gist options
  • Select an option

  • Save cbaragao/9aed3d93fd643cfd24495a88199df312 to your computer and use it in GitHub Desktop.

Select an option

Save cbaragao/9aed3d93fd643cfd24495a88199df312 to your computer and use it in GitHub Desktop.
Format PQ with Power Shell and Power Automate Desktop
SET PQ TO $fx'=Substitute(Code,Char(34),Concatenate("`", Char(34)) )'
Scripting.RunPowershellScript.RunPowershellScript Script: $fx'function FormatPQ {
param (
[string]$code,
[string]$resultType,
[int]$lineWidth = 80,
[int]$indentationLength = 2,
[bool]$includeComments = $true,
[bool]$surroundBracesWithWs = $false,
[bool]$indentSectionMembers = $true,
[int]$alignLineCommentsToPosition = 0,
[string]$alignPairedLetExpressionsByEqual = "never",
[string]$alignPairedRecordExpressionsByEqual = "never",
[string]$indentation = "spaces",
[string]$ws = " ",
[string]$lineEnd = "`n"
)
# Craft the body for the request
$body = @{
code = $code
resultType = $resultType
lineWidth = $lineWidth
indentationLength = $indentationLength
includeComments = $includeComments
surroundBracesWithWs = $surroundBracesWithWs
indentSectionMembers = $indentSectionMembers
alignLineCommentsToPosition = $alignLineCommentsToPosition
alignPairedLetExpressionsByEqual = $alignPairedLetExpressionsByEqual
alignPairedRecordExpressionsByEqual = $alignPairedRecordExpressionsByEqual
indentation = $indentation
ws = $ws
lineEnd = $lineEnd
} | ConvertTo-Json
# Set the URL
$url = "https://m-formatter.azurewebsites.net/api/v2"
# Send the request
try {
$response = Invoke-RestMethod -Uri $url -Method Post -Body $body -ContentType "application/json"
} catch {
Write-Error "Error: $_"
return
}
# Get the reformatted query
$formattedQuery = $response.result -replace "\\\\r\\\\n", "`r`n"
# Return the reformatted query
return $formattedQuery
}
$code = "${PQ}"
$resultType = "text" # Adjust as needed
$formattedCode = FormatPQ -code $code -resultType $resultType
Write-Output $formattedCode' ScriptOutput=> PowershellOutput ScriptError=> ScriptError
Clipboard.SetText Text: $fx'=PowershellOutput'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment