Skip to content

Instantly share code, notes, and snippets.

@stefanstranger
Created April 12, 2020 10:02
Show Gist options
  • Save stefanstranger/7f049f149f11d14dd01947175d144af9 to your computer and use it in GitHub Desktop.
Save stefanstranger/7f049f149f11d14dd01947175d144af9 to your computer and use it in GitHub Desktop.
Create Azure DevOps WIKI Documentation
<#
PowerShell script to create Azure DevOps WIKI Markdown Documentation
https://docs.microsoft.com/en-US/rest/api/azure/devops/wiki/pages/create%20or%20update?view=azure-devops-rest-5.0#examples
https://medium.com/digikare/create-automatic-release-notes-on-azuredevops-f235376ec533
Requirements:
- PSDocs PowerShell Module (Install-Module -Name PSDocs)
#>
#region variables
$OrganizationName = '[enter Azure DevOps Organization Name]'
$ProjectName = '[enter Azure DevOps Project Name]'
$PAT = '[enter Personal Access Token]'
$WikiName = '{projectname}.wiki'
#endregion
#region Create WIKI MarkDown Content
Document 'Create-MarkdownTable' {
'Demo for creating WIKI Pages'
Section 'Process Table' {
$InputObject | Table
}
}
# Generate markdown for the inline document
$options = New-PSDocumentOption -Option @{ 'Markdown.UseEdgePipes' = 'Always'; 'Markdown.ColumnPadding' = 'None' };
$null = [PSDocs.Configuration.PSDocumentOption]$Options
$InputObject = Get-Service | Select-Object -First 5
$Content = Create-MarkdownTable -InputObject $InputObject -Option $Options -PassThru
#endregion
#region Create WIKI page
$uri = ('https://dev.azure.com/{0}/{1}/_apis/wiki/wikis/{2}/pages?path={3}&api-version=5.0' -f $OrganizationName, $ProjectName, $WikiName, 'demopage')
$Header = @{
'Authorization' = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
}
$params = @{
'Uri' = $uri
'Headers' = $Header
'Method' = 'Put'
'ContentType' = 'application/json; charset=utf-8'
'body' = @{content = $content; } | ConvertTo-Json
}
Invoke-RestMethod @params
#endregion
#region delete page
$uri = ('https://dev.azure.com/{0}/{1}/_apis/wiki/wikis/{2}/pages?path={3}&api-version=5.0' -f $OrganizationName, $ProjectName, $WikiName, 'demopage')
$Header = @{
'Authorization' = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
}
$params = @{
'Uri' = $uri
'Headers' = $Header
'Method' = 'Delete'
'ContentType' = 'application/json; charset=utf-8'
}
Invoke-RestMethod @params
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment