Skip to content

Instantly share code, notes, and snippets.

@DexterPOSH
Last active April 13, 2020 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DexterPOSH/0f3da0df5bdaad18d10a0b08bf4027d3 to your computer and use it in GitHub Desktop.
Save DexterPOSH/0f3da0df5bdaad18d10a0b08bf4027d3 to your computer and use it in GitHub Desktop.
Gist with a catch
$url = 'https://dev.azure.com/ddhami/BITPro.AzDeploy/_apis/distributedtask/environments'
$cred = Get-Credential -UserName 'vsts' -Message 'Enter AzDO Personal Access Token with privs to create env'
$encodedValue = [Convert]::ToBase64String(
[Text.Encoding]::ASCII.GetBytes(
("{0}:{1}" -f '', $cred.GetNetworkCredential().Password)
)
)
$body = @{
name = 'test-pwsh-env';
description = 'test environment from APR'
} | ConvertTo-Json
$headers = @{
Accept = 'application/json;';
Authorization = "Basic {0}" -f $encodedValue
}
Invoke-RestMethod -Method POST -Uri $url -Body $body -Headers $headers -ContentType 'application/json'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment