How to get console output of Get-AdUser but also pipe it into another command?

1.5k Views Asked by At

I am trying to run a get-aduser command and | it into a set-aduser command, but how do I display the get-aduser command and also pipe it into the set-aduser?

Thanks

1

There are 1 best solutions below

5
Jeff Zeitlin On

Pipe the output of the Get-ADUser command to a scriptblock that displays it and also executes the Set-ADUser command:

Get-ADUser ... | ForEach-Object { $_ ; Set-ADUser $_ ... }

The first $_ displays the object returned by Get-ADUser; the second passes it to the Set-ADUser command.