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')] [string]$ApiVersion = '7.1-preview.1' ) begin { Write-Verbose "GetProcess : Begin Processing"; Write-Verbose " ProcessId : $($ProcessId)"; Write-Verbose " ApiVersion : $($ApiVersion)"; try { $ErrorActionPreference = 'Stop'; $Error.Clear(); # # Are we connected # if ($Global:azDevOpsConnected) { if ($ProcessId) { $Uri = $Global:azDevOpsOrg + "_apis/process/processes/$($ProcessId)?api-version=$($ApiVersion)"; return (Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Get -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference); } else { $Uri = $Global:azDevOpsOrg + "_apis/process/processes?api-version=$($ApiVersion)" return (Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Get -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference).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')] [string]$ApiVersion = '7.1-preview.4' ) begin { Write-Verbose "GetProject : Begin Processing"; Write-Verbose " ProjectId : $($ProjectId)"; Write-Verbose " ApiVersion : $($ApiVersion)"; try { $ErrorActionPreference = 'Stop'; $Error.Clear(); # # Are we connected # if ($Global:azDevOpsConnected) { if ($ProjectId) { $Uri = $Global:azDevOpsOrg + "_apis/projects/$($ProjectId)?api-version=$($ApiVersion)"; return (Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Get -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference); } else { $Uri = $Global:azDevOpsOrg + "_apis/projects?api-version=$($ApiVersion)"; return (Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Get -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference).Value; } } } catch { 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')] [string]$ApiVersion = '7.1-preview.1' ) begin { Write-Verbose "GetBuild : Begin Processing"; Write-Verbose " ProjectId : $($Project.Id)"; Write-Verbose " ApiVersion : $($ApiVersion)"; try { $ErrorActionPreference = 'Stop'; $Error.Clear(); # # Are we connected # if ($Global:azDevOpsConnected) { $Uri = $Global:azDevOpsOrg + "_apis/projects/$($Project.id)/properties?api-version=$($ApiVersion)"; return (Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Get -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference).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')] [string]$ApiVersion = '7.1-preview.4' ) begin { Write-Verbose "NewProject : Begin Processing"; Write-Verbose " Name : $($BuildId)"; Write-Verbose " Description : $($BuildId)"; Write-Verbose " ApiVersion : $($ApiVersion)"; try { $ErrorActionPreference = 'Stop'; $Error.Clear(); # # Are we connected # if ($Global:azDevOpsConnected) { $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)"; 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; } until ($Status.status -eq 'succeeded') Start-Sleep -Seconds 1; 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')] [string]$ApiVersion = '7.1-preview.4' ) begin { Write-Verbose "RemoveProject : Begin Processing"; Write-Verbose " ProjectId : $($Project.Id)"; Write-Verbose " ApiVersion : $($ApiVersion)"; try { $ErrorActionPreference = 'Stop'; $Error.Clear(); # # Are we connected # if ($Global:azDevOpsConnected) { $Uri = $Global:azDevOpsOrg + "_apis/projects/$($Project.id)?api-version=$($ApiVersion)"; 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-AdoOperations -OperationId $Result.id -Verbose:$VerbosePreference; Write-Verbose $Status.status; } 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')] [string]$ApiVersion = '7.1-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)"; try { $ErrorActionPreference = 'Stop'; $Error.Clear(); # # Are we connected # if ($Global:azDevOpsConnected) { $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)"; 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')] [string]$ApiVersion = '7.1-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(); # # Are we connected # if ($Global:azDevOpsConnected) { if ($PSCmdlet.ParameterSetName -eq 'ProjectId') { $Project = Get-AdoProject -ProjectId $ProjectId -Verbose:$VerbosePreference; } switch ($PSCmdlet.ParameterSetName) { 'Project' { if ($TeamId) { $Uri = $Global:azDevOpsOrg + "_apis/projects/$($Project.Id)/teams/$($TeamId)?api-version=$($ApiVersion)"; return (Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Get -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference); } else { $Uri = $Global:azDevOpsOrg + "_apis/projects/$($Project.Id)/teams/?api-version=$($ApiVersion)"; return (Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Get -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference).Value; } } default { $Uri = $Global:azDevOpsOrg + "_apis/teams?api-version=$($ApiVersion)"; return (Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Get -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference).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')] [string]$ApiVersion = '7.1-preview.3' ) 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(); # # Are we connected # if ($Global:azDevOpsConnected) { if ($PSCmdlet.ParameterSetName -eq 'ProjectId') { $Project = Get-AdoProject -ProjectId $ProjectId -Verbose:$VerbosePreference; } $Team = Get-AdoTeam -ProjectId $Project.Id -TeamId $TeamId -Verbose:$VerbosePreference; switch ($PSCmdlet.ParameterSetName) { 'Project' { if ($TeamId) { $Uri = $Global:azDevOpsOrg + "_apis/projects/$($Project.id)/teams/$($Team.id)/members?api-version=$($ApiVersion)" return ((Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Get -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference).Value | Select-Object -ExpandProperty Identity); } else { foreach ($Team in Get-AdoTeam -ProjectId $Project.Id) { $Uri = $Global:azDevOpsOrg + "_apis/projects/$($Project.Id)/teams/$($Team.id)/members?api-version=$($ApiVersion)" return ((Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method Get -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference).Value | Select-Object -ExpandProperty Identity); } } } } } } 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')] [string]$ApiVersion = '7.1-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(); # # Are we connected # if ($Global:azDevOpsConnected) { $Body = @{ "name" = $Name "description" = $Description } | ConvertTo-Json -Depth 5 -Compress; $Uri = $Global:azDevOpsOrg + "_apis/projects/$($Project.id)/teams/?api-version=$($ApiVersion)"; 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')] [string]$ApiVersion = '7.1-preview.3' ) begin { Write-Verbose "RemoveTeam : Begin Processing"; Write-Verbose " ProjectId : $($Project.Id)"; Write-Verbose " TeamId : $($TeamId)"; Write-Verbose " ApiVersion : $($ApiVersion)"; try { $ErrorActionPreference = 'Stop'; $Error.Clear(); # # Are we connected # if ($Global:azDevOpsConnected) { $Project = Get-AdoProject -ProjectId $ProjectId -Verbose:$VerbosePreference; $Team = Get-AdoTeam -ProjectId $ProjectId -TeamId $TeamId -Verbose:$VerbosePreference; $Uri = $Global:azDevOpsOrg + "_apis/projects/$($Project.id)/teams/$($Team.id)?api-version=$($ApiVersion)" if ($PSCmdlet.ShouldProcess("Delete", "Remove team $($Team.name) from $($Project.name) Azure Devops Projects")) { $Result = Invoke-AdoEndpoint -Uri ([System.Uri]::new($Uri)) -Method DELETE -Headers $Global:azDevOpsHeader -Verbose:$VerbosePreference; if (!($Result)) { return "Team : $($Team.id) removed from Project : $($Project.id)"; } } } } 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')] [string]$ApiVersion = '7.1-preview.3' ) begin { Write-Verbose "UpdateTeam : Process Record"; Write-Verbose " Name : $($Name)"; Write-Verbose " Description : $($Description)"; Write-Verbose " TeamId : $($Team.Id)"; Write-Verbose " ApiVersion : $($ApiVersion)"; try { $ErrorActionPreference = 'Stop'; $Error.Clear(); # # Are we connected # if ($Global:azDevOpsConnected) { $Body = @{ "name" = $Name "description" = $Description } | ConvertTo-Json -Depth 5 -Compress; $Uri = $Global:azDevOpsOrg + "_apis/projects/$($Team.projectid)/teams/$($Team.id)?api-version=$($ApiVersion)"; if ($PSCmdlet.ShouldProcess("Update", "Update new team in $($Project.name) 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]' |