Last active
April 5, 2019 21:02
-
-
Save irwins/e91bccb02a83047c29eae9b4445ac503 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Author: I. Strachan | |
Version: 1.0 | |
Version History: | |
Purpose: Get az devops projects wrapper | |
#> | |
Function Get-AzDevOpsProject{ | |
[cmdletbinding()] | |
[Outputtype("Get-AzDevOpsProject.myDevOpsProjects")] | |
Param( | |
[ValidateNotNullorEmpty()] | |
[Parameter(Position = 0, HelpMessage = "Enter a azure devops project name", ParameterSetName = "name")] | |
[String[]]$Name, | |
[Parameter(HelpMessage = "Show project properties", ParameterSetName = "name")] | |
[Switch]$Show, | |
[Parameter(HelpMessage = "Get all azure devops projects", ParameterSetName = "all")] | |
[Switch]$All | |
) | |
Begin { | |
Write-Verbose "[BEGIN ] Starting: $($MyInvocation.Mycommand)" | |
#define a class for my az devops objects | |
Class myDevOpsProjects { | |
[String] $Name | |
[String] $Description | |
[String] $Id | |
[Int] $Revision | |
[String] $Visibility | |
#Constructor | |
myDevOpsProjects ($Name) { | |
$psObject = az devops project show -p $Name | ConvertFrom-Json | |
$this.Name = $Name.replace('"', '') | |
$this.Description = $psObject.Description | |
$this.Id = $psObject.Id | |
$this.Revision = $psObject.Revision | |
$this.Visibility = $psObject.Visibility | |
} | |
static [PSObject]show($Name){ | |
$psObject = az devops project show -p $Name | ConvertFrom-Json | |
return $psObject | |
} | |
} | |
} | |
Process { | |
$arrProjectNames = az devops project list --query '[].name' | ConvertFrom-Json | |
if ($all) { | |
Write-Verbose "[PROCESS] Getting all projects" | |
$names = $arrProjectNames | |
} | |
else{ | |
Write-Verbose "[PROCESS] Getting project $($name -join ', ')" | |
$names = $Name | |
} | |
foreach ($name in $names) { | |
Write-Verbose "[PROCESS] Processing $name" | |
if ($arrProjectNames -contains $name) { | |
if ($show){ | |
Write-Verbose "[PROCESS] Showing project properties $name" | |
[myDevOpsProjects]::show($name) | |
} | |
else{ | |
[myDevOpsProjects]::new($name) | |
} | |
} | |
else{ | |
Write-Warning "Failed to find a project named $name" | |
} | |
} | |
} | |
End { | |
Write-Verbose "[END ] Ending: $($MyInvocation.Mycommand)" | |
} | |
} | |
Get-AzDevOpsProject -All -Verbose |
isn't using an unqualified executable a security risk, especially in something that is supposed to be a reusable component?
The only thing you are missing is some error handling. You could add a #requires -module statement in the file,
Yeah... And esteemed colleague pointed that out to me.... 😉
Try/Catch didn't catch any errors, that's why I opted for show/query solution... I am curious though how to go about doing proper error-handeling for exe...
I feel a teachable moment coming on... 😃
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got the idea from Jeff Hicks!
MORE FUN WITH DOCKER CONTAINERS AND POWERSHELL
Here's the results on my private Project:
Note: you need az cli extension devops for this to work...
I guess this is the way to leverage az cli in PowerShell... The extesion list is growing rapidly!
Hope it's worth something to you...
Urv