如何在PowerShell中传递超长篇JSON参数突破字符限制?
Great question—this is a common pain point when working with large payloads in Azure Automation. The 524,288-byte limit on runbook parameter values is a hard constraint for string parameters, and switching to other primitive data types won’t get around it (since all parameters are serialized before being sent to the runbook, and the serialized size still counts against the limit).
Instead, the most reliable workaround is to avoid passing the large JSON directly as a parameter. Here’s how to implement it:
Option 1: Use Azure Blob Storage to Host the JSON
This is the recommended approach for large payloads:
Upload JSON to Blob Storage in Logic Apps
- Add a "Create blob" action in your Logic Apps workflow, pointing to an Azure Blob Storage container. Write the raw JSON content from your SharePoint API call directly to a blob (use a unique filename like
{SiteId}-{ListId}-{Timestamp}.jsonto avoid conflicts). - Generate a SAS URI for the new blob using the "Generate SAS URI" action (set a short expiration time to keep things secure).
- Add a "Create blob" action in your Logic Apps workflow, pointing to an Azure Blob Storage container. Write the raw JSON content from your SharePoint API call directly to a blob (use a unique filename like
Pass the SAS URI to Your Runbook
- Update your runbook’s parameter to accept the SAS URI instead of the JSON string:
[parameter(Mandatory=$True)] [string] $BlobSasUrl
- Update your runbook’s parameter to accept the SAS URI instead of the JSON string:
Read the JSON from Blob in the Runbook
- In your PowerShell runbook, fetch the blob content and parse it into a JSON object:
# Fetch the blob content as a string $jsonString = (Invoke-WebRequest -Uri $BlobSasUrl -UseBasicParsing).Content $jsonData = $jsonString | ConvertFrom-Json # Proceed with your ADO.NET connection and stored procedure execution # Pass $jsonString or $jsonData to your stored procedure as needed
- In your PowerShell runbook, fetch the blob content and parse it into a JSON object:
This works because the SAS URI is a short string (well under the 524KB limit), and Azure Blob Storage can handle JSON payloads of virtually any size (up to 4.75TB per blob).
Why Other Data Types Won’t Work
Even if you tried using [byte[]] (byte array) or other complex types, Azure Automation still serializes the parameter value into a JSON payload for transmission. The serialized size of a large byte array would still exceed the 524KB limit, making this approach impractical.
Bonus: Clean Up Old Blobs
To avoid cluttering your storage account, add a step in your Logic Apps workflow (after the runbook completes successfully) to delete the temporary blob using the "Delete blob" action.
内容的提问来源于stack exchange,提问作者Gabriel Menezes

