Q. Is there a way to pipe an object to multiple commands when using PowerShell?

John Savill

August 30, 2009

1 Min Read
ITPro Today logo

A. Normally, when you use PowerShell you perform actions by piping the objects from one PowerShell command to another. For example:

get-aduser bruce | Disable-ADAccount

This command gets the object for user bruce and disables it using the Disable-ADAccount cmdlet. But what if you want to run another command on the bruce account as well? Say you want to pass the bruce object through the Disable-ADAccount cmdlet to the next cmdlet. Fortunately, this is easy. You just add -PassThru to the end of the cmdlet. For example, the command below would disable the AD account then update its description.

get-aduser bruce | Disable-ADAccount -PassThru | Set-ADUser -Description ("Account Disabled on $(get-date)")

Related Reading:

  • Q. How can I get a list of all the Windows PowerShell modules that are available to be imported?

  • PowerShell Script Lists Group Hierarchies in Any LDAP Directory

  • Q. How can I see all the cmdlets provided in a Windows PowerShell module?

  • Q. How can I launch a Windows PowerShell instance to run a command from a cmd.exe prompt?



Check out hundreds more useful Q&As like this in John Savill's FAQ for Windows. Also, watch instructional videos made by John at ITTV.net.

About the Author(s)

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like