Tag Archives: PassThru

Stop-Service

NAME
    Stop-Service

SYNOPSIS
    Stops one or more running services.

SYNTAX
    Stop-Service [-Name] <string[]> [-Exclude <string[]>] [-Force] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

    Stop-Service -DisplayName <string[]> [-Exclude <string[]>] [-Force] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

    Stop-Service [-InputObject <ServiceController[]>] [-Exclude <string[]>] [-Force] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Stop-Service cmdlet sends a stop message to the Windows Service Controller for each of the specified services. You can specify the services by their service names or display names, or you can use the InputObject parameter to pass a service object representing the services that you want to stop.

PARAMETERS
    -DisplayName <string[]>
        Specifies the display names of the services to be stopped. Wildcards are permitted.

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

    -Exclude <string[]>
        Omits the specified services. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as “s*”. Wildcards are permitted.

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

    -Force [<SwitchParameter>]
        Allows the cmdlet to stop a service even if that service has dependent services.

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

    -Include <string[]>
        Stops only the specified services. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as “s*”. Wildcards are permitted.

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

    -InputObject <ServiceController[]>
        Specifies ServiceController objects representing the services to be stopped. Enter a Variable that contains the objects, or type a command or expression that gets the objects.

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

    -Name <string[]>
        Specifies the service names of the services to be stopped. Wildcards are permitted.

        The parameter name is optional. You can use “Name” or its Alias, “ServiceName”, or you can omit the parameter name.

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

    -PassThru [<SwitchParameter>]
        Returns an object representing the service. 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.ServiceProcess.ServiceController or System.String
        You can pipe a service object or a string that contains the name of a service to Stop-Service.

OUTPUTS
    None or System.ServiceProcess.ServiceController
        When you use the PassThru parameter, Stop-Service generates a System.ServiceProcess.ServiceController object representing the service. Otherwise, this cmdlet does not generate any output.

NOTES

        You can also refer to Stop-Service by its built-in Alias, “spsv”. For more information, see about_aliases.

        Stop-Service can control services only when the current user has permission to do so. If a command does not work correctly, you might not have the required permissions.

        To find the service names and display names of the services on your system, type “Get-Service“. The service names appear in the Name column and the display names appear in the DisplayName column.

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

    C:\PS>Stop-Service sysmonlog

    Description
    ———–
    This command stops the Performance Logs and Alerts (SysmonLog) service on the local computer.

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

    C:\PS>Get-Service -displayname telnet | Stop-Service

    Description
    ———–
    This command stops the Telnet service on the local computer. The command uses the Get-Service cmdlet to get an object representing the Telnet service. The pipeline operator (|) pipes the object to the Stop-Service cmdlet, which stops the service.

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

    C:\PS>Get-Service iisadmin | Format-List -property name, dependentservices

    C:PS>Stop-Service iisadmin -Force -Confirm

    Description
    ———–
    The Stop-Service command stops the IISAdmin service on the local computer. Because stopping this service also stops the services that depend on the IISAdmin service, it is best to precede the Stop-Service command with a command that lists the services that depend on the IISAdmin service.

    The first command lists the services that depend on IISAdmin. It uses the Get-Service cmdlet to get an object representing the IISAdmin service. The pipeline operator (|) passes the result to the Format-List cmdlet. The command uses the Property parameter of Format-List to list only the Name and DependentServices properties of the service.

    The second command stops the IISAdmin service. The Force parameter is required to stop a service that has dependent services. The command uses the Confirm parameter to request confirmation from the user before stopping each service.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113414
    Get-Service
    Suspend-Service
    Start-Service
    Restart-Service
    Resume-Service
    Set-Service
    New-Service

Suspend-Service

NAME
    Suspend-Service

SYNOPSIS
    Suspends (pauses) one or more running services.

SYNTAX
    Suspend-Service [-Name] <string[]> [-Exclude <string[]>] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

    Suspend-Service -DisplayName <string[]> [-Exclude <string[]>] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

    Suspend-Service [-InputObject <ServiceController[]>] [-Exclude <string[]>] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Suspend-Service cmdlet sends a suspend message to the Windows Service Controller for each of the specified services. While suspended, the service is still running, but its action is halted until resumed, such as by using Resume-Service. You can specify the services by their service names or display names, or you can use the InputObject parameter to pass a service object representing the services that you want to suspend.

PARAMETERS
    -DisplayName <string[]>
        Specifies the display names of the services to be suspended. Wildcards are permitted.

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

    -Exclude <string[]>
        Omits the specified services. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as “s*”. Wildcards are permitted.

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

    -Include <string[]>
        Suspends only the specified services. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as “s*”. Wildcards are permitted.

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

    -InputObject <ServiceController[]>
        Specifies ServiceController objects representing the services to be suspended. Enter a Variable that contains the objects, or type a command or expression that gets the objects.

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

    -Name <string[]>
        Specifies the service names of the services to be suspended. Wildcards are permitted.

        The parameter name is optional. You can use “Name” or its Alias, “ServiceName”, or you can omit the parameter name.

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

    -PassThru [<SwitchParameter>]
        Returns an object representing the service. 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.ServiceProcess.ServiceController or System.String
        You can pipe a service object or a string that contains a service name to Suspend-Service.

OUTPUTS
    None or System.ServiceProcess.ServiceController
        When you use the PassThru parameter, Suspend-Service generates a System.ServiceProcess.ServiceController object representing the service. Otherwise, this cmdlet does not generate any output.

NOTES

        Suspend-Service can control services only when the current user has permission to do so. If a command does not work correctly, you might not have the required permissions.

        Also, Suspend-Service can suspend only services that support being suspended and resumed. To determine whether a particular service can be suspended, use the Get-Service cmdlet with the CanPauseAndContinue property. For example, “Get-Service wmi | Format-List name, canpauseandcontinue”. To find all services on the computer that can be suspended, type “Get-Service | Where-Object {$_.canpauseandcontinue -eq “True”}”.

        To find the service names and display names of the services on your system, type “Get-Service“. The service names appear in the Name column, and the display names appear in the DisplayName column.

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

    C:\PS>Suspend-Service -displayname “Telnet”

    Description
    ———–
    This command suspends the Telnet service (Tlntsvr) service on the local computer.

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

    C:\PS>Suspend-Service -Name lanman* -WhatIf

    Description
    ———–
    This command tells what would happen if you suspended the services that have a service name that begins with “lanman”. To suspend the services, rerun the command without the WhatIf parameter.

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

    C:\PS>Get-Service schedule | Suspend-Service

    Description
    ———–
    This command uses the Get-Service cmdlet to get an object that represents the Task Scheduler (Schedule) service on the computer. The pipeline operator (|) passes the result to the Suspend-Service cmdlet, which suspends the service.

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

    C:\PS>Get-Service | Where-Object {$_.canpauseandcontinue -eq “True”} | Suspend-Service -Confirm

    Description
    ———–
    This command suspends all of the services on the computer that can be suspended. It uses the Get-Service cmdlet to get objects representing the services on the computer. The pipeline operator (|) passes the results to the Where-Object cmdlet, which selects only the services that have a value of “True” for the CanPauseAndContinue property. Another pipeline operator passes the results to the Suspend-Service cmdlet. The Confirm parameter prompts you for confirmation before suspending each of the services.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113416
    Get-Service
    Start-Service
    Stop-Service
    Restart-Service
    Resume-Service
    Set-Service
    New-Service

Set-Variable

NAME
    Set-Variable

SYNOPSIS
    Sets the value of a Variable. Creates the Variable if one with the requested name does not exist.

SYNTAX
    Set-Variable [-Name] <string[]> [[-Value] <Object>] [-Description <string>] [-Exclude <string[]>] [-Force] [-Include <string[]>] [-Option {None | ReadOnly | Constant | Private | AllScope}] [-PassThru] [-Scope <string>] [-Visibility {Public | Private}] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Set-Variable cmdlet assigns a value to a specified Variable or changes the current value. If the Variable does not exist, the cmdlet creates it.

PARAMETERS
    -Description <string>
        Specifies the description of the Variable.

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

    -Exclude <string[]>
        Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as “*.txt”. Wildcards are permitted.

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

    -Force [<SwitchParameter>]
        Allows you to create a Variable with the same name as an existing read-only Variable, or to change the value of a read-only Variable.

        By default, you can overwrite a Variable, unless the Variable has an option value of “ReadOnly” or “Constant”. For more information, see the Option parameter.

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

    -Include <string[]>
        Changes only the specified items. The value of this parameter qualifies the Name parameter. Enter a name or name pattern, such as “c*”. Wildcards are permitted.

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

    -Name <string[]>
        Specifies the Variable name.

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

    -Option <ScopedItemOptions>
        Changes the value of the Options property of the Variable. Valid values are:

        — None: Sets no options. (“None” is the default.)

        — ReadOnly: The properties of the Variable cannot be changed, except by using the Force parameter. You can use Remove-Variable to delete the Variable.

        — Constant: The Variable cannot be deleted and its properties cannot be changed. “Constant” is available only when you are creating an Alias. You cannot change the option of an existing Variable to “Constant”.

        — Private: The Variable is available only within the scope specified by the Scope parameter. It is inherited by child scopes.

        — AllScope: The Variable is copied to any new scopes that are created.

        To see the Options property of the Variables, type “Get-Variable| Format-Table -property name, options -autosize”.

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

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

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

    -Scope <string>
        Determines the scope of the Variable. Valid values are “Global”, “Local”, or “Script”, or a number relative to the current scope (0 through the number of scopes, where 0 is the current scope and 1 is its parent). “Local” is the default. For more information, see about_scopes.

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

    -Value <Object>
        Specifies the value of the Variable.

        Required?                    false
        Position?                    2
        Default value
        Accept pipeline input?     true (ByValue, ByPropertyName)
        Accept wildcard characters? false

    -Visibility <SessionStateEntryVisibility>
        Determines whether the Variable is visible outside of the session in which it was created. This parameter is designed for use in scripts and commands that will be delivered to other users.

        Valid values are:

        — Public: The Variable is visible. (“Public” is the default.)
        — Private: The Variable is not visible.

        When a Variable is private, it does not appear in lists of Variables, such as those returned by Get-Variable, or in displays of the Variable: drive. Commands to read or change the value of a private Variable return an error. However, the user can run commands that use a private Variable if the commands were written in the session in which the Variable was defined.

        Required?                    false
        Position?                    named
        Default value                Public
        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.Object
        You can pipe an object that represents the value of the Variable to Set-Variable.

OUTPUTS
    None or System.Management.Automation.PSVariable
        When you use the PassThru parameter, Set-Variable generates a System.Management.Automation.PSVariable object representing the new or changed Variable. Otherwise, this cmdlet does not generate any output.

NOTES

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

    C:\PS>Set-Variable -Name desc -Value “A description”

    C:\PS>Get-Variable -Name desc

    Description
    ———–
    These commands set the value of the “desc” Variable to “A description”, and then get the value of the Variable.

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

    C:\PS>Set-Variable -Name processes -Value (Get-Process) -Option constant -Scope global -Description “All processes” -PassThru | Format-List -property *

    Description
    ———–
    This command creates a global, read-only Variable that contains all processes on the system, and then it displays all properties of the Variable.

    The command uses the Set-Variable cmdlet to create the Variable. It uses the PassThru parameter to create an object representing the new Variable, and it uses the pipeline operator (|) to pass the object to the Format-List cmdlet. It uses the Property parameter of Format-List with a value of all (*) to display all properties of the newly created Variable.

    The value, “(Get-Process)”, is enclosed in parentheses to ensure that it is executed before being stored in the Variable. Otherwise, the Variable contains the words “Get-Process“.

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

    C:\PS># Set-Variable -Name counter -Visibility private

    C:\PS> New-Variable -Name counter -Visibility public -Value 26

    C:\PS> $counter
    26

    C:\PS> Get-Variable c*

    Name Value
    —- —–
    Culture en-US
    ConsoleFileName
    ConfirmPreference High
    CommandLineParameters {}
    Counter 26

    C:\PS> Set-Variable -Name counter -Visibility private

    C:\PS> Get-Variable c*

    Name Value
    —- —–
    Culture en-US
    ConsoleFileName
    ConfirmPreference High
    CommandLineParameters {}

    C:\PS> $counter
    “Cannot access the Variable ‘$counter’ because it is a private Variable

    C:\PS> .\use-counter.ps1
    Commands completed successfully.

    Description
    ———–
    This command shows how to change the visibility of a Variable to “Private”. This Variable can be read and changed by scripts with the required permissions, but it is not visible to the user.

    The sample output shows the difference in the behavior of public and private Variables.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113401
    Get-Variable
    New-Variable
    Remove-Variable
    Clear-Variable

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

Start-Service

NAME
    Start-Service

SYNOPSIS
    Starts one or more stopped services.

SYNTAX
    Start-Service [-Name] <string[]> [-Exclude <string[]>] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

    Start-Service -DisplayName <string[]> [-Exclude <string[]>] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

    Start-Service [-InputObject <ServiceController[]>] [-Exclude <string[]>] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Start-Service cmdlet sends a start message to the Windows Service Controller for each of the specified services. If a service is already running, the message is ignored without error. You can specify the services by their service names or display names, or you can use the InputObject parameter to supply a service object representing the services that you want to start.

PARAMETERS
    -DisplayName <string[]>
        Specifies the display names of the services to be started. Wildcards are permitted.

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

    -Exclude <string[]>
        Omits the specified services. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as “s*”. Wildcards are permitted.

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

    -Include <string[]>
        Starts only the specified services. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as “s*”. Wildcards are permitted.

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

    -InputObject <ServiceController[]>
        Specifies ServiceController objects representing the services to be started. Enter a Variable that contains the objects, or type a command or expression that gets the objects.

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

    -Name <string[]>
        Specifies the service names for the service to be started.

        The parameter name is optional. You can use “-Name” or its Alias, “-ServiceName”, or you can omit the parameter name.

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

    -PassThru [<SwitchParameter>]
        Returns an object representing the service. 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.ServiceProcess.ServiceController, System.String
        You can pipe objects that represent the services or strings that contain the service names to Start-Service.

OUTPUTS
    None or System.ServiceProcess.ServiceController
        When you use the PassThru parameter, Start-Service generates a System.ServiceProcess.ServiceController object representing the service. Otherwise, this cmdlet does not generate any output.

NOTES

        You can also refer to Start-Service by its built-in Alias, “sasv”. For more information, see about_aliases.

        Start-Service can control services only when the current user has permission to do so. If a command does not work correctly, you might not have the required permissions.

        To find the service names and display names of the services on your system, type “Get-Service“. The service names appear in the Name column, and the display names appear in the DisplayName column.

        You can start only the services that have a start type of “Manual” or “Automatic”. You cannot start the services with a start type of “Disabled”. If a Start-Service command fails with the message “Cannot start service <service-Name> on computer,” use a Get-WmiObject command to find the start type of the service and, if necessary, use a Set-Service command to change the start type of the service.

        Some services, such as Performance Logs and Alerts (SysmonLog) stop automatically if they have no work to do. When Windows PowerShell starts a service that stops itself almost immediately, it displays the following message: “Service <display-Name> start failed.”

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

    C:\PS>Start-Service -Name eventlog

    Description
    ———–
    This command starts the EventLog service on the local computer. It uses the Name parameter to identify the service by its service name.

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

    C:\PS>Start-Service -displayname *remote* -WhatIf

    Description
    ———–
    This command tells what would happen if you started the services with a display name that includes “remote”. It uses the DisplayName parameter to specify the services by their display name instead of by their service name. And, it uses the WhatIf parameter to tell what would happen if the command were executed instead of executing the command.

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

    C:\PS>$s = Get-Service wmi

    C:\PS>Start-Service -InputObject $s -PassThru | Format-List >> services.txt

    Description
    ———–
    These commands start the Windows Management Instrumentation (WMI) service on the computer and add a record of the action to the services.txt file. The first command uses the Get-Service cmdlet to get an object representing the WMI service and store it in the $s Variable.

    The second command uses the Start-Service cmdlet to start the WMI service. It identifies the service by using the InputObject parameter to pass the $s Variable containing the WMI service object to Start-Service. Then, it uses the PassThru parameter to create an object that represents the starting of the service. Without this parameter, Start-Service does not create any output.

    The pipeline operator (|) passes the object that Start-Service creates to the Format-List cmdlet, which formats the object as a list of its properties. The append redirection operator (>>) redirects the output to the services.txt file, where it is added to the end of the existing file.

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

    C:\PS># Start-Service

    Description
    ———–
    This series of commands shows how to start a service when the start type of the service is “Disabled”. The first command, which uses the Start-Service cmdlet to start the Telnet service (tlntsvr), fails.

    C:\PS>Start-Service tlntsvr

    Start-Service : Service ‘Telnet (TlntSvr)’ cannot be started due to the    following error: Cannot start service TlntSvr on computer ‘.’.
    At line:1 char:14
    + Start-Service <<<< tlntsvr

    The second command uses the Get-WmiObject cmdlet to get the Tlntsvr service. This command retrieves an object with the start type property in the StartMode field. The resulting display reveals that the start type of the Tlntsvr service is “Disabled”.

    C:\PS> Get-WmiObject win32_service | Where-Object {$_.Name -eq “tlntsvr”}

    ExitCode : 0
    Name     : TlntSvr
    ProcessId : 0
    StartMode : Disabled
    State     : Stopped
    Status    : OK

    The next command uses the Set-Service cmdlet to change the start type of the Tlntsvr service to “Manual”.

    C:\PS> Set-Service tlntsvr -startuptype manual

    Now, we can resubmit the Start-Service command. This time, the command succeeds.

    C:\PS> Start-Service tlntsvr

    To verify that the command succeeded, use Get-Service.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113406
    Get-Service
    Suspend-Service
    Stop-Service
    Restart-Service
    Resume-Service
    Set-Service
    New-Service

Stop-Job

NAME
    Stop-Job

SYNOPSIS
    Stops a Windows PowerShell background job.

SYNTAX
    Stop-Job [[-InstanceId] <Guid[]>] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

    Stop-Job [-Job] <Job[]> [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

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

    Stop-Job [-Id] <Int32[]> [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

    Stop-Job [-State {NotStarted | Running | Completed | Failed | Stopped | Blocked}] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Stop-Job cmdlet stops Windows PowerShell background jobs that are in progress. You can use this cmdlet to stop all jobs or stop selected jobs based on their name, ID, instance ID, or state, or by passing a job object to Stop-Job.

    You can use Stop-Job to stop jobs that were started by using Start-Job or the AsJob parameter of Invoke-Command. When you stop a background job, Windows PowerShell completes all tasks that are pending in that job queue and then ends the job. No new tasks are added to the queue after this command is submitted.

    This cmdlet does not delete background jobs. To delete a job, use Remove-Job.

PARAMETERS
    -Id <Int32[]>
        Stops jobs with the specified IDs. The default is all jobs in the current session.

        The ID is an integer that uniquely identifies the job within the current session. It is easier to remember and type than the InstanceId, but it is unique only within the current session. You can type one or more IDs (separated by commas). To find the ID of a job, type “Get-Job” without parameters.

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

    -InstanceId <Guid[]>
        Stops only jobs with the specified instance IDs. The default is all jobs.

        An instance ID is a GUID that uniquely identifies the job on the computer. To find the instance ID of a job, use Get-Job.

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

    -Job <Job[]>
        Specifies the jobs to be stopped. Enter a Variable that contains the jobs or a command that gets the jobs. You can also use a pipeline operator to submit jobs to the Stop-Job cmdlet. By default, Stop-Job deletes all jobs that were started in the current session.

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

    -Name <string[]>
        Stops only the jobs with the specified friendly names. Enter the job names in a comma-separated list or use wildcard characters (*) to enter a job name pattern. By default, Stop-Job stops all jobs created in the current session.

        Because the friendly name is not guaranteed to be unique, use the WhatIf and Confirm parameters when stopping jobs by name.

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

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

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

    -State <JobState>
        Stops only jobs within the specified state. Valid values are NotStarted, Running, Completed, Stopped, Failed, and Blocked.

        Required?                    false
        Position?                    named
        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.Management.Automation.RemotingJob
        You can pipe a job object to Stop-Job.

OUTPUTS
    None or System.Management.Automation.RemotingJob
        When you use the PassThru parameter, Stop-Job returns a job object. Otherwise, this cmdlet does not generate any output.

NOTES

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

    C:\PS>$s = New-PSSession -computername Server01 -credential domain01\admin02

    C:\PS> $j = Invoke-Command -session $s -scriptblock {Start-Job -scriptblock {Get-Eventlog system}}

    C:\PS> Invoke-Command -session $s -scriptblock {param($j) Stop-Job -job $j} -ArgumentList $j

    Description
    ———–
    This example shows how to use the Stop-Job cmdlet to stop a job that is running on a remote computer.

    Because the job was started by using Invoke-Command to run a Start-Job command remotely, the job object is stored on the remote computer, and you must use another Invoke-Command command to run a Stop-Job command remotely. For more information about remote background jobs, see about_remote_Jobs.

    The first command creates a Windows PowerShell session (PSSession) on the Server01 computer and saves the session object in the $s Variable. The command uses the credentials of a domain administrator.

    The second command uses the Invoke-Command cmdlet to run a Start-Job command in the session. The command in the job gets all of the events in the System event log. The resulting job object is stored in the $j Variable.

    The third command stops the job. It uses the Invoke-Command cmdlet to run a Stop-Job command in the PSSession on Server01. Because the job objects are stored in $j, which is a Variable on the local computer, the command uses the “param” keyword to declare the local Variables in the command, and it uses the ArgumentList parameter to supply values for the Variables.

    When the command completes, the job is stopped and the PSSession in $s is available for use.

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

    C:\PS>Stop-Job -state failed

    Description
    ———–
    This command stops all jobs with a State value of “Failed”.

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

    C:\PS>Stop-Job -name job1

    Description
    ———–
    This command stops the Job1 background job.

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

    C:\PS>Stop-Job -Id 1, 3, 4

    Description
    ———–
    This command stops three jobs. It identifies them by their IDs.

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

    C:\PS>Get-Job | Stop-Job

    Description
    ———–
    This command stops all the background jobs in the current session.

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

    C:\PS>Stop-Job -state blocked

    Description
    ———–
    This command stops all the jobs with a job status of “Blocked”.

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

    C:\PS>Get-Job | Format-Table ID, Name, Command, @{Label=”State”;Expression={$_.jobstateinfo.state}}, I
    nstanceID -auto

    Id Name Command                 State InstanceId
    — —- ——-                 —– ———-
     1 Job1 Start-Service schedule Running 05abb67a-2932-4bd5-b331-c0254b8d9146
     3 Job3 Start-Service schedule Running c03cbd45-19f3-4558-ba94-ebe41b68ad03
     5 Job5 Get-Service s*         Blocked e3bbfed1-9c53-401a-a2c3-a8db34336adf

    C:\PS> Stop-Job -instanceid e3bbfed1-9c53-401a-a2c3-a8db34336adf

    Description
    ———–
    These commands show how to stop a job based on its instance ID.

    The first command uses a Get-Job command to get the jobs in the current session. The command uses a pipeline operator (|) to send the jobs to a Format-Table command, which displays a table of the specified properties of each job. The table includes the Instance ID of each job. It uses a calculated property to display the job state.

    The second command uses a Stop-Job command with the InstanceID parameter to stop a selected job.

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

    C:\PS>$j = Invoke-Command -computername Server01 -scriptblock {Get-Eventlog system} -asjob

    C:\PS> $j | Stop-Job -PassThru

    Id    Name    State     HasMoreData     Location         Command
    —    —-    —-     ———–     ——–         ——-
    5     Job5    Stopped    True            judithh-tablet Get-Eventlog system

    Description
    ———–
    This example shows how to use the Stop-Job cmdlet to stop a job that is running on a remote computer.

    Because the job was started by using the AsJob parameter of Invoke-Command, the job object is located on the local computer, even though the job runs on the remote computer. As such, you can use a local Stop-Job command to stop the job.

    The first command uses the Invoke-Command cmdlet to start a background job on the Server01 computer. The command uses the AsJob parameter to run the remote command as a background job.

    This command returns a job object, which is the same job object that Start-Job returns. The command saves the job object in the $j Variable.

    The second command uses a pipeline operator to send the job in the $j Variable to Stop-Job. The command uses the PassThru parameter to direct Stop-Job to return a job object. The job object display confirms that the State of the job is “Stopped”.

    For more information about remote background jobs, see about_remote_Jobs.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113413
    about_jobs
    about_job_details
    about_remote_Jobs
    Start-Job
    Get-Job
    Receive-Job
    Wait-Job
    Remove-Job
    Invoke-Command

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

Set-Item

NAME
    Set-Item

SYNOPSIS
    Changes the value of an item to the value specified in the command.

SYNTAX
    Set-Item [-LiteralPath] <string[]> [[-Value] <Object>] [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]

    Set-Item [-Path] <string[]> [[-Value] <Object>] [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]

DESCRIPTION
    The Set-Item cmdlet changes the value of an item, such as a Variable or Registry key, to the value specified in the command.

PARAMETERS
    -Credential <PSCredential>
        Specifies a user account that has permission to perform this action. The default is the current user.

        Type a user name, such as “User01” or “Domain01\User01”, or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.

        This parameter is not supported by any providers installed with Windows PowerShell.

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

    -Exclude <string[]>
        Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as “*.txt”. Wildcards are permitted.

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

    -Filter <string>
        Specifies a filter in the provider’s format or language. The value of this parameter qualifies the Path parameter. The syntax of the filter, including the use of wildcards, depends on the provider. Filters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having Windows PowerShell filter the objects after they are retrieved.

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

    -Force [<SwitchParameter>]
        Allows the cmdlet to set items that cannot otherwise be changed, such as read-only Alias or Variables. The cmdlet cannot change constant Aliases or Variables. Implementation varies from provider to provider. For more information, see about_providers. Even using the Force parameter, the cmdlet cannot override security restrictions.

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

    -Include <string[]>
        Changes only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as “*.txt”. Wildcards are permitted.

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

    -LiteralPath <string[]>
        Specifies a path to the location of the new items. Unlike Path, the value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.

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

    -PassThru [<SwitchParameter>]
        Passes an object representing the item to the pipeline. By default, this cmdlet does not generate any output.

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

    -Path <string[]>
        Specifies a path to the location of the new items. Wildcards are permitted.

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

    -Value <Object>
        Specifies a new value for the item.

        Required?                    false
        Position?                    2
        Default value
        Accept pipeline input?     true (ByValue, 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

    -UseTransaction [<SwitchParameter>]
        Includes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see about_transactions.

        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.Object
        You can pipe an object that represents the new value of the item to Set-Item.

OUTPUTS
    None or an object representing the new or changed item.
        When you use the Passthru parameter, Set-Item generates an object representing the item. Otherwise, this cmdlet does not generate any output.

NOTES

        You can also refer to Set-Item by its built-in Alias, “si”. For more information, see about_aliases.

        The Set-Item cmdlet is not supported by the Windows PowerShell FileSystem provider. To change the values of items in the file system, use Set-Content.

        In the Registry drives, HKLM: and HKCU:, Set-Item changes the data in the (Default) value of a Registry key. To create and change the names of Registry keys, use New-Item and Rename-Item. To change the names and data in Registry values, use New-ItemProperty, Set-ItemProperty, and Rename-ItemProperty.

        The Set-Item cmdlet is designed to work with the data exposed by any provider. To list the providers available in your session, type “Get-PSProvider“. For more information, see about_providers.

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

    C:\PS>Set-Item -Path Alias:np -Value c:\windows\notepad.exe

    Description
    ———–
    This command creates an Alias of “np” for Notepad.

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

    C:\PS>Set-Item -Path env:UserRole -Value Administrator

    Description
    ———–
    This command uses the Set-Item cmdlet to change the value of the “UserRole” Environment Variable to “Administrator”.

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

    C:\PS>Set-Item -Path Function:prompt -Value {‘PS ‘+ $(Get-Date -format t) + ” ” + $(Get-Location) + ‘> ‘}

    Description
    ———–
    This command uses the Set-Item cmdlet to change the “prompt” Function so that it displays the time before the path.

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

    C:\PS>Set-Item -Path Function:prompt -options “AllScope,ReadOnly”

    Description
    ———–
    This command sets the AllScope and ReadOnly options for the “prompt” Function. This command uses the Options dynamic parameter of the Set-Item cmdlet. The Options parameter is available in Set-Item only when you use it with the Alias or Function provider.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113395
    about_providers
    Get-Item
    New-Item
    Remove-Item
    Clear-Item
    Invoke-Item
    Rename-Item
    Move-Item
    Copy-Item

Set-ItemProperty

NAME
    Set-ItemProperty

SYNOPSIS
    Creates or changes the value of a property of an item.

SYNTAX
    Set-ItemProperty [-LiteralPath] <string[]> -InputObject <psobject> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]

    Set-ItemProperty [-Path] <string[]> -InputObject <psobject> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]

    Set-ItemProperty [-LiteralPath] <string[]> [-Name] <string> [-Value] <Object> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]

    Set-ItemProperty [-Path] <string[]> [-Name] <string> [-Value] <Object> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-PassThru] [-Confirm] [-WhatIf] [-UseTransaction] [<CommonParameters>]

DESCRIPTION
    The Set-ItemProperty cmdlet changes the value of the property of the specified item. You can use the cmdlet to establish or change the properties of items. For example, you can use Set-ItemProperty to set the value of the IsReadOnly property of a file object to true.

    You also use Set-ItemProperty to create and change Registry values and data. For example, you can add a new Registry entry to a key and establish or change its value.

PARAMETERS
    -Credential <PSCredential>
        Specifies a user account that has permission to perform this action. The default is the current user.

        Type a user name, such as “User01” or “Domain01\User01”, or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.

        This parameter is not supported by any providers installed with Windows PowerShell.

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

    -Exclude <string[]>
        Specifies those items upon which the cmdlet is not to act, and includes all others.

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

    -Filter <string>
        Specifies a filter in the provider’s format or language. The value of this parameter qualifies the Path parameter. The syntax of the filter, including the use of wildcards, depends on the provider. Filters are more efficient than other parameters, because the provider applies them when retrieving the objects rather than having Windows PowerShell filter the objects after they are retrieved.

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

    -Force [<SwitchParameter>]
        Allows the cmdlet to set a property on items that cannot otherwise be accessed by the user. Implementation varies from provider to provider. For more information, see about_providers.

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

    -Include <string[]>
        Specifies only those items upon which the cmdlet will act, excluding all others.

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

    -InputObject <psobject>
        Specifies the object that has the properties that you want to change. Enter a Variable that contains the object or a command that gets the object.

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

    -LiteralPath <string[]>
        Specifies a path to the item property. The value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.

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

    -Name <string>
        Specifies the name of the property.

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

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

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

    -Path <string[]>
        Specifies the path to the items with the property to be set.

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

    -Value <Object>
        Specifies the value of the property.

        Required?                    true
        Position?                    3
        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

    -UseTransaction [<SwitchParameter>]
        Includes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see about_transactions.

        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.Management.Automation.PSObject
        You can pipe objects to Set-ItemProperty.

OUTPUTS
    None or System.Management.Automation.PSCustomObject
        When you use the PassThru parameter, Set-ItemProperty generates a PSCustomObject object that represents the item that was changed and its new property value. Otherwise, this cmdlet does not generate any output.

NOTES

        The Set-ItemProperty cmdlet is designed to work with the data exposed by any provider. To list the providers available in your session, type “Get-PSProvider“. For more information, see about_providers.

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

    C:\PS>Set-Itemproperty -Path c:\GroupFiles\final.doc -Name IsReadOnly -Value $true

    Description
    ———–
    This command sets the value of the IsReadOnly property of the final.doc file to true.

    The command uses the Set-ItemProperty cmdlet to change the value of the property of the final.doc file. It uses the Path parameter to specify the file. It uses the Name parameter to specify the name of the property and the Value parameter to specify the new value.

    The $true automatic Variable represents a value of TRUE. For more information, see about_Automatic_Variables.

    The file is a System.IO.FileInfo object and IsReadOnly is just one of its properties. To see all of the properties and methods of a FileInfo object, pipe the file to the Get-Member cmdlet. For example, “final.doc | Get-Member“.

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

    C:\PS>Set-Itemproperty -Path HKLM:\Software\MyCompany -Name NoOfEmployees -Value 823

    C:\PS>Get-Itemproperty -Path HKLM:\Software\MyCompany

    PSPath        : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software\mycompany
    PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software
    PSChildName : mycompany
    PSDrive     : HKLM
    PSProvider    : Microsoft.PowerShell.Core\Registry
    NoOfLocations : 2
    NoOfEmployees : 823

    C:\PS>Set-Itemproperty -Path HKLM:\Software\MyCompany -Name NoOfEmployees -Value 824
    C:\PS>Get-Itemproperty -Path HKLM:\Software\MyCompany

    PSPath        : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software\mycompany
    PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software
    PSChildName : mycompany
    PSDrive     : HKLM
    PSProvider    : Microsoft.PowerShell.Core\Registry
    NoOfLocations : 2
    NoOfEmployees : 824

    Description
    ———–
    This example shows how to use Set-ItemProperty to create a new Registry entry and to assign a value to the entry. It creates the NoOfEmployees entry in the MyCompany key in HKLM\Software key and sets its value to 823.

    Because Registry entries are considered to be properties of the Registry keys (which are items), you use Set-ItemProperty to create Registry entries, and to establish and change their values.

    The first command uses the Set-ItemProperty cmdlet to create the Registry entry. It uses the Path parameter to specify the path to the HKLM: drive and the Software\MyCompany key. It uses the Name parameter to specify the entry name and the Value parameter to specify a value.

    The second command uses the Get-ItemProperty cmdlet to see the new Registry entry. If you use the Get-Item or Get-ChildItem cmdlets, the entries do not appear because they are properties of a key, not items or child items.

    The third command changes the value of the NoOfEmployees entry to 824.

    You can also use the New-ItemProperty cmdlet to create the Registry entry and its value and then use Set-ItemProperty to change the value.

    For more information about the HKLM: drive, type “Get-Help Get-PSDrive“. For more information about using Windows PowerShell to manage the Registry, type “Get-Help Registry“.

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

    C:\PS>Get-ChildItem weekly.txt | Set-Itemproperty -Name IsReadOnly -Value $true

    Description
    ———–
    These commands show how to use a pipeline operator (|) to send an item to Set-ItemProperty.

    The first part of the command uses the Get-ChildItem cmdlet to get an object that represents the Weekly.txt file. The command uses a pipeline operator to send the file object to Set-ItemProperty. The Set-ItemProperty command uses the Name and Value parameters to specify the property and its new value.

    This command is equivalent to using the InputObject parameter to specify the object that Get-ChildItem gets.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113396
    about_providers
    Get-ItemProperty
    New-ItemProperty
    Clear-ItemProperty
    Remove-ItemProperty
    Rename-ItemProperty
    Move-ItemProperty
    Copy-ItemProperty

Set-Location

NAME
    Set-Location

SYNOPSIS
    Sets the current working location to a specified location.

SYNTAX
    Set-Location [-LiteralPath] <string> [-PassThru] [-UseTransaction] [<CommonParameters>]

    Set-Location [[-Path] <string>] [-PassThru] [-UseTransaction] [<CommonParameters>]

    Set-Location [-StackName <string>] [-PassThru] [-UseTransaction] [<CommonParameters>]

DESCRIPTION
    The Set-Location cmdlet sets the working location to a specified location. That location could be a directory, a sub-directory, a Registry location, or another location stack.

PARAMETERS
    -LiteralPath <string>
        Specifies a path to the location. The value of the LiteralPath parameter is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.

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

    -PassThru [<SwitchParameter>]
        Passes an object representing the location to the pipeline. By default, this cmdlet does not generate any output.

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

    -Path <string>
        This parameter is used to specify the path to a new working location.

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

    -StackName <string>
        The name of the stack to which the location is being set.

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

    -UseTransaction [<SwitchParameter>]
        Includes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see about_transactions.

        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.String
        You can pipe a string that contains a path (but not a literal path) to Set-Location.

OUTPUTS
    None or System.Management.Automation.PathInfo
        When you use the PassThru parameter, Set-Location generates a System.Management.Automation.PathInfo object that represents the location. Otherwise, this cmdlet does not generate any output.

NOTES

        The Set-Location cmdlet is designed to work with the data exposed by any provider. To list the providers available in your session, type “Get-PSProvider“. For more information, see about_providers.

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

    C:\PS>Set-Location HKLM:

    Description
    ———–
    This will set the current location to the one specified; in this case, it is the HKLM provider.

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

    C:\PS>Set-Location env: -PassThru

    Path
    —-
    Env:\

    Description
    ———–
    This will set the current location to the one specified; in this case, it is the Environment Variable provider.

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

    C:\PS>Set-Location C:

    Description
    ———–
    This will set the current location to the one specified; in this case, it is the C: drive in the file system provider.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113397
    about_providers
    Get-Location
    Pop-Location
    Push-Location