Category Archives: Process

Wait-Process

NAME
    Wait-Process

SYNOPSIS
    Waits for the processes to be stopped before accepting more input.

SYNTAX
    Wait-Process [-Id] <Int32[]> [[-Timeout] <int>] [<CommonParameters>]

    Wait-Process -InputObject <Process[]> [[-Timeout] <int>] [<CommonParameters>]

    Wait-Process [-Name] <string[]> [[-Timeout] <int>] [<CommonParameters>]

DESCRIPTION
    The Wait-Process cmdlet waits for one or more running processes to be stopped before accepting input. In the Windows PowerShell console, this cmdlet suppresses the command prompt until the processes are stopped. You can specify a process by process name or process ID (PID), or pipe a process object to Wait-Process.

    Wait-Process works only on processes running on the local computer.

PARAMETERS
    -Id <Int32[]>
        Specifies the process IDs of the processes. To specify multiple IDs, use commas to separate the IDs. To find the PID of a process, type “Get-Process“. The parameter name (“Id”) is optional.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -InputObject <Process[]>
        Specifies the processes by submitting process objects. Enter a Variable that contains the process objects, or type a command or expression that gets the process objects, such as a Get-Process command.

        Required?                    true
        Position?                    named
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? false

    -Name <string[]>
        Specifies the process names of the processes. To specify multiple names, use commas to separate the names.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Timeout <int>
        Determines the maximum time, in seconds, that Wait-Process waits for the specified processes to stop. When this interval expires, the command displays a non-terminating error that lists the processes that are still running, and ends the wait.

        Required?                    false
        Position?                    2
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Diagnostics.Process
        You can pipe a process object to Wait-Process.

OUTPUTS
    None
        This cmdlet does not generate any output.

NOTES

        This cmdlet uses the WaitForExit method of the System.Diagnostics.Process class. For more information about this method, see the Microsoft .NET Framework SDK.

    ————————– EXAMPLE 1 ————————–

    C:\PS>$nid = (Get-Process notepad).id

    C:\PS> Stop-Process -id $nid

    C:\PS> Wait-Process -id $nid

    Description
    ———–
    These commands stop the Notepad process and then wait for the process to be stopped before proceeding with the next command.

    The first command uses the Get-Process cmdlet to get the ID of the Notepad process. It saves it in the $nid Variable.

    The second command uses the Stop-Process cmdlet to stop the process with the ID saved in $nid.

    The third command uses the Wait-Process cmdlet to wait until the Notepad process is stopped. It uses the ID parameter of Wait-Process to identify the process.

    ————————– EXAMPLE 2 ————————–

    C:\PS>$p = Get-Process notepad

    C:\PS> Wait-Process -id $p.id

    C:\PS> Wait-Process -Name notepad

    C:\PS> Wait-Process -inputobject $p

    Description
    ———–
    These commands show three different methods of specifying a process to the Wait-Process cmdlet. The first command gets the Notepad process and saves it in the $p Variable.

    The second command uses the ID parameter, the third command uses the Name parameter, and the fourth command uses the InputObject parameter.

    These commands have the same results and can be used interchangeably.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Wait-Process -Name outlook, winword -Timeout 30

    Description
    ———–
    This command waits 30 seconds for the Outlook and Winword processes to stop. If both processes are not stopped, the cmdlet displays a non-terminating error and the command prompt.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135277
    Get-Process
    Start-Process
    Stop-Process
    Wait-Process
    Debug-Process

Start-Process

NAME
    Start-Process

SYNOPSIS
    Starts one or more processes on the local computer.

SYNTAX
    Start-Process [-FilePath] <string> [[-ArgumentList] <string[]>] [-Credential <PSCredential>] [-LoadUserProfile] [-NoNewWindow] [-PassThru] [-RedirectStandardError <string>] [-RedirectStandardInput <string>] [-RedirectStandardOutput <string>] [-UseNewEnvironment] [-Wait] [-WorkingDirectory <string>] [<CommonParameters>]

    Start-Process [-FilePath] <string> [[-ArgumentList] <string[]>] [-PassThru] [-Verb <string>] [-Wait] [-WindowStyle {Normal | Hidden | Minimized | Maximized}] [-WorkingDirectory <string>] [<CommonParameters>]

DESCRIPTION
    Starts one or more processes on the local computer. To specify the program that runs in the process, enter an executable file or script file, or a file that can be opened by using a program on the computer. If you specify a non-executable file, Start-Process starts the program that is associated with the file, much like the Invoke-Item cmdlet.

    You can use the parameters of Start-Process to specify options, such as loading a user profile, starting the process in a new window, or using alternate credentials.

PARAMETERS
    -ArgumentList <string[]>
        Specifies parameters or parameter values to use when starting the process. The parameter name (“Arguments”) is optional.

        Required?                    false
        Position?                    2
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Credential <PSCredential>
        Specifies a user account that has permission to perform this action. Type a user-name, such as “User01” or “Domain01\User01”, or enter a PSCredential object, such as one from the Get-Credential cmdlet. By default, the cmdlet uses the credentials of the current user.

        Required?                    false
        Position?                    named
        Default value                Current user.
        Accept pipeline input?     false
        Accept wildcard characters? false

    -FilePath <string>
        Specifies the path (optional) and file name of the program that runs in the process. Enter the name of an executable file or of a document, such as a .txt or .doc file, that is associated with a program on the computer. This parameter is required.

        If you specify only a file name, use the WorkingDirectory parameter to specify the path.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -LoadUserProfile [<SwitchParameter>]
        Loads the Windows user profile stored in the HKEY_USERS Registry key for the current user. The default value is FALSE.

        This parameter does not affect the Windows PowerShell profiles. (See about_profiles.)

        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?     false
        Accept wildcard characters? false

    -NoNewWindow [<SwitchParameter>]
        Prevents the process from running in a new window. By default, the process runs in a new window.

        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?     false
        Accept wildcard characters? false

    -PassThru [<SwitchParameter>]
        Returns a process object for each process that the cmdlet started. By default, this cmdlet does not generate any output.

        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?     false
        Accept wildcard characters? false

    -RedirectStandardError <string>
        Sends any errors generated by the process to a file that you specify. Enter the path and file name. By default, the errors are displayed in the console.

        Required?                    false
        Position?                    named
        Default value                Errors are displayed in the console
        Accept pipeline input?     false
        Accept wildcard characters? false

    -RedirectStandardInput <string>
        Reads input from the specified file. Enter the path and file name of the input file. By default, the process gets its input from the keyboard.

        Required?                    false
        Position?                    named
        Default value                Keyboard
        Accept pipeline input?     false
        Accept wildcard characters? false

    -RedirectStandardOutput <string>
        Sends the output generated by the process to a file that you specify. Enter the path and file name. By default, the output is displayed in the console.

        Required?                    false
        Position?                    named
        Default value                FALSE
        Accept pipeline input?     false
        Accept wildcard characters? false

    -UseNewEnvironment [<SwitchParameter>]
        Use new Environment Variables specified for the process. By default, the started process runs with the Environment Variables specified for the computer and user.

        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Verb <string>
        Specifies a verb to be used when starting the process, such as Edit, Open, or Print.

        Each file type has a set of verbs that you can use. To find the verbs that can be used with the process, use the Verbs property of the object.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Wait [<SwitchParameter>]
        Waits for the specified process to complete before accepting more input. This parameter suppresses the command prompt or retains the window until the process completes.

        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WindowStyle <ProcessWindowStyle>
        Specifies the state of the windows used for the process. Valid values are Normal, Hidden, Minimized, and Maximized. The default value is Normal.

        Required?                    false
        Position?                    named
        Default value                Normal
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WorkingDirectory <string>
        Specifies the location of the executable file or document that runs in the process. The default is the current directory.

        Required?                    false
        Position?                    named
        Default value                Current directory
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    None
        You cannot pipe input to Start-Process.

OUTPUTS
    None or System.Diagnostics.Process
        When you use the PassThru parameter, Start-Process generates a System.Diagnostics.Process. Otherwise, this cmdlet does not return any output.

NOTES

        This cmdlet is implemented by using the Start method of the System.Diagnostics,Process class. For more information about this method, see “Process.Start Method” in the MSDN (Microsoft Developer Network) library at http://go.microsoft.com/fwlink/?LinkId=143602.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Start-Process sort.exe

    Description
    ———–
    This command starts a process that uses the Sort.exe file in the current directory. The command uses all of the default values, including the default window style, working directory, and credentials.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Start-Process myfile.txt -WorkingDirectory “C:\PS-Test” -verb Print

    Description
    ———–
    This command starts a process that prints the C:\PS-Test\MyFile.txt file.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Start-Process Sort.exe -RedirectStandardInput Testsort.txt -RedirectStandardOutput Sorted.txt -RedirectStandardError SortError.txt -UseNewEnvironment

    Description
    ———–
    This command starts a process that sorts items in the Testsort.txt file and returns the sorted items in the Sorted.txt files. Any errors are written to the SortError.txt file.

    The UseNewEnvironment parameter specifies that the process runs with its own Environment Variables.

    ————————– EXAMPLE 4 ————————–

    C:\PS>Start-Process notepad -Wait -windowstyle Maximized

    Description
    ———–
    This command starts the Notepad process. It maximizes the window and retains the window until the process completes.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135261
    Start-Service
    Get-Process
    Stop-Process
    Wait-Process
    Debug-Process

Stop-Process

NAME
    Stop-Process

SYNOPSIS
    Stops one or more running processes.

SYNTAX
    Stop-Process [-Id] <Int32[]> [-Force] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

    Stop-Process -InputObject <Process[]> [-Force] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

    Stop-Process -Name <string[]> [-Force] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Stop-Process cmdlet stops one or more running processes. You can specify a process by process name or process ID (PID), or pass a process object to Stop-Process. Stop-Process works only on processes running on the local computer.

    On Windows Vista and later versions of Windows, to stop a process that is not owned by the current user, you must start Windows PowerShell with the “Run as administrator” option. Also, you are prompted for confirmation unless you use the Force parameter.

PARAMETERS
    -Force [<SwitchParameter>]
        Stops the specified processes without prompting for confirmation. By default, Stop-Process prompts for confirmation before stopping any process that is not owned by the current user.

        To find the owner of a process, use the Get-WmiMethod cmdlet to get a Win32_Process object that represents the process, and then use the GetOwner method of the object.

        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Id <Int32[]>
        Specifies the process IDs of the processes to be stopped. To specify multiple IDs, use commas to separate the IDs. To find the PID of a process, type “Get-Process“. The parameter name (“Id”) is optional.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -InputObject <Process[]>
        Stops the processes represented by the specified process objects. Enter a Variable that contains the objects, or type a command or expression that gets the objects.

        Required?                    true
        Position?                    named
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? false

    -Name <string[]>
        Specifies the process names of the processes to be stopped. You can type multiple process names (separated by commas) or use wildcard characters.

        Required?                    true
        Position?                    named
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -PassThru [<SwitchParameter>]
        Returns an object representing the process. By default, this cmdlet does not generate any output.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Diagnostics.Process
        You can pipe a process object to Stop-Process.

OUTPUTS
    None or System.Diagnostics.Process
        When you use the PassThru parameter, Stop-Process returns a System.Diagnostics.Process object that represents the stopped process. Otherwise, this cmdlet does not generate any output.

NOTES

        You can also refer to Stop-Process by its built-in Aliases, “kill” and “spps”. For more information, see about_aliases.

        You can also use the properties and methods of the Windows Management Instrumentation (WMI) Win32_Process object in Windows PowerShell. For more information, see Get-WmiObject and the WMI SDK.

        When stopping processes, be aware that stopping a process can stop process and services that depend on the process. In an extreme case, stopping a process can stop Windows.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Stop-Process -name notepad

    Description
    ———–
    This command stops all instances of the Notepad process on the computer. (Each instance of Notepad runs in its own process.) It uses the Name parameter to specify the processes, all of which have the same name. If you were to use the ID parameter to stop the same processes, you would have to list the process IDs of each instance of Notepad.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Stop-Process -Id 3952 -Confirm -PassThru

    Confirm
    Are you sure you want to perform this action?
    Performing operation “Stop-Process” on Target “notepad (3952)”.
    [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help
    (default is “Y”):y
    Handles NPM(K)    PM(K)     WS(K) VM(M) CPU(s)     Id ProcessName
    ——- ——    —–     —– —– ——     — ———–
         41     2     996     3212    31            3952 notepad

    Description
    ———–
    This command stops a particular instance of the Notepad process. It uses the process ID, 3952, to identify the process. The Confirm parameter directs Windows PowerShell to prompt the user before stopping the process. Because the prompt includes the process name, as well as its ID, this is best practice. The PassThru parameter passes the process object to the formatter for display. Without this parameter, there would be no display after a Stop-Process command.

    ————————– EXAMPLE 3 ————————–

    C:\PS>calc

    c:\PS>$p = Get-Process calc

    c:\PS>Stop-Process -inputobject $p

    c:\PS>Get-Process | Where-Object {$_.HasExited}

    Description
    ———–
    This series of commands starts and stops the Calc process and then detects processes that have stopped.

    The first command (“calc”) starts an instance of the calculator. The second command (“$p = Get-Process calc”), uses the Get-Process cmdlet to get an object representing the Calc process and store it in the $p Variable. The third command (“Stop-Process -inputobject $p”) uses the Stop-Process cmdlet to stop the Calc process. It uses the InputObject parameter to pass the object to Stop-Process.

    The last command gets all of the processes on the computer that were running but that are now stopped. It uses the Get-Process cmdlet to get all of the processes on the computer. The pipeline operator (|) passes the results to the Where-Object cmdlet, which selects the ones where the value of the HasExited property is TRUE. HasExited is just one property of process objects. To find all the properties, type “Get-Process | Get-Member“.

    ————————– EXAMPLE 4 ————————–

    C:\PS>Get-Process lsass | Stop-Process

    Stop-Process : Cannot stop process ‘lsass (596)’ because of the following error: Access is denied
    At line:1 char:34
    + Get-Process lsass | Stop-Process <<<<

    [ADMIN]: C:\PS> Get-Process lsass | Stop-Process
    Warning!
    Are you sure you want to perform this action?
    Performing operation ‘Stop-Process‘ on Target ‘lsass(596)’
    [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “Y”):

    [ADMIN]: C:\PS> Get-Process lsass | Stop-Process -Force
    [ADMIN]: C:\PS>

    Description
    ———–
    These commands show the effect of using the Force parameter to stop a process that is not owned by the user.

    The first command uses the Get-Process cmdlet to get the Lsass process. A pipeline operator sends the process to the Stop-Process cmdlet to stop it. As shown in the sample output, the first command fails with an “Access denied” message, because this process can be stopped only by a member of the Administrator’s group on the computer.

    When Windows PowerShell is opened with the “Run as administrator” option, and the command is repeated, Windows PowerShell prompts you for confirmation.

    The second command uses the Force parameter to suppress the prompt. As a result, the process is stopped without confirmation.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113412
    Get-Process
    Start-Process
    Stop-Process
    Wait-Process
    Debug-Process

Get-Process

NAME
    Get-Process

SYNOPSIS
    Gets the processes that are running on the local computer or a remote computer.

SYNTAX
    Get-Process [[-Name] <string[]>] [-ComputerName <string[]>] [-FileVersionInfo] [-Module] [<CommonParameters>]

    Get-Process -Id <Int32[]> [-ComputerName <string[]>] [-FileVersionInfo] [-Module] [<CommonParameters>]

    Get-Process -InputObject <Process[]> [-ComputerName <string[]>] [-FileVersionInfo] [-Module] [<CommonParameters>]

DESCRIPTION
    The Get-Process cmdlet gets the processes on a local or remote computer.

    Without parameters, Get-Process gets all of the processes on the local computer. You can also specify a particular process by process name or process ID (PID) or pass a process object through the pipeline to Get-Process.

    By default, Get-Process returns a process object that has detailed information about the process and supports methods that let you start and stop the process. You can also use the parameters of Get-Process to get file version information for the program that runs in the process and to get the modules that the process loaded.

PARAMETERS
    -ComputerName <string[]>
        Gets the processes running on the specified computers. The default is the local computer.

        Type the NetBIOS name, an IP address, or a fully qualified domain name of one or more computers. To specify the local computer, type the computer name, a dot (.), or “localhost”.

        This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of Get-Process even if your computer is not configured to run remote commands.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -FileVersionInfo [<SwitchParameter>]
        Gets the file version information for the program that runs in the process.

        On Windows Vista and later versions of Windows, you must open Windows PowerShell with the “Run as administrator” option to use this parameter on processes that you do not own.

        Using this parameter is equivalent to getting the MainModule.FileVersionInfo property of each process object. When you use this parameter, Get-Process returns a FileVersionInfo object (System.Diagnostics.FileVersionInfo), not a process object. So, you cannot pipe the output of the command to a cmdlet that expects a process object, such as Stop-Process.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Id <Int32[]>
        Specifies one or more processes by process ID (PID). To specify multiple IDs, use commas to separate the IDs. To find the PID of a process, type “Get-Process“.

        Required?                    true
        Position?                    named
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -InputObject <Process[]>
        Specifies one or more process objects. Enter a Variable that contains the objects, or type a command or expression that gets the objects.

        Required?                    true
        Position?                    named
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? false

    -Module [<SwitchParameter>]
        Gets the modules that have been loaded by the processes.

        On Windows Vista and later versions of Windows, you must open Windows PowerShell with the “Run as administrator” option to use this parameter on processes that you do not own.

        This parameter is equivalent to getting the Modules property of each process object. When you use this parameter, Get-Process returns a ProcessModule object (System.Diagnostics.ProcessModule), not a process object. So, you cannot pipe the output of the command to a cmdlet that expects a process object, such as Stop-Process.

        When you use both the Module and FileVersionInfo parameters in the same command, Get-Process returns a FileVersionInfo object with information about the file version of all modules.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Name <string[]>
        Specifies one or more processes by process name. You can type multiple process names (separated by commas) or use wildcard characters. The parameter name (“Name”) is optional.

        Required?                    false
        Position?                    1
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? true

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Diagnostics.Process
        You can pipe a process object to Get-Process.

OUTPUTS
    System.Diagnostics.Process, System.Diagnotics.FileVersionInfo, System.Diagnostics.ProcessModule
        By default, Get-Process returns a System.Diagnostics.Process object. If you use the FileVersionInfo parameter, it returns a System.Diagnotics.FileVersionInfo object. If you use the Module parameter (without the FileVersionInfo parameter), it returns a System.Diagnostics.ProcessModule object.

NOTES

        You cannot use the Name, ID, and InputObject parameters in the same command.

        You can also refer to Get-Process by its built-in Aliases, “ps” and “gps”. For more information, see about_aliases.

        You can also use the properties and methods of the WMI Win32_Process object in Windows PowerShell. For information, see Get-WmiObject and the Windows Management Instrumentation (WMI) SDK.

        The default display of a process is a table that includes the following columns:

        — Handles: The number of handles that the process has opened.

        — NPM(K): The amount of non-paged memory that the process is using, in kilobytes.

        — PM(K): The amount of pageable memory that the process is using, in kilobytes.

        — WS(K): The size of the working set of the process, in kilobytes. The working set consists of the pages of memory that were recently referenced by the process.

        — VM(M): The amount of virtual memory that the process is using, in megabytes. Virtual memory includes storage in the paging files on disk.

        — CPU(s): The amount of processor time that the process has used on all processors, in seconds.

        — ID: The process ID (PID) of the process.

        — ProcessName: The name of the process.

        For explanations of the concepts related to processes, see the Glossary in Help and Support Center and the Help for Task Manager.

        You can also use the built-in alternate views of the processes available with Format-Table, such as “StartTime” and “Priority”, and you can design your own views. For more information, see Format-Table.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Get-Process

    Description
    ———–
    This command gets a list of all of the running processes running on the local computer. For a definition of each column, see the “Additional Notes” section of the Help topic for Get-Help.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Get-Process winword, explorer | Format-List *

    Description
    ———–
    This command gets all available data about the Winword and Explorer processes on the computer. It uses the Name parameter to specify the processes, but it omits the optional parameter name. The pipeline operator (|) passes the data to the Format-List cmdlet, which displays all available properties (*) of the Winword and Explorer process objects.

    You can also identify the processes by their process IDs. For example, “Get-Process -id 664, 2060″.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Get-Process | Where-Object {$_.WorkingSet -gt 20000000}

    Description
    ———–
    This command gets all processes that have a working set greater than 20 MB. It uses the Get-Process cmdlet to get all running processes. The pipeline operator (|) passes the process objects to the Where-Object cmdlet, which selects only the object with a value greater than 20,000,000 bytes for the WorkingSet property.

    WorkingSet is one of many properties of process objects. To see all of the properties, type “Get-Process | Get-Member“. By default, the values of all amount properties are in bytes, even though the default display lists them in kilobytes and megabytes.

    ————————– EXAMPLE 4 ————————–

    C:\PS>$a = Get-Process

    C:\PS> Get-Process -inputobject $a | Format-Table -view priority

    Description
    ———–
    These commands list the processes on the computer in groups based on their priority class.

    The first command gets all the processes on the computer and then stores them in the $a Variable.

    The second command uses the InputObject parameter to pass the process objects that are stored in the $a Variable to the Get-Process cmdlet. The pipeline operator passes the objects to the Format-Table cmdlet, which formats the processes by using the Priority view.

    The priority view, and other views, are defined in the PS1XML format files in the Windows PowerShell home directory ($pshome).

    ————————– EXAMPLE 5 ————————–

    C:\PS>Get-Process powershell -ComputerName S1, localhost | ft @{Label=”NPM(K)”;Expression={[int]($_.NPM/1024)}}, @{Label=”PM(K)”;Expression={[int]($_.PM/1024)}},@{Label=”WS(K)”;Expression={[int]($_.WS/1024)}},@{Label=”VM(M)”;Expression={[int]($_.VM/1MB)}}, @{Label=”CPU(s)”;Expression={if ($_.CPU -ne $()) { $_.CPU.ToString(“N”)}}}, Id, MachineName, ProcessName -auto

    NPM(K) PM(K) WS(K) VM(M) CPU(s) Id MachineName ProcessName
    —— —– —– —– —— — ———– ———–
         6 23500 31340 142        1980 S1         powershell
         6 23500 31348 142        4016 S1         powershell
        27 54572 54520 576        4428 localhost powershell

    Description
    ———–
    This example provides a Format-Table (alias = ft) command that adds the MachineName property to the standard Get-Process output display.

    ————————– EXAMPLE 6 ————————–

    C:\PS>Get-Process powershell -FileVersionInfo

    ProductVersion FileVersion     FileName
    ————– ———–     ——–
    6.1.6713.1     6.1.6713.1 (f… C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe

    Description
    ———–
    This command uses the FileVersionInfo parameter to get the version information for the PowerShell.exe file that is the main module for the PowerShell process.

    To run this command with processes that you do not own on Windows Vista and later versions of Windows, you must open Windows PowerShell with the “Run as administrator” option.

    ————————– EXAMPLE 7 ————————–

    C:\PS>Get-Process sql* -Module

    Description
    ———–
    This command uses the Module parameter to get the modules that have been loaded by the process. This command gets the modules for the processes that have names that begin with “sql”.

    To run this command on Windows Vista (and later versions of Windows) with processes that you do not own, you must start Windows PowerShell with the “Run as administrator” option.

    ————————– EXAMPLE 8 ————————–

    C:\PS>$p = Get-WmiObject win32_process -filter “name=’powershell.exe'”

    C:\PS> $p.getowner()

    __GENUS         : 2
    __CLASS         : __PARAMETERS
    __SUPERCLASS     :
    __DYNASTY        : __PARAMETERS
    __RELPATH        :
    __PROPERTY_COUNT : 3
    __DERIVATION     : {}
    __SERVER         :
    __NAMESPACE     :
    __PATH         :
    Domain         : DOMAIN01
    ReturnValue     : 0
    User             : user01

    Description
    ———–
    This command shows how to find the owner of a process. Because the System.Diagnostics.Process object that Get-Process returns does not have a property or method that returns the process owner, the command uses
    the Get-WmiObject cmdlet to get a Win32_Process object that represents the same process.

    The first command uses Get-WmiObject to get the PowerShell process. It saves it in the $p Variable.

    The second command uses the GetOwner method to get the owner of the process in $p. The command reveals that the owner is Domain01\user01.

    ————————– EXAMPLE 9 ————————–

    C:\PS>Get-Process powershell

    C:\PS> Get-Process -id $pid

    C:\PS> Get-Process powershell

    Handles NPM(K)    PM(K)     WS(K) VM(M) CPU(s)     Id ProcessName
    ——- ——    —–     —– —– ——     — ———–
        308     26    52308     61780 567     3.18 5632 powershell
        377     26    62676     63384 575     3.88 5888 powershell

    C:\PS> Get-Process -id $pid

    Handles NPM(K)    PM(K)     WS(K) VM(M) CPU(s)     Id ProcessName
    ——- ——    —–     —– —– ——     — ———–
        396     26    56488     57236 575     3.90 5888 powershell

    Description
    ———–
    These commands show how to use the $pid automatic Variable to identify the process that is hosting the current Windows PowerShell session. You can use this method to distinguish the host process from other PowerShell processes that you might want to stop or close.

    The first command gets all of the PowerShell processes in the current session.

    The second command gets the PowerShell process that is hosting the current session.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113324
    Get-Process
    Start-Process
    Stop-Process
    Wait-Process
    Debug-Process

Debug-Process

NAME
    Debug-Process

SYNOPSIS
    Debugs one or more processes running on the local computer.

SYNTAX
    Debug-Process [-Name] <string[]> [-Confirm] [-WhatIf] [<CommonParameters>]

    Debug-Process [-Id] <Int32[]> [-Confirm] [-WhatIf] [<CommonParameters>]

    Debug-Process -InputObject <Process[]> [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Debug-Process cmdlet attaches a debugger to one or more running processes on a local computer. You can specify the processes by their process name or process ID (PID), or you can pipe process objects to Debug-Process.

    Debug-Process attaches the debugger that is currently registered for the process. Before using this cmdlet, verify that a debugger is downloaded and correctly configured.

PARAMETERS
    -Id <Int32[]>
        Specifies the process IDs of the processes to be debugged. The parameter name (“-Id”) is optional.

        To find the process ID of a process, type “Get-Process“.

        Required?                    true
        Position?                    1
        Default value                None
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -InputObject <Process[]>
        Specifies the process objects that represent processes to be debugged. Enter a Variable that contains the process objects or a command that gets the process objects, such as a Get-Process command. You can also pipe process objects to Debug-Process.

        Required?                    true
        Position?                    named
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? false

    -Name <string[]>
        Specifies the names of the processes to be debugged. If there is more than one process with the same name, Debug-Process attaches a debugger to all processes with that name. The parameter name (“Name”) is optional.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Int32, System.Diagnostics.Process, System.String
        You can pipe a process ID (Int32), a process object (System.Diagnostics.Process), or a process name (String) to Debug-Process.

OUTPUTS
    None
        This cmdlet does not generate any output.

NOTES

        This cmdlet uses the AttachDebugger method of the Windows Management Instrumentation (WMI) Win32_Process class. For more information about this method, see “AttachDebugger Method” in the MSDN (Microsoft Developer Network) library at http://go.microsoft.com/fwlink/?LinkId=143640.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Debug-Process -Name powershell

    Description
    ———–
    This command attaches a debugger to the PowerShell process on the computer.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Debug-Process -Name sql*

    Description
    ———–
    This command attaches a debugger to all processes that have names that begin with “sql”.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Debug-Process winlogon, explorer, outlook

    Description
    ———–
    This command attaches a debugger to the Winlogon, Explorer, and Outlook processes.

    ————————– EXAMPLE 4 ————————–

    C:\PS>Debug-Process -id 1132, 2028

    Description
    ———–
    This command attaches a debugger to the processes that have process IDs 1132 and 2028.

    ————————– EXAMPLE 5 ————————–

    C:\PS>Get-Process powershell | Debug-Process

    Description
    ———–
    This command attaches a debugger to the PowerShell processes on the computer. It uses the Get-Process cmdlet to get the PowerShell processes on the computer, and it uses a pipeline operator (|) to send the processes to the Debug-Process cmdlet.

    To specify a particular PowerShell process, use the ID parameter of Get-Process.

    ————————– EXAMPLE 6 ————————–

    C:\PS>$pid | Debug-Process

    Description
    ———–
    This command attaches a debugger to the current PowerShell processes on the computer.

    It uses the $pid automatic Variable, which contains the process ID of the current PowerShell process. Then, it uses a pipeline operator (|) to send the process ID to the Debug-Process cmdlet.

    For more information about the $pid automatic Variable, see about_Automatic_Variables.

    ————————– EXAMPLE 7 ————————–

    C:\PS>Get-Process -computername Server01, Server02 -Name MyApp | Debug-Process

    Description
    ———–
    This command attaches a debugger to the MyApp processes on the Server01 and Server02 computers.

    It uses the Get-Process cmdlet to get the MyApp processes on the Server01 and Server02 computers. It uses a pipeline operator to send the processes to the Debug-Process cmdlet, which attaches the debuggers.

    ————————– EXAMPLE 8 ————————–

    C:\PS>$p = Get-Process powershell

    C:\PS> Debug-Process -inputobject $p

    Description
    ———–
    This command attaches a debugger to the PowerShell processes on the local computer.

    The first command uses the Get-Process cmdlet to get the PowerShell processes on the computer. It saves the resulting process object in the $p Variable.

    The second command uses the InputObject parameter of Debug-Process to submit the process object in the $p Variable to Debug-Process.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135206
    Get-Process
    Start-Process
    Stop-Process
    Wait-Process
    Debug-Process