locked
Stuck in a loop RRS feed

  • General discussion

  • Once again I have to turn to the experts. Thanks guys in advance. I'm trying to evaluate all elements in an array as true so it can add those elements to an AD-Object. My script is getting stuck in a loop even when all elements evaluate as true.

    do {
    $sys_input = @()

    $sys_input = Read-Host "Input the syssec server group name.  You may enter multiple names comma-separated with no space."

    $sys_input = $sys_input.Split(',')

    if ($sys_input -notmatch "syssec") {Write-Host "Follow security group naming convention starting the object name with syssec"}

    }

    until ($sys_input -eq $true)

    For testing the loop, the first set of values I entered was syssec-test101,test102.  The logic identifies test102 as the problem and loops as it should.  The second of set of values I entered was syssec-test103,syssec-test104 but it looks back around asking for input again.  Help.  What am I doing wrong?

    Thanks,

    Mike B.


    Mike B.

    Tuesday, May 24, 2016 9:11 PM

All replies

  • You can't match that way/

    do{
    	$sys_input = Read-Host "Input the syssec server group name.  You may enter multiple names comma-separated with no space."
    until -not ($sys_input.Split(',') | %{$_ -notmatch 'sysprep'}|?{$_}))
    


    \_(ツ)_/

    Tuesday, May 24, 2016 9:35 PM
  • I never thought of it that way.  Thanks so much for helping a noob out.  I'll try that tomorrow.

    Mike B.

    Wednesday, May 25, 2016 10:04 PM
  • I had to fix some of the syntax as indicated by the Powershell IDE.  So here's my adjustments below.

    do{
     $sys_input = Read-Host "Input the syssec server group name.  You may enter multiple names comma-separated with no space."
    }
    until ( -not ($sys_input.Split(',') | %{$_ -notmatch 'syssec'}|?{$_}))

    I'm still getting an endless loop though.

    For anyone looking at this, I'm trying to evaluate all the values of the array $sys_input to true before moving on with the rest of the script. 

    Thanks my fellow Powershell scripters.


    Mike B.

    Tuesday, May 31, 2016 9:25 PM
  • Why prompt for input instead of passing a parameter?

    -- Bill Stewart [Bill_Stewart]

    Tuesday, May 31, 2016 9:43 PM