Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Listing processes


In this recipe, we will list processes in the system.

How to do it...

Let's list processes using PowerShell:

  1. Open PowerShell ISE as an administrator.

  2. Add the following script and run it to list processes on the screen:

    #list all processes to screen
    Get-Process
    
    #list 10 most recently started processes
    Get-Process | 
    Sort-Object -Property StartTime -Descending | 
    Select-Object Name, StartTime, Path, Responding -First 10
  3. Add the following script and run it to list and save the processes to a text file:

    #save processes to a text file
    $txtFile = "C:\Temp\processes.txt"
    
    Get-Process | 
    Out-File -FilePath $txtFile -Force
    
    #display text file in notepad
    notepad $txtFile
  4. Add the following script and run it to save the processes to a CSV file:

    #save processes to a csv file
    $csvFile = "C:\Temp\processes.csv"
    
    Get-Process | 
    Export-Csv -Path $csvFile -Force -NoTypeInformation
    
    #display first five lines in file
    Get-Content $csvFile -totalCount 5
  5. Add the following script and run it to save the...