"move" a value from one array to an other

This topic contains 1 reply, has 2 voices, and was last updated by  Sam Boutros 4 months ago.

  • Author
  • #89906



    I'm probably on the wrong track.
    I have an array (values to process) over which I iterate in a foreach loop. If the current value of that array matches several criteria I want to move this value to an other array (processed values).
    Is it possible to move a value from one array to an other? I help myself with copying the value to the new array and remove it afterwards in the old one. But is there a better solution?

  • #89923

    Sam Boutros
    $Naughty = @(
    $Nice = $Naughty | foreach {
        if ( # list of conditions here
            $PSItem -match 'ixe' -or
            $PSItem -match 'sh'
        ) { # matches copied into $Nice
    $Naughty = $Naughty | where  { $PSItem -notin $Nice } # $Nice items removed from $Naughty
    "Naughty: $($Naughty -join ', ')"
    "Nice:    $($Nice -join ', ')"

You must be logged in to reply to this topic.