0

Why wont the $branch and $FileDirectory parameter work in Process-DropDownlist function? It is not replaced when I try to look at the string when I print it to console.

It will just come out as $fileDirectory and $branch. Please advice........

function Process-DropDownList() {
[CmdletBinding()]
Param(
    [Parameter(Mandatory = $True, ValueFromPipeline = $True)]
    [string] $Branch,
    [Parameter(Mandatory = $True)]
    [string] $FileDirectory,
    [Parameter(Mandatory = $False)]
    [string] $Uri
)

Begin {
    $outFileDirectories = @(
       @{ Pattern = 'fibp*'; Directory = '$FileDirectory\1\$Branch\swagger.json' },
          @{ Pattern = 'fibf*'; Directory = '$FileDirectory\2\$Branch\swagger.json' },
          @{ Pattern = 'fifi*'; Directory = '$FileDirectory\3\$Branch\swagger.json' },
          @{ Pattern = 'fibh*'; Directory = '$FileDirectory\4\$Branch\swagger.json' },
          @{ Pattern = 'fiuc*'; Directory = '$FileDirectory\5\$Branch\swagger.json' },
          @{ Pattern = 'fibu*'; Directory = '$FileDirectory\6\$Branch\swagger.json' },
          @{ Pattern = 'fibc*'; Directory = '$FileDirectory\7\$Branch\swagger.json' }
    )
 
 
  $outDropLists = @(
       @{ Pattern = 'fibp*'; DropName = 'Someting1 - $Branch' },
          @{ Pattern = 'fibf*'; DropName = 'Something2 - $Branch' },
          @{ Pattern = 'fifi*'; DropName = 'Someting3 - $Branch' },
          @{ Pattern = 'fibh*'; DropName = 'Someting4 - $Branch' },
          @{ Pattern = 'fiuc*'; DropName = 'Someting5 - $Branch' },
          @{ Pattern = 'fibu*'; DropName = 'Something6 - $Branch' },
          @{ Pattern = 'fibc*'; DropName = 'Something7 - $Branch' }
    )
 
}      

Process {
    $outFileDirectory = $outFileDirectories |
        Where-Object -FilterScript { $Branch -Like $_.Pattern} |
        Select-Object -First 1 |
        ForEach-Object -Process { $_.Directory }

   
 
  $outDropList = $outDropLists |
        Where-Object -FilterScript { $Branch -Like $_.Pattern} |
        Select-Object -First 1 |
        ForEach-Object -Process { $_.DropName }

        $outFileDirectory
        $outDropList


}

}


$data = Git ls-remote --refs ssh://git@stometing:7669/containers.git
$reg = '(fi[-\w]+)\s*$'
$branches = $data | Select-String $reg -AllMatches | ForEach-Object { $_.Matches.Value }
$branches | Process-DropDownList -FileDirectory http://something/swagger
mklement0
  • 382,024
  • 64
  • 607
  • 775
Mikael
  • 173
  • 2
  • 12
  • 2
    Strings surrounded by single quotes are treated at literal strings and no substitution is made for embedded variables / expressions. Use double-quotes instead for “string interpolation”. – mclayton Jul 07 '22 at 11:32
  • In short: In PowerShell, only `"..."` strings (double-quoted aka _expandable strings_) perform string interpolation (expansion of variable values), not `'...'` strings (single-quoted aka _verbatim strings_). If the string value itself contains `"` chars., escape them as `\`"` or `""`, or use a double-quoted _here-string_. See the conceptual [about_Quoting_Rules](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Quoting_Rules) help topic. – mklement0 Jul 07 '22 at 12:31

0 Answers0