如何使用 PowerShell 创建 Azure Devops Wiki 子页面
How to create Azure Devops Wiki SubPage with PowerShell
我需要在 Azure Devops Wiki 中创建一个子页面。
下面是创建主页的代码,如果我更改名称,则会创建新页面,但不会创建后续子页面。
官方文档中没有明确的订购或创建子页面的信息
https://docs.microsoft.com/fr-fr/rest/api/azure/devops/wiki/pages?view=azure-devops-rest-6.0
我怎样才能做到这一点?
$content = [IO.File]::ReadAllText("wiki\file.md")
$data= @{content=$content;} | ConvertTo-Json;
$OrganizationName = "organizationName"
$ProjectName = "ProjectName"
$WikiName = "WikiName"
$WikiPath = "MainPage"
$PAT="PAT Token"
$uri = "https://dev.azure.com/$OrganizationName/$ProjectName/_apis/wiki/wikis/$WikiName/pages?path=$WikiPath&api-version=6.0"
$Header = @{
'Authorization' = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
}
$params = @{
Uri = $uri;
Headers = $Header;
Method = 'Put';
ContentType = "application/json";
body = $data;
}
Invoke-RestMethod @params
从您的 Powershell Sample and Rest API url,您需要将主页路径添加到 url.
中的路径
https://dev.azure.com/$OrganizationName/$ProjectName/_apis/wiki/wikis/$WikiName/pages?path=MainPagePath/$WikiSubPagePath&api-version=6.0
例如:
$content = [IO.File]::ReadAllText("wiki\file.md")
$data= @{content=$content;} | ConvertTo-Json;
$OrganizationName = "organizationName"
$ProjectName = "ProjectName"
$WikiName = "WikiName"
$WikiPath = "MainPage"
$PAT="PAT Token"
$uri = "https://dev.azure.com/$OrganizationName/$ProjectName/_apis/wiki/wikis/$WikiName/pages?path=$WikiPath/$WikiSubPagePath&api-version=6.0"
$Header = @{
'Authorization' = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
}
$params = @{
Uri = $uri;
Headers = $Header;
Method = 'Put';
ContentType = "application/json";
body = $data;
}
Invoke-RestMethod @params
然后就可以在主页面下创建子页面了
我需要在 Azure Devops Wiki 中创建一个子页面。
下面是创建主页的代码,如果我更改名称,则会创建新页面,但不会创建后续子页面。 官方文档中没有明确的订购或创建子页面的信息 https://docs.microsoft.com/fr-fr/rest/api/azure/devops/wiki/pages?view=azure-devops-rest-6.0 我怎样才能做到这一点?
$content = [IO.File]::ReadAllText("wiki\file.md")
$data= @{content=$content;} | ConvertTo-Json;
$OrganizationName = "organizationName"
$ProjectName = "ProjectName"
$WikiName = "WikiName"
$WikiPath = "MainPage"
$PAT="PAT Token"
$uri = "https://dev.azure.com/$OrganizationName/$ProjectName/_apis/wiki/wikis/$WikiName/pages?path=$WikiPath&api-version=6.0"
$Header = @{
'Authorization' = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
}
$params = @{
Uri = $uri;
Headers = $Header;
Method = 'Put';
ContentType = "application/json";
body = $data;
}
Invoke-RestMethod @params
从您的 Powershell Sample and Rest API url,您需要将主页路径添加到 url.
中的路径https://dev.azure.com/$OrganizationName/$ProjectName/_apis/wiki/wikis/$WikiName/pages?path=MainPagePath/$WikiSubPagePath&api-version=6.0
例如:
$content = [IO.File]::ReadAllText("wiki\file.md")
$data= @{content=$content;} | ConvertTo-Json;
$OrganizationName = "organizationName"
$ProjectName = "ProjectName"
$WikiName = "WikiName"
$WikiPath = "MainPage"
$PAT="PAT Token"
$uri = "https://dev.azure.com/$OrganizationName/$ProjectName/_apis/wiki/wikis/$WikiName/pages?path=$WikiPath/$WikiSubPagePath&api-version=6.0"
$Header = @{
'Authorization' = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
}
$params = @{
Uri = $uri;
Headers = $Header;
Method = 'Put';
ContentType = "application/json";
body = $data;
}
Invoke-RestMethod @params
然后就可以在主页面下创建子页面了