Powershell 4 : Pipeline - 2020
PowerShell connects commands to each other using a pipeline. The pipeline provides a way for one command to pass, or pipe, its output to another command, allowing that second command to have something to work with. Though the PowerShell's use of a pipeline appears to be the same as how Unix and Linux shells work, PowerShell's pipeline has more.
We're going to pipe our processes to Export-CSV:
PS C:\Users\KHong> Get-Process | Export-CSV procs.csv
That second cmdlet has a mandatory positional parameter that we've used to specify the output filename. Because Export-CSV is a native PowerShell cmdlet, it knows how to translate the table normally generated by Get-Process into a normal CSV file.
Let's open the file to see the results:
#TYPE System.Diagnostics.Process "__NounName","Name","Handles","VM","WS","PM","NPM","Path","Company","CPU","FileVersion","ProductVersion","Description","Product","BasePriority","ExitCode","HasExited","ExitTime","Handle","HandleCount","Id","MachineName","MainWindowHandle","MainWindowTitle","MainModule","MaxWorkingSet","MinWorkingSet","Modules","NonpagedSystemMemorySize","NonpagedSystemMemorySize64","PagedMemorySize","PagedMemorySize64","PagedSystemMemorySize","PagedSystemMemorySize64","PeakPagedMemorySize","PeakPagedMemorySize64","PeakWorkingSet","PeakWorkingSet64","PeakVirtualMemorySize","PeakVirtualMemorySize64","PriorityBoostEnabled","PriorityClass","PrivateMemorySize","PrivateMemorySize64","PrivilegedProcessorTime","ProcessName","ProcessorAffinity","Responding","SessionId","StartInfo","StartTime","SynchronizingObject","Threads","TotalProcessorTime","UserProcessorTime","VirtualMemorySize","VirtualMemorySize64","EnableRaisingEvents","StandardInput","StandardOutput","StandardError","WorkingSet","WorkingSet64","Site","Container" "Process","AcroRd32","195","125140992","63041536","50937856","6960","C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe","Adobe Systems Incorporated","107.953125","9.5.0.270","9.5.0.270","Adobe Reader 9.5","Adobe Reader","8",,"False",,"548","195","2236",".","132806","Learn Windows PowerShell 3 in a Month of Lunches, 2nd Edition.pdf - Adobe Reader","System.Diagnostics.ProcessModule (AcroRd32.exe)","1413120","204800","System.Diagnostics.ProcessModuleCollection","6960","6960","50937856","50937856","151348","151348","57671680","57671680","69554176","69554176","131633152","131633152","True","Normal","50937856","50937856","00:00:39.7812500","AcroRd32","3","True","0","System.Diagnostics.ProcessStartInfo","9/17/2014 12:57:33 PM",,"System.Diagnostics.ProcessThreadCollection","00:01:47.9687500","00:01:08.1875000","125140992","125140992","False",,,,"63041536","63041536",, "Process","AdobeARM","203","55947264","8253440","4513792","6456","C:\Program Files\Common Files\Adobe\ARM\1.0\AdobeARM.exe","Adobe Systems Incorporated","0.3125","1.7.4.0","1.7.4.0","Adobe Reader and Acrobat Manager","Adobe Reader and Acrobat Manager","8",,"False",,"1000","203","1492",".","0","","System.Diagnostics.ProcessModule (AdobeARM.exe)","1413120","204800","System.Diagnostics.ProcessModuleCollection","6456","6456","4513792","4513792","92228","92228","4751360","4751360","8314880","8314880","63504384","63504384","True","Normal","4513792","4513792","00:00:00.1562500","AdobeARM","3","True","0","System.Diagnostics.ProcessStartInfo","9/17/2014 10:41:14 AM",,"System.Diagnostics.ProcessThreadCollection","00:00:00.3125000","00:00:00.1562500","55947264","55947264","False",,,,"8253440","8253440",, "Process","alg","114","33857536","3833856","1228800","6104","C:\WINDOWS\System32\alg.exe","Microsoft Corporation","0.03125","5.1.2600.5512 (xpsp.080413-0852)","5.1.2600.5512","Application Layer Gateway Service","Microsoft? Windows? Operating System","8",,"False",,"1004","114","4356",".","0","","System.Diagnostics.ProcessModule (alg.exe)","1413120","204800","System.Diagnostics.ProcessModuleCollection","6104","6104","1228800","1228800","65380","65380","1265664","1265664","3858432","3858432","34811904","34811904","True","Normal","1228800","1228800","00:00:00.0156250","alg","3","True","0","System.Diagnostics.ProcessStartInfo","9/17/2014 10:44:38 AM",,"System.Diagnostics.ProcessThreadCollection","00:00:00.0312500","00:00:00.0156250","33857536","33857536","False",,,,"3833856","3833856",, "Process","ApacheMonitor","29","26963968","2703360","663552","1920","C:\Apache2\bin\ApacheMonitor.exe","Apache Software Foundation","14.5","2.2.25","2.2.25","Apache HTTP Server Monitor","Apache HTTP Server","8",,"False",,"1184","29","1948",".","0","","System.Diagnostics.ProcessModule (ApacheMonitor.exe)","1413120","204800","System.Diagnostics.ProcessModuleCollection","1920","1920","663552","663552","53100","53100","667648","667648","2703360","2703360","34865152","34865152","True","Normal","663552","663552","00:00:13.0156250","ApacheMonitor","3","True","0","System.Diagnostics.ProcessStartInfo","9/17/2014 10:41:17 AM",,"System.Diagnostics.ProcessThreadCollection","00:00:14.5000000","00:00:01.4843750","26963968","26963968","False",,,,"2703360","2703360",, "Process","CCC","597","199929856","6434816","49549312","18300","C:\Program Files\ATI Technologies\ATI.ACE\Core-Static\ccc.exe","ATI Technologies Inc.","2.4375","2.0.0.0","2.0.0.0","Catalyst Control Center: Host application","Catalyst Control Center","8",,"False",,"1048","597","2792",".","0","","System.Diagnostics.ProcessModule (ccc.exe)","1413120","204800","System.Diagnostics.ProcessModuleCollection","18300","18300","49549312","49549312","268948","268948","58781696","58781696","40562688","40562688","209600512","209600512","True","Normal","49549312","49549312","00:00:00.6406250","CCC","3","True","0","System.Diagnostics.ProcessStartInfo","9/17/2014 10:41:30 AM",,"System.Diagnostics.ProcessThreadCollection","00:00:02.5000000","00:00:01.8593750","199929856","199929856","False",,,,"6434816","6434816",, "Process","chrome","112","177025024","39563264","46706688","5960","C:\Program Files\Google\Chrome\Application\chrome.exe","Google Inc.","3.75","37.0.2062.120","37.0.2062.120","Google Chrome","Google Chrome","8",,"False",,"880","112","1580",".","0","","System.Diagnostics.ProcessModule (chrome.exe)","1413120","204800","System.Diagnostics.ProcessModuleCollection","5960","5960","46706688","46706688","196812","196812","50515968","50515968","40120320","40120320","180170752","180170752","True","Normal","46706688","46706688","00:00:03.0312500","chrome","3","True","0","System.Diagnostics.ProcessStartInfo","9/17/2014 12:03:15 PM",,"System.Diagnostics.ProcessThreadCollection","00:00:03.7500000","00:00:00.7187500","177025024","177025024","False",,,,"39563264","39563264",, "Process","chrome","113","186130432","47271936","51945472","6000","C:\Program Files\Google\Chrome\Application\chrome.exe","Google Inc.","4.28125","37.0.2062.120","37.0.2062.120","Google Chrome","Google Chrome","8",,"False",,"884","113","4480",".","0","","System.Diagnostics.ProcessModule (chrome.exe)","1413120","204800","System.Diagnostics.ProcessModuleCollection","6000","6000","51945472","51945472","196812","196812","64577536","64577536","56479744","56479744","194519040","194519040","True","Normal","51945472","51945472","00:00:03.0937500","chrome","3","True","0","System.Diagnostics.ProcessStartInfo","9/17/2014 12:03:14 PM",,"System.Diagnostics.ProcessThreadCollection","00:00:04.2812500","00:00:01.1875000","186130432","186130432","False",,,,"47271936","47271936",, "Process","chrome","199","426373120","217174016","199540736","21240","C:\Program Files\Google\Chrome\Application\chrome.exe","Google Inc.","222.890625","37.0.2062.120","37.0.2062.120","Google Chrome","Google Chrome","8",,"False",,"912","199","4700",".","0","","System.Diagnostics.ProcessModule (chrome.exe)","1413120","204800","System.Diagnostics.ProcessModuleCollection","21240","21240","199540736","199540736","235596","235596","233803776","233803776","262492160","262492160","445509632","445509632","True","Normal","199540736","199540736","00:00:34.0625000","chrome","3","True","0","System.Diagnostics.ProcessStartInfo","9/17/2014 12:03:26 PM",,"System.Diagnostics.ProcessThreadCollection","00:03:42.8906250","00:03:08.8281250","426373120","426373120","False",,,,"217174016","217174016",, "Process","chrome","115","197410816","53350400","57454592","6960","C:\Program Files\Google\Chrome\Application\chrome.exe","Google Inc.","2.875","37.0.2062.120","37.0.2062.120","Google Chrome","Google Chrome","8",,"False",,"872","115","4716",".","0","","System.Diagnostics.ProcessModule (chrome.exe)","1413120","204800","System.Diagnostics.ProcessModuleCollection","6960","6960","57454592","57454592","197684","197684","68853760","68853760","72798208","72798208","212746240","212746240","True","Normal","57454592","57454592","00:00:01.6718750","chrome","3","True","0","System.Diagnostics.ProcessStartInfo","9/17/2014 6:57:23 PM",,"System.Diagnostics.ProcessThreadCollection","00:00:02.8750000","00:00:01.2031250","197410816","197410816","False",,,,"53350400","53350400",, "Process","chrome","117","196030464","65544192","72130560","6720","C:\Program Files\Google\Chrome\Application\chrome.exe","Google Inc.","54.53125","37.0.2062.120","37.0.2062.120","Google Chrome","Google Chrome","8",,"False",,"876","117","4840",".","0","","System.Diagnostics.ProcessModule (chrome.exe)","1413120","204800","System.Diagnostics.ProcessModuleCollection","6720","6720","72130560","72130560","196812","196812","118067200","118067200","103403520","103403520","227381248","227381248","True","Normal","72130560","72130560","00:00:05.3750000","chrome","3","True","0","System.Diagnostics.ProcessStartInfo","9/17/2014 12:03:10 PM",,"System.Diagnostics.ProcessThreadCollection","00:00:54.5312500","00:00:49.1562500","196030464","196030464","False",,,,"65544192","65544192",, "Process","chrome","1036","298016768","147562496","104210432","32336","C:\Program Files\Google\Chrome\Application\chrome.exe","Google Inc.","295.046875","37.0.2062.120","37.0.2062.120","Google Chrome","Google Chrome","8",,"False",,"888","1036","5068",".","131426","cPanel X - File Manager - Google Chrome","System.Diagnostics.ProcessModule (chrome.exe)","1413120","204800","System.Diagnostics.ProcessModuleCollection","32336","32336","104210432","104210432","339780","339780","122400768","122400768","160870400","160870400","321863680","321863680","True","Normal","104210432","104210432","00:01:33.3593750","chrome","3","True","0","System.Diagnostics.ProcessStartInfo","9/17/2014 12:02:57 PM",,"System.Diagnostics.ProcessThreadCollection","00:04:55.0468750","00:03:21.6875000","298016768","298016768","False",,,,"147562496","147562496",, "Process","chrome","190","352305152","166928384","148336640","12720","C:\Program Files\Google\Chrome\Application\chrome.exe","Google Inc.","180.890625","37.0.2062.120","37.0.2062.120","Google Chrome","Google Chrome","8",,"False",,"440","190","5076",".","0","","System.Diagnostics.ProcessModule (chrome.exe)","1413120","204800","System.Diagnostics.ProcessModuleCollection","12720","12720","148336640","148336640","234540","234540","162209792","162209792","193515520","193515520","381665280","381665280","True","Normal","148336640","148336640","00:00:36.5625000","chrome","3","True","0","System.Diagnostics.ProcessStartInfo","9/17/2014 12:03:15 PM",,"System.Diagnostics.ProcessThreadCollection","00:03:00.8906250","00:02:24.3281250","352305152","352305152","False",,,,"166928384","166928384",, "Process","chrome","115","189890560","54104064","58855424","6920","C:\Program Files\Google\Chrome\Application\chrome.exe","Google Inc.","2.421875","37.0.2062.120","37.0.2062.120","Google Chrome","Google Chrome","8",,"False",,"580","115","5584",".","0","","System.Diagnostics.ProcessModule (chrome.exe)","1413120","204800","System.Diagnostics.ProcessModuleCollection","6920","6920","58855424","58855424","196820","196820","72114176","72114176","70463488","70463488","203821056","203821056","True","Normal","58855424","58855424","00:00:01.3750000","chrome","3","True","0","System.Diagnostics.ProcessStartInfo","9/17/2014 6:54:23 PM",,"System.Diagnostics.ProcessThreadCollection","00:00:02.4218750","00:00:01.0468750","189890560","189890560","False",,,,"54104064","54104064",, "Process","chrome","143","325533696","166535168","161280000","13720","C:\Program Files\Google\Chrome\Application\chrome.exe","Google Inc.","406.171875","37.0.2062.120","37.0.2062.120","Google Chrome","Google Chrome","8",,"False",,"536","143","5836",".","0","","System.Diagnostics.ProcessModule (chrome.exe)","1413120","204800","System.Diagnostics.ProcessModuleCollection","13720","13720","161280000","161280000","207196","207196","205332480","205332480","226684928","226684928","371908608","371908608","True","Normal","161280000","161280000","00:00:30","chrome","3","True","0","System.Diagnostics.ProcessStartInfo","9/17/2014 12:03:15 PM",,"System.Diagnostics.ProcessThreadCollection","00:06:46.1875000","00:06:16.1875000","325533696","325533696","False",,,,"166535168","166535168",,
The first line of the file will be a comment, preceded by a # character, and it identifies the kind of information that's included in the file. It's System .Diagnostics.Process, which is the under-the-hood name that Windows uses to identify the information related to a running process.
The second line will be column headings, and the subsequent lines will list the information for the various processes running on the computer.
We can pipe the output of almost any Get- cmdlet to Export-CSV and get excellent results.
Once the information is saved into a CSV file, which can be imported via:
Import-CSV procs.csv
Powershell 4 Tutorial
- Powersehll : Introduction
- Powersehll : Help System
- Powersehll : Running commands
- Powersehll : Providers
- Powersehll : Pipeline
- Powersehll : Objects
- Powershell : Remote Control
- Windows Management Instrumentation (WMI)
- How to Enable Multiple RDP Sessions in Windows 2012 Server
- How to install and configure FTP server on IIS 8 in Windows 2012 Server
- How to Run Exe as a Service on Windows 2012 Server
- SQL Inner, Left, Right, and Outer Joins
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization