PowerShell 3 -PassThru Parameter 
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.
- Example 1: Out-GridView -PassThru
- Launching PowerShell 3.0 in Windows 8
- What Else Is New In PowerShell 3.0?
♦
Example 1: Out-GridView -PassThru
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’
Guy Recommends: Free WMI Monitor for PowerShell
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.
Download your free copy of WMI Monitor
Other Examples of PowerShell PassThru
To see the full list of PowerShell PassThru cmdlets try this:
Clear-host
Get-Command | Where {$_.parameters.keys -Contains "PassThru" `
-And $_.CommandType -Contains "Cmdlet"} |
Ft Name, CommandType -AutoSize
Note 1: Parameters.Keys is the crucial property.
Cmdlets for further study of PowerShell -PassThru
- Compare-Object
- Stop-Process
- Add-Computer See another example 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
$Old ="OriginalName"
$New ="GuyServer"
Rename-Computer -NewName $New -ComputerName $Old `
-PassThru -WhatIf
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.
Launching PowerShell v 3.0
This is how to get started from the Metro user interface in Windows 8.
- From anywhere in the Metro UI, press the ‘p’ key. You should see a list of the programs and Apps beginning with ‘p’.
- At this point you could ‘Pin’ the ‘Windows PowerShell ISE’ by right-clicking and selecting ‘Pin’ at the bottom right of the screen.
- Incidentally, I prefer the GUI (ISE) version to the plain command line Windows PowerShell.
- I like to drag the PowerShell ISE tile to the left of my screen because it’s one of the most important Windows 8 Tiles that use.
See more of what’s new in PowerShell v 3.0 »
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:
• PShell Home • Out-GridView • PowerShell Splatting • Read-Host • Write-Host • ConvertTo-Html
• Export-CSV • Import-CSV • PowerShell Write-Progress • PowerShell Measure-Command
• PowerShell 3 -PassThru • PowerShell 3.0 Redirection • ConvertFrom-Csv • Free CSV Import Tool
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.