#requires -version 2.0 <# ----------------------------------------------------------------------------- Script: Out-Tee.ps1 Version: 0.9 Author: Jeffery Hicks http://jdhitsolutions.com/blog http://twitter.com/JeffHicks http://www.ScriptingGeek.com Date: 1/13/2012 Keywords: Comments: "Those who forget to script are doomed to repeat their work." **************************************************************** * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED * * THOROUGHLY IN A LAB ENVIRONMENT. USE AT YOUR OWN RISK. IF * * YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, * * DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING. * **************************************************************** ----------------------------------------------------------------------------- #> <# This simple function takes a PowerShell expression and writes the results to the console using Write-Host and also to the clipboard. The default output will use the current console foreground color. But you can specify any other color that you would use with Write-Host. #> Function Out-Tee { [cmdletbinding()] Param ( [Parameter(Position=0,Mandatory=$True,ValueFromPipeline=$True)] [object[]]$InputObject, [alias("foregroundcolor","fg")] [string]$TextColor=$host.ui.rawui.ForegroundColor ) Begin { #define an empty array to hold piped in objects $a=@() } Process { #add each piped in object to the array $a+=$inputobject } End { #write the array to the pipeline as a string then pass to Write-Host $a | out-string | write-host -fore $textColor #write the array again to Clip.exe $a | clip } } #end function #define an optional alias New-Alias -Name ot -Value Out-Tee