Skip to content

Instantly share code, notes, and snippets.

@mirontoli
Last active February 21, 2022 21:50
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 mirontoli/b64316354171b54d1d4d76f4de763184 to your computer and use it in GitHub Desktop.
Save mirontoli/b64316354171b54d1d4d76f4de763184 to your computer and use it in GitHub Desktop.
$auth = "apitest:j2vsnu3obx55ekwjkfdxfpljziiy27qkuku5jitsx73wvegpdpeq"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($auth)
$token = [System.Convert]::ToBase64String($bytes)
$headers = @{ Authorization = "Basic $token" }
$org = "tolle" # my sandbox Azure DevOps organization
$url = "https://dev.azure.com/$org/_apis/git/repositories?api-version=6.0"
# $projectId = "288c25f0-4bc9-4139-9337-cdbb328f1af8"
@("repo001", "repo002", "repo003") | ForEach-Object {
$name = $_
$body = @"
{
"name": "$name",
"project": {
"id": "$projectId"
}
}
"@
Invoke-WebRequest -Uri $url -Method POST -Headers $headers -Body $body -ContentType "application/json"
}
$org = "tolle"
$url = "https://dev.azure.com/$org/_apis/projects?api-version=6.0"
$projectCall = Invoke-WebRequest -Uri $url -Method GET -Headers $headers
$projects = $projectCall | ConvertFrom-Json | Select-Object -ExpandProperty value
$projectName = "try-api" # the current Azure DevOps project
$project = $projects | Where-Object { $_.name -eq $projectName }
$projectId = $project.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment