I'm having a variable of type System.Collections.Hashtable
I want to write this value in azure DevOps variable in Powershell script and need to use the variable in the below tasks.
Variable created in azure DevOps: header
Task 1
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId $env:tenant_id
$head = $null
$head = @{}
$head = Get-PowerBIAccessToken
Write-Host ("##vso[task.setvariable variable=headers]$head")
Task 2
Write-Host "Header is " $env:headers
Invoke-RestMethod -Headers $env:headers -Uri 'https://api.powerbi.com/v1.0/myorg/groups'
But the issue in Task 2 is
Header is System.Collections.Hashtable
Invoke-RestMethod : Cannot bind parameter 'Headers'. Cannot convert the "System.Collections.Hashtable" value of type "System.String" to type "System.Collections.IDictionary".
Since the value of the header is simply assigning the string of System.Collections.Hashtable
and not the actual value
$headers = @{}
. Then add the property$headers[“PropertyName”] = $env:headers
– Nick Graham