Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
function Get-AzDoProjectProperties {
<#
.SYNOPSIS
Retrieves properties of specified Azure DevOps projects.

.DESCRIPTION
The Get-AzDoProjectProperties function retrieves properties of specified Azure DevOps projects within a given collection URI. It supports pipeline input for project names and collection URI.

.EXAMPLE
$Params = @{
CollectionUri = "https://dev.azure.com/organization"
ProjectName = "Project1"
}
Get-AzDoProjectProperties @Params

This example retrieves properties of the project named "Project1" in the specified Azure DevOps organization.

.EXAMPLE
$Params = @{
CollectionUri = "https://dev.azure.com/organization"
}
"Project1", "Project2" | Get-AzDoProjectProperties @Params

This example retrieves properties of multiple projects ("Project1" and "Project2") in the specified Azure DevOps organization.

.NOTES
This function requires the Validate-CollectionUri and Invoke-AzDoRestMethod helper functions to be defined in the scope.

.LINK
https://learn.microsoft.com/en-us/rest/api/azure/devops/core/projects/get-project-properties?view=azure-devops-rest-7.1&tabs=HTTP
#>
[CmdletBinding(SupportsShouldProcess)]
param (
# Collection Uri of the organization
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
[string]
$CollectionUri,

# Project where the Repos are contained
[Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)]
[string]
$ProjectName
)

begin {
Write-Verbose "Starting function: Get-AzDoProjectProperties"
}

process {
# somehow it will not work on project name, but will work like this:
$ProjectId = (Get-AzDoProject -CollectionUri $CollectionUri -ProjectName $ProjectName).ProjectID
$params = @{
uri = "$CollectionUri/_apis/projects/$ProjectId/Properties"
version = "7.2-preview.1"
method = 'GET'
}

if ($PSCmdlet.ShouldProcess($CollectionUri, "Get project $ProjectName properties")) {
$result = (Invoke-AzDoRestMethod @params).value
} else {
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params| ConvertTo-Json -Depth 10)"
}

if ($result) {
[PSCustomObject]@{
CollectionURI = $CollectionUri
ProjectName = $ProjectName
Properties = $result
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,35 @@ function Get-AzDoEnvironment {
Creates a Build Validation policy on a branch
.DESCRIPTION
Creates a Build Validation policy on a branch

.EXAMPLE
$params = @{
$Params = @{
CollectionUri = "https://dev.azure.com/contoso"
Name = "Policy 1"
RepoName = "Repo 1"
ProjectName = "Project 1"
Id = 1
ProjectName = "Project 1"
}
Set-AzDoBranchPolicyBuildValidation @params
Get-AzDoEnvironment @Params

This example creates a policy with splatting parameters
This example retrieves all environments in the specified project ("Project 1") in Azure DevOps.

.EXAMPLE
$env:SYSTEM_ACCESSTOKEN = '***'
New-AzDoPipeline -CollectionUri "https://dev.azure.com/contoso" -ProjectName "Project 1" -Name "Pipeline 1" -RepoName "Repo 1" -Path "main.yml"
| Set-AzDoBranchPolicyBuildValidation
$Params = @{
CollectionUri = "https://dev.azure.com/contoso"
ProjectName = "Project 1"
EnvironmentName = "Environment 1"
}
Get-AzDoEnvironment @Params

This example retrieves details of the environment named "Environment 1" in the specified project ("Project 1") in Azure DevOps.

.EXAMPLE
$Params = @{
CollectionUri = "https://dev.azure.com/contoso"
ProjectName = "Project 1"
EnvironmentName = @("Environment 1", "Environment 2")
}
Get-AzDoEnvironment @Params

This example creates a new Azure Pipeline and sets this pipeline as Build Validation policy on the main branch
This example retrieves details of multiple environments ("Environment 1" and "Environment 2") in the specified project ("Project 1") in Azure DevOps.

.OUTPUTS
[PSCustomObject]@{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
function Remove-AzDoEnvironment {
<#
.SYNOPSIS
Remove Environment from Azure DevOps.

.DESCRIPTION
This function removes an environment from Azure DevOps.

.EXAMPLE
Remove-AzDoEnvironment -CollectionUri "https://dev.azure.com/contoso" -ProjectName "Project 1" -EnvironmentName "Environment 1"

This example removes the environment named "Environment 1" from the specified project in Azure DevOps.

.EXAMPLE
Remove-AzDoEnvironment -CollectionUri "https://dev.azure.com/contoso" -ProjectName "Project 1" -EnvironmentName "Environment 1", "Environment 2"

This example removes multiple environments ("Environment 1" and "Environment 2") from the specified project in Azure DevOps.

.EXAMPLE
Remove-AzDoEnvironment -CollectionUri "https://dev.azure.com/contoso" -ProjectName "Project 1" -EnvironmentName 1

This example removes the environment with the ID 1 from the specified project in Azure DevOps.

.EXAMPLE
Remove-AzDoEnvironment -CollectionUri "https://dev.azure.com/contoso" -ProjectName "Project 1" -EnvironmentName 1, 2

This example removes multiple environments with IDs 1 and 2 from the specified project in Azure DevOps.

.EXAMPLE
Remove-AzDoEnvironment -CollectionUri "https://dev.azure.com/contoso" -ProjectName "Project 1" -EnvironmentName "Environment 1", 2

This example removes a mix of environments by name ("Environment 1") and ID (2) from the specified project in Azure DevOps.

.LINK
https://learn.microsoft.com/en-us/rest/api/azure/devops/environments/environments/delete?view=azure-devops-rest-7.2
#>
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
[OutputType([System.Collections.ArrayList])]
param (
# Collection URI. e.g. https://dev.azure.com/contoso.
# Azure Pipelines has a predefined variable for this.
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
[string]
$CollectionUri,

# Name of the project.
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)]
[string]
$ProjectName,

# Id or name of the environment.
# this is a string because a name can be used as well and will do a Get-AzDoEnvironment to get the ID.
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)]
[string[]]
$EnvironmentName
)

begin {
$result = @()
Write-Verbose "Starting function: Remove-AzDoEnvironment"
}

Process {

foreach ($Environment in $EnvironmentName) {
if ($Environment -ne [int]) {
$EnvironmentId = (Get-AzDoEnvironment -CollectionUri $CollectionUri -ProjectName $ProjectName -EnvironmentName $Environment).EnvironmentId

} else {
$EnvironmentId = $Environment
}

$params = @{
uri = "$CollectionUri/$ProjectName/_apis/pipelines/environments/$EnvironmentId"
version = "7.2-preview.1"
method = 'DELETE'
}

if ($PSCmdlet.ShouldProcess($CollectionUri, "Remove environment id: $($PSStyle.Bold)$EnvironmentId$($PSStyle.Reset)")) {
$result += Invoke-AzDoRestMethod @params
} else {
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params| ConvertTo-Json -Depth 10)"
}
}
if ($result) {
$result | ForEach-Object {
[PSCustomObject]@{
CollectionUri = $CollectionUri
ProjectName = $ProjectName
Response = $_
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
function Get-AzDoPipelineBranchControl {
<#
.SYNOPSIS
Retrieves branch policy configurations of specified Azure DevOps projects.

.DESCRIPTION
The Get-AzDoPipelineBranchControl function retrieves branch policy configurations of specified Azure DevOps projects within a given collection URI.
It supports pipeline input for project names and collection URI.

.EXAMPLE
$Params = @{
CollectionUri = "https://dev.azure.com/organization"
ProjectName = "Project1"
}
Get-AzDoPipelineBranchControl @Params

This example retrieves branch policy configurations for the project named "Project1" in the specified Azure DevOps organization.

.EXAMPLE
$Params = @{
CollectionUri = "https://dev.azure.com/organization"
}
"Project1", "Project2" | Get-AzDoPipelineBranchControl @Params

This example retrieves branch policy configurations for multiple projects ("Project1" and "Project2") in the specified Azure DevOps organization.

.EXAMPLE
$Params = @{
CollectionUri = "https://dev.azure.com/organization"
ProjectName = "Project1"
RepositoryId = "12345"
RefName = "refs/heads/main"
PolicyType = "Build"
}
Get-AzDoPipelineBranchControl @Params

This example retrieves branch policy configurations for the "main" branch in the repository with ID "12345" in the project "Project1" in the specified Azure DevOps organization, filtered by the "Build" policy type.

.NOTES
This function requires the Validate-CollectionUri and Invoke-AzDoRestMethod helper functions to be defined in the scope.

.LINK
https://learn.microsoft.com/en-us/rest/api/azure/devops/git/policy-configurations/list?view=azure-devops-rest-5.0#policyconfiguration
#>
[CmdletBinding(SupportsShouldProcess)]
param (
# Collection URI of the organization
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
[string]
$CollectionUri,

# Project where the policies are defined
[Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)]
[string]
$ProjectName,

# Repository ID (optional)
[Parameter(ValueFromPipelineByPropertyName)]
[string]
$RepositoryId,

# Ref name (branch) to filter policies (optional)
[Parameter(ValueFromPipelineByPropertyName)]
[string]
$RefName,

# Policy type to filter results (optional)
[Parameter(ValueFromPipelineByPropertyName)]
[string]
$PolicyType
)

begin {
Write-Verbose "Starting function: Get-AzDoPipelineBranchControl"
}

process {
# somehow it will not work on project name, but will work like this:
$ProjectId = (Get-AzDoProject -CollectionUri $CollectionUri -ProjectName $ProjectName).ProjectID

$queryParams = @()
if ($RepositoryId) {
$queryParams += "repositoryId=$RepositoryId"
}
if ($RefName) {
$queryParams += "refName=$RefName"
}
if ($PolicyType) {
$queryParams += "policyType=$PolicyType"
}
$queryString = $queryParams -join "&"

$params = @{
Uri = "$CollectionUri/$ProjectId/_apis/git/policy/configurations"
Version = "7.1"
Method = 'GET'
}
if (-not([string]::IsNullOrEmpty(($queryString)))) {
$params.QueryParameters = $queryString
}
if ($PSCmdlet.ShouldProcess($CollectionUri, "Get branch policies for project $ProjectName")) {
$result = (Invoke-AzDoRestMethod @params).value
} else {
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params | ConvertTo-Json -Depth 10)"
}
if ($result) {

$result | ForEach-Object {
[PSCustomObject]@{
CollectionUri = $CollectionUri
ProjectName = $ProjectName
IsEnabled = $_.isEnabled
IsBlocking = $_.isBlocking
Settings = $_.settings
PolicyId = $_.id
PolicyUrl = $_.url
PolicyType = $_.PolicyTypeRef
CreatedBy = $_.createdBy
CreatedDate = $_.createdDate
}
}
}
}
}
Loading
Loading