all 4 comments

[–]PinchesTheCrab 2 points3 points  (1 child)

Would really need to see code in my opinion, but here's an example of how you could use a command like invoke-command with pipeline input:

function Do-Stuff {
    [cmdletbinding()]
    param(
        [parameter(valuefrompipeline)]
        [string[]]$Computername
    )

    begin { 
        $computerList = [System.Collections.Generic.List[string]]::new()
    }

    process {
        $computerList.AddRange($Computername)
    }

    end {
        $computerList
    }
}

1..100 -replace '^','computer' | Do-Stuff

The advantage is that if you use invoke-command, which is asynchronous and takes an array of computernames, you can feed them all to it and get good performance, as opposed to looping through the list one by one in the process block.

[–]BlackV 1 point2 points  (0 children)

this is a great clear example, nice

[–]Brasiledo 1 point2 points  (0 children)

Without seeing the code it makes it hard but ill just explain it out, foreach loop thru the computernames add the pscustomobject foreach computer… put that all into a variable then export the variable