# ============================================================================================== # # Microsoft PowerShell Source File -- Created with SAPIEN Technologies PrimalScript 2009 # # NAME: Out-Notepad.ps1 # # Jeffery Hicks # http://jdhitsolutions.com/blog # follow on Twitter: http://twitter.com/JeffHicks # "Those who forget to script are doomed to repeat their work." # DATE : 10/5/2009 # # COMMENT: Pipe PowerShell output to a temp file and open the file in Notepad # **************************************************************** # * 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. * # **************************************************************** # # ============================================================================================== Function Out-Notepad { #this function is designed to take pipelined input #example: get-process | out-notepad Begin { #create the FileSystem COM object $fso=new-object -com scripting.filesystemobject $filename=$fso.GetTempName() $tempfile=Join-Path $env:temp $filename #initialize a placeholder array $data=@() } #end Begin scriptblock Process { #add pipelined data to $data $data+=$_ } #end Process scriptblock End { #write data to the temp file $data | Out-File $tempfile #open the tempfile in Notepad Notepad $tempfile #sleep for 5 seconds to give Notepad a chance to open the fi sleep 5 #delete the temp file if it still exists after closing Notepad if (Test-Path $tempfile) {del $tempfile} } #end End scriptblock } #end Function Set-Alias on Out-Notepad # ps | Out-Notepad