Ответы пользователя по тегу PowerShell
  • Как организовать цикл из динамически формирующихся элементов?

    @Dartar
    Попробуйте вот так:
    function ClearOuList($count)
    {
      #$comboboxOuNext1.DataSource = $null
      switch ($count) {
        1 {
             Get-Variable -Name "comboboxOuNext[1-9]" | %{$_.Value.visible=$false
             Get-Variable -Name "comboboxOuNext10" | %{$_.Value.visible=$false
            }
        2 {
             Get-Variable -Name "comboboxOuNext[2-9]" | %{$_.Value.visible=$false
             Get-Variable -Name "comboboxOuNext10" | %{$_.Value.visible=$false
            }
        3 {
             Get-Variable -Name "comboboxOuNext[3-9]" | %{$_.Value.visible=$false
             Get-Variable -Name "comboboxOuNext10" | %{$_.Value.visible=$false
            }
        4 {
             Get-Variable -Name "comboboxOuNext[4-9]" | %{$_.Value.visible=$false
             Get-Variable -Name "comboboxOuNext10" | %{$_.Value.visible=$false
            }
        5{
             Get-Variable -Name "comboboxOuNext[5-9]" | %{$_.Value.visible=$false
             Get-Variable -Name "comboboxOuNext10" | %{$_.Value.visible=$false
            }
        6{
             Get-Variable -Name "comboboxOuNext[6-9]" | %{$_.Value.visible=$false
             Get-Variable -Name "comboboxOuNext10" | %{$_.Value.visible=$false
            }
        7 {
             Get-Variable -Name "comboboxOuNext[7-9]" | %{$_.Value.visible=$false
             Get-Variable -Name "comboboxOuNext10" | %{$_.Value.visible=$false
            }
        8 {
             Get-Variable -Name "comboboxOuNext[89]" | %{$_.Value.visible=$false
             Get-Variable -Name "comboboxOuNext10" | %{$_.Value.visible=$false
            }
        9 {
             Get-Variable -Name "comboboxOuNext9" | %{$_.Value.visible=$false
             Get-Variable -Name "comboboxOuNext10" | %{$_.Value.visible=$false
            }
        10 {
              Get-Variable -Name "comboboxOuNext10" | %{$_.Value.visible=$false
            }
      }
    }
    }

    Так же можете рассмотреть квантификаторы:
    Get-Variable * | ? {$_.name -match "comboboxOuNext[0-9]{1,2}"}
    Ответ написан