core/core.psm1
Write-Verbose 'Importing from [D:\CODE\projects\Azure-Devops-PowerShell-Module\AzDevOps\AzDevOps\core\processes]' # .GetProcess function Get-Process { [CmdletBinding( HelpURI = 'https://github.com/Azure-Devops-PowerShell-Module/processes/blob/master/docs/Get-AdoProcess.md#get-adoprocess', PositionalBinding = $true )] [OutputType([Object])] param ( [Parameter(Mandatory = $false)] [Guid]$ProcessId, [Parameter(Mandatory = $false)] [ValidateSet('5.1', '7.1-preview.1','7.2-preview.1')] [string]$ApiVersion = '7.2-preview.1' ) begin { Write-Verbose "GetProcess: Begin Processing" Write-Verbose "ProcessId: $($ProcessId)" Write-Verbose "ApiVersion: $($ApiVersion)" } process { try { $ErrorActionPreference = 'Stop' $Error.Clear() if (-not $Global:azDevOpsConnected) { throw "Not connected to Azure DevOps. Please connect using Connect-AzDevOps." } if ($ProcessId) { $Uri = "$($Global:azDevOpsOrg)_apis/process/processes/$($ProcessId)?api-version=$($ApiVersion)" } else { $Uri = "$($Global:azDevOpsOrg)_apis/process/processes?api-version=$($ApiVersion)" } Write-Verbose "Uri: $($Uri)" $Response = Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Get -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference if ($ProcessId) { return $Response } else { return $Response.Value } } catch { throw $_ } } } Write-Verbose 'Importing from [D:\CODE\projects\Azure-Devops-PowerShell-Module\AzDevOps\AzDevOps\core\projects]' # .GetProject function Get-Project { [CmdletBinding( HelpURI = 'https://github.com/Azure-Devops-PowerShell-Module/projects/blob/master/docs/Get-AdoProject.md#get-adoproject', PositionalBinding = $true )] [OutputType([Object])] param ( [Parameter(Mandatory = $false)] [Guid]$ProjectId, [Parameter(Mandatory = $false)] [ValidateSet('5.1', '7.1-preview.4','7.2-preview.4')] [string]$ApiVersion = '7.2-preview.4' ) begin { Write-Verbose "GetProject: Begin Processing" Write-Verbose "ProjectId: $($ProjectId)" Write-Verbose "ApiVersion: $($ApiVersion)" } process { try { $ErrorActionPreference = 'Stop' $Error.Clear() if (-not $Global:azDevOpsConnected) { throw "Not connected to Azure DevOps. Please connect using Connect-AzDevOps." } if ($ProjectId) { $Uri = "$($Global:azDevOpsOrg)_apis/projects/$($ProjectId)?api-version=$($ApiVersion)" } else { $Uri = "$($Global:azDevOpsOrg)_apis/projects?api-version=$($ApiVersion)" } Write-Verbose "Uri: $($Uri)" $Response = Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Get -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference if ($ProjectId) { return $Response } else { return $Response.Value } } catch { Write-Error "Error retrieving project(s): $($_)" throw $_ } } } # .GetProjectProperty function Get-ProjectProperty { [CmdletBinding( HelpURI = 'https://github.com/Azure-Devops-PowerShell-Module/projects/blob/master/docs/Get-AdoProjectProperty.md#get-adoprojectproperty', PositionalBinding = $true )] [OutputType([Object])] param ( [Parameter(ValueFromPipeline)] [object]$Project, [Parameter(Mandatory = $false)] [ValidateSet('5.1-preview.1', '7.1-preview.1', '7.2-preview.1')] [string]$ApiVersion = '7.2-preview.1' ) begin { Write-Verbose "GetBuild: Begin Processing" Write-Verbose "ProjectId: $($Project.Id)" Write-Verbose "ApiVersion: $($ApiVersion)" } process { try { $ErrorActionPreference = 'Stop' $Error.Clear() if (-not $Global:azDevOpsConnected) { throw "Not connected to Azure DevOps. Please connect using Connect-AzDevOps." } $Uri = "$($Global:azDevOpsOrg)_apis/projects/$($Project.Id)/properties?api-version=$($ApiVersion)" Write-Verbose "Uri: $($Uri)" $Response = Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Get -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference return $Response.Value } catch { throw $_ } } } # .NewProject function New-Project { [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low', HelpURI = 'https://github.com/Azure-Devops-PowerShell-Module/projects/blob/master/docs/New-AdoProject.md#new-Adoproject', PositionalBinding = $true)] [OutputType([Object])] param ( [Parameter(Mandatory = $true)] [string]$Name, [Parameter(Mandatory = $false)] [string]$Description, [Parameter(Mandatory = $false)] [ValidateSet('5.1', '7.1-preview.4', '7.2-preview.4')] [string]$ApiVersion = '7.2-preview.4' ) begin { Write-Verbose "NewProject: Begin Processing" Write-Verbose "Name: $($Name)" Write-Verbose "Description: $($Description)" Write-Verbose "ApiVersion: $($ApiVersion)" } process { try { $ErrorActionPreference = 'Stop' $Error.Clear() if (-not $Global:azDevOpsConnected) { throw "Not connected to Azure DevOps. Please connect using Connect-AzDevOps." } $Body = @{ "name" = $Name "description" = $Description "capabilities" = @{ "versioncontrol" = @{ "sourceControlType" = "Git" } "processTemplate" = @{ "templateTypeId" = "b8a3a935-7e91-48b8-a94c-606d37c3e9f2" } } } | ConvertTo-Json -Depth 5 -Compress $Uri = "$($Global:azDevOpsOrg)_apis/projects?api-version=$($ApiVersion)" Write-Verbose "Uri: $($Uri)" if ($PSCmdlet.ShouldProcess("Create", "Create new project in $($Global:azDevOpsOrg) Azure DevOps")) { $Result = Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method POST -Headers $Global:azDevOpsHeader -Body $Body -ContentType "application/json" -Verbose:$VerbosePreference } do { $Status = Get-AdoOperations -OperationId $Result.id -Verbose:$VerbosePreference Write-Verbose "Status: $($Status.status)" Start-Sleep -Seconds 1 } until ($Status.status -eq 'succeeded') Get-AdoProject -Verbose:$VerbosePreference | Where-Object -Property name -eq $Name } catch { throw $_ } } } # .RemoveProject function Remove-Project { [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High', HelpURI = 'https://github.com/Azure-Devops-PowerShell-Module/projects/blob/master/docs/Remove-AdoProject.md#remove-Adoproject', PositionalBinding = $true)] [OutputType([String])] param ( [Parameter(Mandatory = $true)] [object]$Project, [Parameter(Mandatory = $false)] [ValidateSet('5.1', '7.1-preview.4', '7.2-preview.4')] [string]$ApiVersion = '7.2-preview.4' ) begin { Write-Verbose "RemoveProject: Begin Processing" Write-Verbose "ProjectId: $($Project.Id)" Write-Verbose "ApiVersion: $($ApiVersion)" } process { try { $ErrorActionPreference = 'Stop' $Error.Clear() if (-not $Global:azDevOpsConnected) { throw "Not connected to Azure DevOps. Please connect using Connect-AzDevOps." } $Uri = "$($Global:azDevOpsOrg)_apis/projects/$($Project.Id)?api-version=$($ApiVersion)" Write-Verbose "Uri: $($Uri)" if ($PSCmdlet.ShouldProcess("Remove", "Delete $($Project.Name) from $($Global:azDevOpsOrg) Azure DevOps")) { $Result = Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Delete -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference } do { $Status = Get-AdoOperation -OperationId $Result.id -Verbose:$VerbosePreference Write-Verbose "Status: $($Status.status)" Start-Sleep -Seconds 1 } until ($Status.status -eq 'succeeded') return "Project $($Project.Name) removed" } catch { throw $_ } } } # .UpdateProject function Update-Project { [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium', HelpURI = 'https://github.com/Azure-Devops-PowerShell-Module/projects/blob/master/docs/Update-AdoProject.md#update-adoproject', PositionalBinding = $true)] [OutputType([Object])] param ( [Parameter(Mandatory = $false)] [string]$Name, [Parameter(Mandatory = $false)] [string]$Description, [Parameter(Mandatory = $true)] [object]$Project, [Parameter(Mandatory = $false)] [ValidateSet('5.1', '7.1-preview.4', '7.2-preview.4')] [string]$ApiVersion = '7.2-preview.4' ) begin { Write-Verbose "UpdateProject: Begin Processing" Write-Verbose "Name: $($Name)" Write-Verbose "Description: $($Description)" Write-Verbose "ProjectId: $($Project.Id)" Write-Verbose "ApiVersion: $($ApiVersion)" } process { try { $ErrorActionPreference = 'Stop' $Error.Clear() if (-not $Global:azDevOpsConnected) { throw "Not connected to Azure DevOps. Please connect using Connect-AzDevOps." } $Body = @{ "name" = $Name "description" = $Description "capabilities" = @{ "versioncontrol" = @{ "sourceControlType" = "Git" } "processTemplate" = @{ "templateTypeId" = "b8a3a935-7e91-48b8-a94c-606d37c3e9f2" } } } | ConvertTo-Json -Depth 5 -Compress $Uri = "$($Global:azDevOpsOrg)_apis/projects/$($Project.Id)?api-version=$($ApiVersion)" Write-Verbose "Uri: $($Uri)" if ($PSCmdlet.ShouldProcess("Modify", "Update $($Project.Name) values")) { Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method PATCH -Headers $Global:azDevOpsHeader -Body $Body -ContentType "application/json" -Verbose:$VerbosePreference } } catch { throw $_ } } } Write-Verbose 'Importing from [D:\CODE\projects\Azure-Devops-PowerShell-Module\AzDevOps\AzDevOps\core\teams]' # .GetTeam function Get-Team { [CmdletBinding( HelpURI = 'https://github.com/Azure-Devops-PowerShell-Module/teams/blob/master/docs/Get-AdoTeam.md#get-adoteam', PositionalBinding = $true )] [OutputType([Object])] param ( [Parameter(ValueFromPipeline, Mandatory = $false, ParameterSetName = 'Project')] [object]$Project, [Parameter(Mandatory = $false, ParameterSetName = 'ProjectId')] [Guid]$ProjectId, [Parameter(Mandatory = $false, ParameterSetName = 'Project')] [Parameter(Mandatory = $false, ParameterSetName = 'ProjectId')] [Guid]$TeamId, [Parameter(Mandatory = $false)] [ValidateSet('5.1-preview.3', '7.1-preview.3', '7.2-preview.3')] [string]$ApiVersion = '7.2-preview.3' ) process { Write-Verbose "GetTeam: Process Record" if ($PSCmdlet.ParameterSetName -eq 'Project') { Write-Verbose "ProjectId: $($Project.Id)" } else { Write-Verbose "ProjectId: $($ProjectId)" } Write-Verbose "TeamId: $($TeamId)" Write-Verbose "ApiVersion: $($ApiVersion)" try { $ErrorActionPreference = 'Stop' $Error.Clear() if (-not $Global:azDevOpsConnected) { throw "Not connected to Azure DevOps. Please connect using Connect-AzDevOps." } $BaseUri = if ($PSCmdlet.ParameterSetName -eq 'Project') { "$($Global:azDevOpsOrg)_apis/projects/$($Project.Id)/teams" } else { "$($Global:azDevOpsOrg)_apis/projects/$($ProjectId)/teams" } if ($TeamId) { $Uri = "$($BaseUri)/$($TeamId)?api-version=$($ApiVersion)" } else { $Uri = "$($BaseUri)?api-version=$($ApiVersion)" } Write-Verbose "Uri: $($Uri)" $Response = Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Get -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference if ($TeamId) { return $Response } else { return $Response.Value } } catch { throw $_ } } } # .GetTeamMember function Get-TeamMember { [CmdletBinding( HelpURI = 'https://github.com/Azure-Devops-PowerShell-Module/teams/blob/master/docs/Get-AdoTeamMember.md#get-adoteammember', PositionalBinding = $true )] [OutputType([Object])] param ( [Parameter(ValueFromPipeline, Mandatory = $false, ParameterSetName = 'Project')] [object]$Project, [Parameter(Mandatory = $false, ParameterSetName = 'ProjectId')] [Guid]$ProjectId, [Parameter(Mandatory = $false, ParameterSetName = 'Project')] [Parameter(Mandatory = $false, ParameterSetName = 'ProjectId')] [Guid]$TeamId, [Parameter(Mandatory = $false)] [ValidateSet('5.1-preview.3', '7.1-preview.3', '7.2-preview.2')] [string]$ApiVersion = '7.2-preview.2' ) process { Write-Verbose "GetTeamMember: Process Record" if ($PSCmdlet.ParameterSetName -eq 'Project') { Write-Verbose "ProjectId: $($Project.Id)" } else { Write-Verbose "ProjectId: $($ProjectId)" } Write-Verbose "TeamId: $($TeamId)" Write-Verbose "ApiVersion: $($ApiVersion)" try { $ErrorActionPreference = 'Stop' $Error.Clear() if (-not $Global:azDevOpsConnected) { throw "Not connected to Azure DevOps. Please connect using Connect-AzDevOps." } $BaseUri = if ($PSCmdlet.ParameterSetName -eq 'Project') { "$($Global:azDevOpsOrg)_apis/projects/$($Project.Id)/teams" } else { "$($Global:azDevOpsOrg)_apis/projects/$($ProjectId)/teams" } if ($TeamId) { $Uri = "$($BaseUri)/$($TeamId)/members?api-version=$($ApiVersion)" Write-Verbose "Uri: $($Uri)" return (Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Get -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference).Value | Select-Object -ExpandProperty Identity } else { $TeamsUri = "$($BaseUri)?api-version=$($ApiVersion)" Write-Verbose "TeamsUri: $($TeamsUri)" $Teams = (Invoke-AdoEndpoint -Uri ([System.Uri]::new($TeamsUri)) -Method Get -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference).Value $Members = @() foreach ($Team in $Teams) { $Uri = "$($BaseUri)/$($Team.id)/members?api-version=$($ApiVersion)" Write-Verbose "Uri: $($Uri)" $Members += (Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Get -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference).Value | Select-Object -ExpandProperty Identity } return $Members } } catch { throw $_ } } } # .NewTeam function New-Team { [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low', HelpURI = 'https://github.com/Azure-Devops-PowerShell-Module/teams/blob/master/docs/New-AdoTeam.md#new-adoteam', PositionalBinding = $true)] [OutputType([Object])] param ( [Parameter(Mandatory = $true)] [string]$Name, [Parameter(Mandatory = $false)] [string]$Description, [Parameter(ValueFromPipeline)] [object]$Project, [Parameter(Mandatory = $false)] [ValidateSet('5.1-preview.3', '7.1-preview.3', '7.2-preview.3')] [string]$ApiVersion = '7.2-preview.3' ) process { Write-Verbose "NewTeam: Process Record" Write-Verbose "Name: $($Name)" Write-Verbose "Description: $($Description)" Write-Verbose "ProjectId: $($Project.Id)" Write-Verbose "ApiVersion: $($ApiVersion)" try { $ErrorActionPreference = 'Stop' $Error.Clear() if (-not $Global:azDevOpsConnected) { throw "Not connected to Azure DevOps. Please connect using Connect-AzDevOps." } $Body = @{ "name" = $Name "description" = $Description } | ConvertTo-Json -Depth 5 -Compress $Uri = "$($Global:azDevOpsOrg)_apis/projects/$($Project.Id)/teams/?api-version=$($ApiVersion)" Write-Verbose "Uri: $($Uri)" if ($PSCmdlet.ShouldProcess("Create", "Create new team in $($Project.Name) Azure DevOps Projects")) { return Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Post -Headers $Global:azDevOpsHeader -Body $Body -ContentType "application/json" -Verbose:$VerbosePreference } } catch { throw $_ } } } # .RemoveTeam function Remove-Team { [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High', HelpURI = 'https://github.com/Azure-Devops-PowerShell-Module/teams/blob/master/docs/Remove-AdoTeam.md#remove-adoteam', PositionalBinding = $true)] [OutputType([string])] param ( [Parameter(Mandatory = $true)] [Guid]$ProjectId, [Parameter(Mandatory = $true)] [Guid]$TeamId, [Parameter(Mandatory = $false)] [ValidateSet('5.1-preview.3', '7.1-preview.3', '7.2-preview.3')] [string]$ApiVersion = '7.2-preview.3' ) begin { Write-Verbose "RemoveTeam: Begin Processing" Write-Verbose "ProjectId: $($ProjectId)" Write-Verbose "TeamId: $($TeamId)" Write-Verbose "ApiVersion: $($ApiVersion)" } process { try { $ErrorActionPreference = 'Stop' $Error.Clear() if (-not $Global:azDevOpsConnected) { throw "Not connected to Azure DevOps. Please connect using Connect-AzDevOps." } $Uri = "$($Global:azDevOpsOrg)_apis/projects/$($ProjectId)/teams/$($TeamId)?api-version=$($ApiVersion)" Write-Verbose "Uri: $($Uri)" if ($PSCmdlet.ShouldProcess("Delete", "Remove team with ID $($TeamId) from project with ID $($ProjectId)")) { $Result = Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method DELETE -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference if (-not $Result) { return "Team: $($TeamId) removed from Project: $($ProjectId)" } } } catch { throw $_ } } } # .UpdateTeam function Update-Team { [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low', HelpURI = 'https://github.com/Azure-Devops-PowerShell-Module/teams/blob/master/docs/Update-AdoTeam.md#update-adoteam', PositionalBinding = $true)] [OutputType([Object])] param ( [Parameter(Mandatory = $false)] [string]$Name, [Parameter(Mandatory = $false)] [string]$Description, [Parameter(ValueFromPipeline)] [object]$Team, [Parameter(Mandatory = $false)] [ValidateSet('5.1-preview.3', '7.1-preview.3', '7.2-preview.3')] [string]$ApiVersion = '7.2-preview.3' ) begin { Write-Verbose "UpdateTeam: Begin Processing" Write-Verbose "Name: $($Name)" Write-Verbose "Description: $($Description)" Write-Verbose "TeamId: $($Team.Id)" Write-Verbose "ApiVersion: $($ApiVersion)" } process { try { $ErrorActionPreference = 'Stop' $Error.Clear() if (-not $Global:azDevOpsConnected) { throw "Not connected to Azure DevOps. Please connect using Connect-AzDevOps." } $Body = @{ "name" = $Name "description" = $Description } | ConvertTo-Json -Depth 5 -Compress $Uri = "$($Global:azDevOpsOrg)_apis/projects/$($Team.projectId)/teams/$($Team.Id)?api-version=$($ApiVersion)" Write-Verbose "Uri: $($Uri)" if ($PSCmdlet.ShouldProcess("Update", "Update team in Azure DevOps Projects")) { return Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method PATCH -Body $Body -ContentType "application/json" -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference } } catch { throw $_ } } } Write-Verbose 'Importing from [D:\CODE\projects\Azure-Devops-PowerShell-Module\AzDevOps\AzDevOps\core\core.psd1]' Write-Verbose 'Importing from [D:\CODE\projects\Azure-Devops-PowerShell-Module\AzDevOps\AzDevOps\core\core.psm1]' |