@@ -157,33 +157,28 @@ Specifies the method used for the web request. The acceptable values for this pa
157157 )
158158
159159 begin {
160+ # From [Irregular](https://github.com/StartAutomating/Irregular):
161+ # ?<REST_Variable> -VariableFormat Braces
160162 $RestVariable = [Regex ]::new(@'
161- # Matches URL segments and query strings containing variables.
162- # Variables can be enclosed in brackets or curly braces, or preceeded by a $ or :
163163(?> # A variable can be in a URL segment or subdomain
164164 (?<Start>[/\.]) # Match the <Start>ing slash|dot ...
165165 (?<IsOptional>\?)? # ... an optional ? (to indicate optional) ...
166166 (?:
167- \{(?<Variable>\w+)\}| # ... A <Variable> name in {} OR
168- \[(?<Variable>\w+)\]| # A <Variable> name in [] OR
169- `\$(?<Variable>\w+) | # A `$ followed by a <Variable> OR
170- \:(?<Variable>\w+) # A : followed by a <Variable>
167+ \{(?<Variable>\w+)\} # ... A <Variable> name in {} OR
171168 )
172169|
173- (?<IsOptional> # If it's optional it can also be
170+ (?<IsOptional> # If it's optional it can also be
174171 [{\[](?<Start>/) # a bracket or brace, followed by a slash
175172 )
176173 (?<Variable>\w+)[}\]] # then a <Variable> name followed by } or ]
174+
177175| # OR it can be in a query parameter:
178- (?<Start>[? &]) # Match The <Start>ing ? or & ...
179- (?<Query>[\w\-]+) # ... the <Query> parameter name ...
176+ (?<Start>[\?\ &]) # Match The <Start>ing ? or & ...
177+ (?<Query>[\$\ w\-]+) # ... the <Query> parameter name ...
180178 = # ... an equals ...
181179 (?<IsOptional>\?)? # ... an optional ? (to indicate optional) ...
182180 (?:
183- \{(?<Variable>\w+)\}| # ... A <Variable> name in {} OR
184- \[(?<Variable>\w+)\]| # A <Variable> name in [] OR
185- \`$(?<Variable>\w+) | # A $ followed by a <Variable> OR
186- \:(?<Variable>\w+) # A : followed by a <Variable>
181+ \{(?<Variable>\w+)\} # ... A <Variable> name in {} OR
187182 )
188183)
189184'@ , ' IgnoreCase,IgnorePatternWhitespace' )
@@ -377,7 +372,7 @@ $($MyInvocation.MyCommand.Name) @parameter
377372 $streamIn.Dispose ()
378373 $PSCmdlet.WriteError (
379374 [Management.Automation.ErrorRecord ]::new(
380- [Exception ]::new($ strResponse, $ex.Exception.InnerException
375+ [Exception ]::new(" $ ( $ex .Exception.InnerException.Response.StatusCode , $ex .Exception.InnerException.Response.StatusDescription ) $ strResponse " , $ex.Exception.InnerException
381376 ), $ex.Exception.HResult , ' NotSpecified' , $webRequest )
382377 )
383378 return
@@ -402,7 +397,7 @@ $($MyInvocation.MyCommand.Name) @parameter
402397 if ($AsByte ) {
403398 $ms = [IO.MemoryStream ]::new()
404399 $rs.CopyTo ($ms )
405- $ms.ToArray ()
400+ , $ms.ToArray ()
406401 $ms.Dispose ()
407402 return
408403 }
@@ -424,6 +419,9 @@ $($MyInvocation.MyCommand.Name) @parameter
424419 $null = $null
425420 # We call Invoke-RestMethod with the parameters we've passed in.
426421 # It will take care of converting the results from JSON.
422+ if ($response -is [byte []]) {
423+ return $response
424+ }
427425
428426 $apiOutput =
429427 $response |
@@ -434,7 +432,7 @@ $($MyInvocation.MyCommand.Name) @parameter
434432 # A lot of things in the Azure DevOps REST apis come back as a count/value pair
435433 if ($in -eq ' null' ) {
436434 return
437- }
435+ }
438436 if ($ExpandProperty ) {
439437 if ($in .$ExpandProperty ) {
440438 return $in .$ExpandProperty
@@ -456,7 +454,7 @@ $($MyInvocation.MyCommand.Name) @parameter
456454
457455
458456 $in = $_
459- if ($in -is [string ]) { return $in }
457+ if ($in -is [string ]) { return $in }
460458 if ($null -ne $in.Count -and $in.Count -eq 0 ) {
461459 return
462460 }
0 commit comments