11function Get-VcTag {
22 <#
33 . SYNOPSIS
4- Get tags from TLSPC
4+ Get tag names and values
55
66 . DESCRIPTION
77 Get 1 or all tags.
88 Tag values will be provided.
99
1010 . PARAMETER Tag
11- Tag name
11+ Tag name or name:value pair to get.
12+ If a value is provided, the tag must have that value to be returned.
1213
1314 . PARAMETER All
1415 Get all tags
@@ -26,6 +27,11 @@ function Get-VcTag {
2627
2728 Get a single tag
2829
30+ . EXAMPLE
31+ Get-VcTag -Tag 'MyTag:MyValue'
32+
33+ Get a single tag only if it has the specified value
34+
2935 . EXAMPLE
3036 Get-VcTag -All
3137
@@ -56,21 +62,52 @@ function Get-VcTag {
5662 process {
5763
5864 if ( $PSCmdlet.ParameterSetName -eq ' All' ) {
59- $values = Invoke-VenafiRestMethod - UriLeaf ' tags/values' | Select-Object - ExpandProperty values
60- $response = Invoke-VenafiRestMethod - UriLeaf ' tags' | Select-Object - ExpandProperty tags
61- }
62- else {
63- $response = Invoke-VenafiRestMethod - UriLeaf " tags/$Tag "
64- $values = Invoke-VenafiRestMethod - UriLeaf " tags/$Tag /values" | Select-Object - ExpandProperty values
65- }
65+ $allTags = Invoke-VenafiRestMethod - UriLeaf ' tags' | Select-Object - ExpandProperty tags
66+ $allValues = Invoke-VenafiRestMethod - UriLeaf ' tags/values' | Select-Object - ExpandProperty values
6667
67- if ( $response ) {
68- $response | Select-Object @ {' n' = ' tagId' ; ' e' = { $_.key } },
68+ $allTags | Select-Object @ {' n' = ' tagId' ; ' e' = { $_.key } },
6969 @ {
7070 ' n' = ' value'
7171 ' e' = {
7272 $thisId = $_.id
73- , @ (($values | Where-Object { $_.tagId -eq $thisId }).value)
73+ $thisTagValues = $allValues | Where-Object tagId -eq $thisId
74+ if ( $thisTagValues ) {
75+ @ ($thisTagValues.value )
76+ }
77+ else {
78+ $null
79+ }
80+ }
81+ }
82+ }
83+ else {
84+ if ($Tag.Contains (' :' )) {
85+ $requestName , $requestValue = $Tag.Split (' :' , 2 )
86+ }
87+ else {
88+ $requestName = $Tag
89+ }
90+
91+ $thisTag = Invoke-VenafiRestMethod - UriLeaf " tags/$requestName "
92+ $thisTagValues = Invoke-VenafiRestMethod - UriLeaf " tags/$requestName /values" | Select-Object - ExpandProperty values
93+
94+ if ( $thisTag ) {
95+
96+ if ( $requestValue ) {
97+ if ( $thisTagValues ) {
98+ if ( -not ( $requestValue -in $thisTagValues.value ) ) {
99+ Write-Verbose " The tag '$requestName ' exists but does not have a value of '$requestValue '"
100+ return
101+ }
102+ }
103+ else {
104+ Write-Verbose " The tag '$requestName ' was found but does not have any values"
105+ return
106+ }
107+ }
108+
109+ return @ {
110+ $thisTag.key = $thisTagValues.value
74111 }
75112 }
76113 }
0 commit comments