Welcome to the new Box Support website. Check out all the details here on what’s changed.

Put Box CLI result into Powershell variable

Answered
New post

Comments

2 comments

  • Official comment
    Alex Novotny

    Hey Scott! 

    Thanks for the question. 

    This is happening because Box is returning a 204. There are a couple things you can do! 

    If you want to see the 204 response code - you can use this syntax in a powershell script vs calling the CLI within a powershell script. 

    $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $headers.Add("Authorization", "Bearer <token>")
    try {
    $response = Invoke-RestMethod 'https://api.box.com/2.0/collaborations/<collab_id>' -Method 'DELETE' -Headers $headers
    } catch {
    # Dig into the exception to get the Response details.
    # Note that value__ is not a typo.
    Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
    Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
    }

    If you want to use the CLI in the command still, you could do something like this:

    $id="<collab_id>"
    $collabResponse = "$(box collaborations:delete $id 2>&1)" | Tee-Object -Variable collabResponse
    Write-Host "Response: $collabResponse"

    Thanks, 

    Alex, Box Developer Advocate

    Comment actions Permalink
  • Scott Best

    That's perfect!  Just what I needed to know.  Thank you!

    0
    Comment actions Permalink

Please sign in to leave a comment.