PowerShell 3.0 -PassThru
PowerShell' s -PassThru parameter has found signficantly more uses in PowerShell 3.0.
In a nutshell -PassThru shows you the results of a command that would otherwise be silent.
Let us take this example where we are using PowerShell 3.0 to display the processes.
Get-Process Out-GridView -PassThru
The benefit of the -PassThru parameter comes when you select rows with the mouse, and then click OK. The result is that PowerShell refreshes the output.
Take the screenshot to the right where I have selected just 5 rows, dlhost, LogonUI, lsass, MsMpEng and SearchIndex. When I pressed ' OK' , the result was a display with just those 5 rows.
Result of -PassThru and pressing ' OK'
Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft's operating systems. Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your PowerShell scripts.
Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory, or Exchange Server. Give this WMI monitor a try - it's free.
Other Examples of PowerShell PassThru
To see the full list of PowerShell PassThru cmdlets try this:
Note 1: Parameters.Keys is the crucial property.
Cmdlets for further study of PowerShell -PassThru
Simple Example of -PassThru
Here is an example where you want to rename a Windows computer.
# PowerShell 3.0 Rename-Computer with -PassThru
Note 2: To get this working you need to change $Old to the value of your machine; don't worry the -WhatIf will stop this actually renaming this computer.
This is how to get started from the Metro user interface in Windows 8.
Summary of PowerShell 3.0 PassThru
The best way to learn about PowerShell's -PassThru parameter is by experimenting with examples such as Stop-Process or Out-GridView.
If you like this page then please share it with your friends
See more Microsoft PowerShell output tutorials:
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.