Support bundle download fails with parameter binding error in PowerShell
search cancel

Support bundle download fails with parameter binding error in PowerShell

book

Article ID: 441139

calendar_today

Updated On:

Products

VMware Tanzu Platform Core

Issue/Introduction

When attempting to download a support bundle from Tanzu Hub using a standard curl command within a Windows PowerShell environment, the operation fails. The issue typically occurs when an engineer tries to pass an HTTP Authorization header containing a Bearer token using the -H flag. PowerShell intercepts the command and maps it to its native Invoke-WebRequest utility, resulting in a type mismatch error.

 

PS H:\> curl 'https://<TANZU_HUB_URL>/hub/data/document/download/<BUNDLE_ID>' -H 'Authorization: Bearer

...

value of type "System.String" to type "System.Collections.IDictionary".
At line:1 char:120

+ ... 37767a9' -H 'Authorization: Bearer  ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingExcept
   ion
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.Inv
   okeWebRequestCommand

Environment

 

  • Product: VMware Tanzu Platform Core

  • Component Name: Tanzu Hub

  • Client Environment: Windows PowerShell

 

Cause

The failure is caused by a syntax mismatch between traditional native curl and PowerShell's implementation of the command. In PowerShell, curl is an alias for the native cmdlet Invoke-WebRequest. The -H (or -Headers) parameter in Invoke-WebRequest expects an associative array (Dictionary/Hash Table object, e.g., @{ "Key" = "Value" }), whereas the traditional curl syntax provides the header as a single formatted string. This causes a ParameterBindingException.

Resolution

To successfully download the support bundle within PowerShell, format the headers as a native PowerShell Hash Table using one of the two methods below:

Method 1: Inline Hash Table

Execute the Invoke-WebRequest command by passing the Authorization header inside an inline hash table @{"HeaderName" = "HeaderValue"}:

Invoke-WebRequest -Uri "https://<TANZU_HUB_URL>/hub/data/document/download/<BUNDLE_ID>" -Headers @{"Authorization" = "Bearer <PASTE_TOKEN_HERE>"} -OutFile "support-bundle.tar.gz"

Method 2: Defined Header Variable (Recommended for Readability)

1. Define the authentication header as a Hash Table variable:

$headers = @{
    "Authorization" = "Bearer <PASTE_TOKEN_HERE>"
}

 

2. Execute the download request referencing the variable:

Invoke-WebRequest -Uri "https://<TANZU_HUB_URL>/hub/data/document/download/<BUNDLE_ID>" `
                  -Headers $headers `
                  -OutFile "support-bundle.tar.gz"

Additional Information

  • Ensure that <TANZU_HUB_URL> and <BUNDLE_ID> are updated to match your specific deployment endpoints.

  • Make sure the Bearer token has not expired at the time of executing the request.