I am creating a script that gets different types of information from my azuredevops projects, for example the name of the project, its repositories, its pipeline, task, etc. I already do all this perfectly, but now I only need to obtain certain projects, since there are projects in my azuredevops from which I do not need to obtain their information, since they are projects that could be "inactive" or simply not. I need your information. I think that perhaps through exceptions or saving the names in an array and iterating it could help but it is the first time I have made a script and it is difficult for me to understand how to implement it in powershell. I also saw that there is a method called "where" but I think it would be more complicated to use that. I leave my code that calls the api to get the projects. Any ideas would be helpful.
Name of some projects that I want to get: EANAll, EducationTest, Oppt1.
function projectsGet() {
$apiProjects="$Organization/_apis/projects?continuationToken=$ContinuationToken&$apiVersion"
$projects = @()
do {
$response = Invoke-WebRequest -Uri $projectsUri -Method Get -UseDefaultCredentials
$ContinuationToken=$response.Headers.'x-ms-continuationtoken'
$projectsData = $response.Content | ConvertFrom-Json
$projectsData.value | ForEach-Object {
$projectName=$_.name
$projectUni="$Organization/$projectName"
$projects+=$projectUni
}
$apiProjects="$Organization/_apis/projects?continuationToken=$ContinuationToken&$apiVersion"
} while ($null -ne $ContinuationToken)
return $projects
}
I found a very simple way and I think it's wrong since it only works for a specific project is putting an IF after entering the ForEach-Object and putting "if($_.name -eq "EANAII")" then do the following ... That is a very simple way, but I have 70+ projects in my Azure DevOps, 30 of which I don't want to show. If you have an idea that is helpful, I would appreciate it.
foreach($count in $nameProjectsActi){
if($_.name -eq $count){
$projectName=$_.name
$projectUri="$DevopsServer/$projectName"
$projectsList+=$projectUri
}
}
Well, a very manual solution is to add to the array all the names of the projects that you want to obtain and go through it during the obtaining of all the projects and validate if it is equal to what was obtained in the foreach.