Tag Archives: Force

Trace-Command

NAME
    Trace-Command

SYNOPSIS
    Configures and starts a trace of the specified expression or command.

SYNTAX
    Trace-Command [-Command] <string> [-ArgumentList <Object[]>] [-Name] <string[]> [[-Option] {None | Constructor | Dispose | Finalizer | Method | Property | Delegates | Events | Exception | Lock | Error | Errors | Warning | Verbose | WriteLine | Data | Scope | ExecutionFlow | Assert | All}] [-Debugger] [-FilePath <string>] [-Force] [-InputObject <psobject>] [-ListenerOption {None | LogicalOperationStack | DateTime | Timestamp | ProcessId | ThreadId | Callstack}] [-PSHost] [<CommonParameters>]

    Trace-Command [-Expression] <scriptblock> [-Name] <string[]> [[-Option] {None | Constructor | Dispose | Finalizer | Method | Property | Delegates | Events | Exception | Lock | Error | Errors | Warning | Verbose | WriteLine | Data | Scope | ExecutionFlow | Assert | All}] [-Debugger] [-FilePath <string>] [-Force] [-InputObject <psobject>] [-ListenerOption {None | LogicalOperationStack | DateTime | Timestamp | ProcessId | ThreadId | Callstack}] [-PSHost] [<CommonParameters>]

DESCRIPTION
    The Trace-Command cmdlet configures and starts a trace of the specified expression or command. It works like Set-TraceSource, except that it applies only to the specified command.

PARAMETERS
    -ArgumentList <Object[]>
        Specifies the parameters and parameter values for the command being traced. The Alias for ArgumentList is Args. This feature is especially useful for debugging dynamic parameters.

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

    -Command <string>
        Specifies a command that is being processed during the trace.

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

    -Debugger [<SwitchParameter>]
        Sends the trace output to the debugger. You can view the output in any user-mode or kernel mode debugger or in Visual Studio. This parameter also selects the default trace listener.

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

    -Expression <scriptblock>
        Specifies the expression that is being processed during the trace. Enclose the expression in curly braces ({}).

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

    -FilePath <string>
        Sends the trace output to the specified file. This parameter also selects the file trace listener.

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

    -Force [<SwitchParameter>]
        Allows the cmdlet to append trace information to a read-only file. Used with the FilePath parameter. 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

    -InputObject <psobject>
        Provides input to the expression that is being processed during the trace.

        You can enter a Variable that represents the input that the expression accepts, or pass an object through the pipeline.

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

    -ListenerOption <TraceOptions>
        Adds optional data to the prefix of each trace message in the output. The valid values are None, LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, and Callstack. “None” is the default.

        To specify multiple options, separate them with commas, but with no spaces, and enclose them in quotation marks, such as “ProcessID,ThreadID”.

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

    -Name <string[]>
        Determines which Windows PowerShell components are traced. Enter the name of the trace source of each component. Wildcards are permitted. To find the trace sources on your computer, type “Get-TraceSource“.

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

    -Option <PSTraceSourceOptions>
        Determines the type of events that are traced.

        The valid values are None, Constructor, Dispose, Finalizer, Method, Property, Delegates, Events, Exception, Lock, Error, Errors, Warning, Verbose, WriteLine, Data, Scope, ExecutionFlow, Assert, and All. “All” is the default.

        The following values are combinations of other values:

        — ExecutionFlow: (Constructor, Dispose, Finalizer, Method, Delegates, Events, and Scope)

        — Data: (Constructor, Dispose, Finalizer, Property, Verbose, and WriteLine)

        — Errors: (Error and Exception).

        To specify multiple options, separate them with commas, but with no spaces, and enclose them in quotation marks, such as “Constructor,Dispose”.

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

    -PSHost [<SwitchParameter>]
        Sends the trace output to the Windows PowerShell host. This parameter also selects the PSHost trace listener.

        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 that represent input to the expression to Trace-Command.

OUTPUTS
    System.Management.Automation.PSObject
        Returns the command trace in the debug stream.

NOTES

        Tracing is a method that developers use to debug and refine programs. When tracing, the program generates detailed messages about each step in its internal processing.

        The Windows PowerShell tracing cmdlets are designed to help Windows PowerShell developers, but they are available to all users. They let you monitor nearly every aspect of the Functionality of the shell.

        To find the Windows PowerShell components that are enabled for tracing, type “Get-Help Get-TraceSource.”

        A “trace source” is the part of each Windows PowerShell component that manages tracing and generates trace messages for the component. To trace a component, you identify its trace source.

        A “trace listener” receives the output of the trace and displays it to the user. You can elect to send the trace data to a user-mode or kernel-mode debugger, to the host or console, to a file, or to a custom listener derived from the System.Diagnostics.TraceListener class.

        When you use the Command parameter set, Windows PowerShell processes the command just as it would be processed in a pipeline. For example, command discovery is not repeated for each incoming object.

        The names of the Name, Expression, Option, and Command parameters are optional. If you omit the parameter names, the unnamed parameter values must appear in this order: Name, Expression, Option or Name, Command,-Option . If you include the parameter names, the parameters can appear in any order.

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

    C:\PS>Trace-Command -Name metadata,parameterbinding,cmdlet -Expression {Get-Process notepad} -PSHost

    Description
    ———–
    This command starts a trace of metadata processing, parameter binding, and cmdlet creation and destruction of the “Get-Process notepad” expression. It uses the Name parameter to specify the trace sources, the Expression parameter to specify the command, and the PSHost parameter to send the output to the console. Because it does not specify any tracing options or listener options, the command uses the defaults, “All” for the tracing options, and “None” for the listener options.

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

    C:\PS>Trace-Command -Name commandprocessor,pipelineprocessor -command Get-Alias -argumentlist “ghy” -Option executionflow -ListenerOption “timestamp,callstack” -FilePath c:\test\debug.txt

    Description
    ———–
    This command starts a trace of the command processor and pipeline processor while processing the “Get-Alias cd” command.

    It uses the Name parameter to specify the trace sources, the Command parameter to specify the command, the ArgumentList parameter to specify the parameters of the Get-Alias command, the Option parameter to specify tracing options, and the ListenerOption parameter to specify the fields in the trace message prefix. The FilePath parameter sends the output to the C:\Test\Debug.txt file.

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

    C:\PS>$a = “i*”

    C:\PS> Trace-Command parameterbinding {Get-Alias $input} -PSHost -InputObject $a

    Description
    ———–
    These commands trace the actions of the ParameterBinding operations of Windows PowerShell while it processes a Get-Alias expression that takes input from the pipeline.

    In Trace-Command, the InputObject parameter passes an object to the expression that is being processed during the trace.

    The first command stores the string “i*” in the $a Variable. The second command uses the Trace-Command cmdlet with the ParameterBinding trace source. The PSHost parameter sends the output to the console.

    The expression being processed is “Get-Alias $input”, where the $input Variable is associated with the InputObject parameter. The InputObject parameter passes the Variable $a to the expression. In effect, the command being processed during the trace is “Get-Alias -InputObject $a” or “$a | Get-Alias“.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113419
    Get-TraceSource
    Set-TraceSource

Unregister-Event

NAME
    Unregister-Event

SYNOPSIS
    Cancels an event subscription.

SYNTAX
    Unregister-Event [-SubscriptionId] <int> [-Force] [-Confirm] [-WhatIf] [<CommonParameters>]

    Unregister-Event [-SourceIdentifier] <string> [-Force] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Unregister-Event cmdlet cancels an event subscription that was created by using the Register-EngineEvent, Register-ObjectEvent, or Register-WmiEvent cmdlet.

    When an event subscription is canceled, the event subscriber is deleted from the session and the subscribed events are no longer added to the event queue. When you cancel a subscription to an event created by using the New-Event cmdlet, the new event is also deleted from the session.

    Unregister-Event does not delete events from the event queue. To delete events, use the Remove-Event cmdlet.

PARAMETERS
    -Force [<SwitchParameter>]
        Cancels all event subscriptions, including subscriptions that were hidden by using the SupportEvent parameter of Register-ObjectEvent, Register-WmiEvent, and Register-EngineEvent.

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

    -SourceIdentifier <string>
        Cancels event subscriptions that have the specified source identifier.

        A SourceIdentifier or SubscriptionId parameter must be included in every command.

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

    -SubscriptionId <int>
        Cancels event subscriptions that have the specified subscription identifier.

        A SourceIdentifier or SubscriptionId parameter must be included in every command.

        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.Management.Automation.PSEventSubscriber
        You can pipe the output from Get-EventSubscriber to Unregister-Event.

OUTPUTS
    None
        This cmdlet does not return any output.

NOTES

        Events, event subscriptions, and the event queue exist only in the current session. If you close the current session, the event queue is discarded and the event subscription is canceled.

        Unregister-Event cannot delete events created by using the New-Event cmdlet unless you have subscribed to the event by using the Register-EngineEvent cmdlet. To delete a custom event from the session, you must remove it programmatically or close the session.

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

    C:\PS>Unregister-Event -SourceIdentifier ProcessStarted

    Description
    ———–
    This command cancels the event subscription that has a source identifier of “ProcessStarted”.

    To find the source identifier of an event, use the Get-Event cmdlet. To find the source identifier of an event subscription, use the Get-EventSubscriber cmdlet.

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

    C:\PS>Unregister-Event -subscriptionId 2

    Description
    ———–
    This command cancels the event subscription that has a subscription identifier of 2.

    To find the subscription identifier of an event subscription, use the Get-EventSubscriber cmdlet.

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

    C:\PS>Get-Eventsubscriber -Force | Unregister-Event -Force

    Description
    ———–
    This command cancels all event subscriptions in the session.

    The command uses the Get-EventSubscriber cmdlet to get all event subscriber objects in the session, including the subscribers that are hidden by using the SupportEvent parameter of the event registration cmdlets.

    It uses a pipeline operator (|) to send the subscriber objects to Unregister-Event, which deletes them from the session. To complete the task, the Force parameter is also required on Unregister-Event.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135269
    Register-ObjectEvent
    Register-EngineEvent
    Register-WmiEvent
    Unregister-Event
    Get-Event
    New-Event
    Remove-Event
    Wait-Event
    Get-EventSubscriber

Unregister-PSSessionConfiguration

NAME
    Unregister-PSSessionConfiguration

SYNOPSIS
    Deletes registered session configurations from the computer.

SYNTAX
    Unregister-PSSessionConfiguration [-Name] <string> [-Force] [-NoServiceRestart] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Unregister-PSSessionConfiguration cmdlet deletes registered session configurations from the computer. This is an advanced cmdlet that is designed to be used by system administrators to manage customized session configurations for their users.

    If you accidentally delete the default Microsoft.PowerShell or Microsoft.PowerShell32 session configurations, use the Enable-PSRemoting cmdlet to restore them.

PARAMETERS
    -Force [<SwitchParameter>]
        Suppresses all user prompts, and restarts the WinRM service without prompting. Restarting the service makes the configuration change effective.

        To prevent a restart and suppress the restart prompt, use the NoServiceRestart parameter.

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

    -Name <string>
        Specifies the names of session configurations to delete. Enter one or more configuration names. Wildcards are permitted. This parameter is required.

        You can also pipe a session configuration object to Unregister-PSSessionConfiguration.

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

    -NoServiceRestart [<SwitchParameter>]
        Does not restart the WinRM service, and suppresses the prompt to restart the service.

        By default, when you enter an Unregister-PSSessionConfiguration command, you are prompted to restart the WinRM service to make the change effective. Until the WinRM service is restarted, users can still use the unregistered session configuration, even though Get-PSSessionConfiguration does not find it.

        To restart the WinRM service without prompting, use the Force parameter. To restart the WinRM service manually, use the Restart-Service cmdlet.

        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
    Microsoft.PowerShell.Commands.PSSessionConfigurationCommands#PSSessionConfiguration
        You can pipe a session configuration object from Get-PSSessionConfiguration to Unregister-PSSessionConfiguration.

OUTPUTS
    None
        This cmdlet does not return any objects.

NOTES

        To run this cmdlet on Windows Vista, Windows Server 2008, and later versions of Windows, you must start Windows PowerShell with the “Run as administrator” option.

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

    C:\PS>Unregister-PSSessionConfiguration -Name MaintenanceShell

    Description
    ———–
    This command deletes the MaintenanceShell session configuration from the computer.

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

    C:\PS>Unregister-PSSessionConfiguration -maintenanceShell -Force

    Description
    ———–
    This command deletes the MaintenanceShell session configuration from the computer. The command uses the Force parameter to suppress all user messages and to restart the WinRM service without prompting.

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

    C:\PS>Unregister-PSSessionConfiguration -Name *

    C:\PS> Get-PSSessionConfiguration -Name * | Unregister-PSSessionConfiguration

    Description
    ———–
    These commands delete all of the session configurations on the computer. The commands have the same effect and can be used interchangeably.

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

    C:\PS>Unregister-PSSessionConfiguration -Name maintenanceShell -NoServiceRestart

    C:\PS> Get-PSSessionConfiguration -Name maintenanceShell

    Get-PSSessionConfiguration -Name maintenanceShell : No Session Configuration matches criteria “maintenanceShell”.
        + CategoryInfo         : NotSpecified: (:) [Write-Error], WriteErrorException
        + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException

    C:\PS> New-PSSession -configurationName MaintenanceShell

     Id Name     ComputerName    State    Configuration         Availability
     — —-     ————    —–    ————-         ————
     1 Session1 localhost     Opened MaintenanceShell     Available

    C:\PS> Restart-Service winrm

    C:\PS> New-PSSession -configurationName MaintenanceShell
    [localhost] Connecting to remote server failed with the following error message : The WS-Management service cannot process the request. The resource
    URI (http://schemas.microsoft.com/powershell/MaintenanceShell) was not found in the WS-Management catalog. The catalog contains the metadata that describes resour
    ces, or logical endpoints. For more information, see the about_remote_TroubleShooting Help topic.
        + CategoryInfo         : OpenError: (System.Manageme….RemoteRunspace:RemoteRunspace) [], PSRemotingTransportException
        + FullyQualifiedErrorId : PSSessionOpenFailed

    Description
    ———–
    This example shows the effect of using the NoServiceRestart parameter of Unregister-PSSessionConfiguration. This parameter is designed to prevent a service restart, which would disrupt any sessions on the computer.

    The first command uses the Unregister-PSSessionConfiguration cmdlet to deletes the MaintenanceShell session configuration. However, because the command uses the NoServiceRestart parameter, the WinRM service is not restarted and the change is not yet completely effective.

    The second command uses the Get-PSSessionConfiguration cmdlet to get the MaintenanceShell session. Because the session has been removed from the WS-Management resource table, Get-PSSession cannot return it.

    The third command uses the New-PSSession cmdlet to create a session on the local computer that uses the MaintenanceShell configuration. The command succeeds.

    The fourth command uses the Restart-Service cmdlet to restart the WinRM service.

    The fifth command again uses the New-PSSession cmdlet to create a session that uses the MaintenanceShell configuration. This time, the session fails because the MaintenanceShell configuration has been deleted.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=144308
    about_Session_Configurations
    Disable-PSSessionConfiguration
    Enable-PSSessionConfiguration
    Get-PSSessionConfiguration
    Register-PSSessionConfiguration
    Set-PSSessionConfiguration
    WS-Management Provider

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

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

Set-WSManQuickConfig

NAME
    Set-WSManQuickConfig

SYNOPSIS
    Configures the local computer for remote management.

SYNTAX
    Set-WSManQuickConfig [-UseSSL] [<CommonParameters>]

DESCRIPTION
    The Set-WSManQuickConfig cmdlet configures the computer to receive Windows PowerShell remote commands that are sent by using the Web Services for Management (WS-Management) technology.

    The cmdlet performs the following:
    1. Checks whether the WinRM service is running. If the WinRM service is not running, the service is started.
    2. Sets the WinRM service startup type to automatic.
    3. Creates a listener to accept requests on any IP address. By default, the transport is HTTP.
    4. Enables a firewall exception for WinRM traffic .

    To run this cmdlet in Windows Vista, Windows Server 2008, and later versions of Windows, you must start Windows PowerShell with the “Run as administrator” option.

PARAMETERS
    -UseSSL [<SwitchParameter>]
        Specifies that the Secure Sockets Layer (SSL) protocol should be used to establish a connnection to the remote computer. By default, SSL is not used.

        WS-Management encrypts all Windows PowerShell content transmitted over the network. The UseSSL parameter lets you specify that the additional protection of using HTTPS instead of HTTP should be used. If you specify this parameter, but SSL is not available on the port used for the connection, the command fails.

        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
    None
        This cmdlet does not accept any input.

OUTPUTS
    None
        This cmdlet does not generate any output.

NOTES

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

    C:\PS>Set-WSManQuickConfig

    Description
    ———–
    This command sets the required configuration to enable remote management of the local computer. By default, this command creates a WS-Management listener on HTTP.

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

    C:\PS>Set-WSManQuickConfig -UseSSL

    Description
    ———–
    The command sets the required configuration to enable remote management of the local computer. The UseSSL parameter makes the command create a WS-Management listener on HTTPS.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=141463
    Connect-WSMan
    Disable-WSManCredSSP
    Disconnect-WSMan
    Enable-PSRemoting
    Enable-WSManCredSSP
    Get-WSManCredSSP
    Get-WSManInstance
    Invoke-WSManAction
    New-PSSession
    New-WSManInstance
    New-WSManSessionOption
    Test-WSMan

Start-Transcript

NAME
    Start-Transcript

SYNOPSIS
    Creates a record of all or part of a Windows PowerShell session in a text file.

SYNTAX
    Start-Transcript [[-Path] <string>] [-Append] [-Force] [-NoClobber] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Start-Transcript cmdlet creates a record of all or part of a Windows PowerShell session in a text file. The transcript includes all command that the user types and all output that appears on the console.

PARAMETERS
    -Append [<SwitchParameter>]
        Adds the new transcript to the end of an existing file. Use the Path parameter to specify the file.

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

    -Force [<SwitchParameter>]
        Allows the cmdlet to append the transcript to an existing read-only file. When used on a read-only file, the cmdlet changes the file permission to read-write. 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

    -NoClobber [<SwitchParameter>]
        Will not overwrite (replace the contents) of an existing file. By default, if a transcript file exists in the specified path, Start-Transcript overwrites the file without warning.

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

    -Path <string>
        Specifies a location for the transcript file. Enter a path to a .txt file. Wildcards are not permitted.

        If you do not specify a path, Start-Transcript uses the path in the value of the $Transcript global Variable. If you have not created this Variable, Start-Transcript stores the transcripts in the $Home\My Documents directory as \PowerShell_transcript.<time-stamp>.txt files.

        If any of the directories in the path do not exist, the command fails.

        Required?                    false
        Position?                    1
        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
    None
        You cannot pipe objects to this cmdlet.

OUTPUTS
    System.String
        Start-Transcript returns a string that contains a confirmation message and the path to the output file.

NOTES

        To stop a transcript, use the Stop-Transcript cmdlet.

        To record an entire session, add the Start-Transcript command to your profile. For more information, see about_profiles.

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

    C:\PS>Start-Transcript

    Description
    ———–
    This command starts a transcript in the default file location.

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

    C:\PS>Start-Transcript -Path c:\transcripts\transcript0.txt -NoClobber

    Description
    ———–
    This command starts a transcript in the Transcript0.txt file in C:\transcripts. The NoClobber parameter prevents any existing files from being overwritten. If the Transcript0.txt file already exists, the command fails.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113408
    Stop-Transcript

Stop-Computer

NAME
    Stop-Computer

SYNOPSIS
    Stops (shuts down) local and remote computers.

SYNTAX
    Stop-Computer [[-ComputerName] <string[]>] [[-Credential] <PSCredential>] [-AsJob] [-Authentication {Default | None | Connect | Call | Packet | PacketIntegrity | PacketPrivacy | Unchanged}] [-Force] [-Impersonation {Default | Anonymous | Identify | Impersonate | Delegate}] [-ThrottleLimit <int>] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Stop-Computer cmdlet shuts down computers remotely. It can also shut down the local computer.

    You can use the parameters of Stop-Computer to run the shutdown operations as a background job, to specify the authentication levels and alternate credentials, to limit the concurrent connections that are created to run the command, and to force an immediate shut down.

    This cmdlet does not require Windows PowerShell remoting unless you use the AsJob parameter.

PARAMETERS
    -AsJob [<SwitchParameter>]
        Runs the command as a background job.

        Note: To use this parameter, the local and remote computers must be configured for remoting and, on Windows Vista and later versions of Windows, you must open Windows PowerShell with the “Run as administrator” option. For more information, see about_remote_requirements“.

        When you use the AsJob parameter, the command immediately returns an object that represents the background job. You can continue to work in the session while the job completes. The job is created on the local computer and the results from remote computers are automatically returned to the local computer. To manage the job, use the Job cmdlets. To get the job results, use the Receive-Job cmdlet.

        For more information about Windows PowerShell background jobs, see about_jobs and see about_remote_Jobs.

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

    -Authentication <AuthenticationLevel>
        Specifies the authentication level that is used for the WMI connection. (Stop-Computer uses WMI.) The default value is Packet.

        Valid values are:

        Unchanged:     The authentication level is the same as the previous command.
        Default:         Windows Authentication.
        None:            No COM authentication.
        Connect:         Connect-level COM authentication.
        Call:            Call-level COM authentication.
        Packet:         Packet-level COM authentication.
        PacketIntegrity: Packet Integrity-level COM authentication.
        PacketPrivacy: Packet Privacy-level COM authentication.

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

    -ComputerName <string[]>
        Stops the specified computers. The default is the local computer.

        Type the NETBIOS name, IP address, or fully qualified domain name of one or more computers in a comma-separated list. To specify the local computer, type the computername or “localhost”.

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

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

    -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 from the Get-Credential cmdlet.

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

    -Force [<SwitchParameter>]
        Forces an immediate shut down of the computers.

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

    -Impersonation <ImpersonationLevel>
        Specifies the impersonation level to use when calling WMI. (Stop-Computer uses WMI.) The default value is “Impersonate”.

        Valid values are:

        Default:     Default impersonation.
        Anonymous:    Hides the identity of the caller.
        Identify:     Allows objects to query the credentials of the caller.
        Impersonate: Allows objects to use the credentials of the caller.

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

    -ThrottleLimit <int>
        Specifies the maximum number of concurrent connections that can be established to run this command. If you omit this parameter or enter a value of 0, the default value, 32, is used.

        The throttle limit applies only to the current command, not to the session or to the computer.

        Required?                    false
        Position?                    named
        Default value                32
        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
    None
        You cannot pipe input to this cmdlet.

OUTPUTS
    None or System.Management.Automation.RemotingJob
        When you use the AsJob parameter, the cmdlet returns a job object (System.Management.Automation.RemotingJob). Otherwise, it does not generate any output.

NOTES

        This cmdlet uses the Win32Shutdown method of the Win32_OperatingSystem WMI class.

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

    C:\PS>Stop-Computer

    Description
    ———–
    This command shuts down the local computer.

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

    C:\PS>Stop-Computer -ComputerName Server01, Server02, localhost

    Description
    ———–
    This command stops two remote computers, Server01 and Server02, and the local computer, identified as “localhost”.

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

    C:\PS>$j = Stop-Computer -ComputerName Server01, Server02 -AsJob

    C:\PS> $results = $j | Receive-Job

    C:\PS> $results

    Description
    ———–
    These commands run a Stop-Computer command as a background job on two remote computers, and then get the results.

    The first command uses the AsJob parameter to run the command as a background job. The command saves the resulting job object in the $j Variable.

    The second command uses a pipeline operator to send the job object in $j to the Receive-Job cmdlet, which gets the job results. The command saves the results in the $results Variable.

    The third command displays the result saved in the $results Variable.

    Because the AsJob parameter creates the job on the local computer and automatically returns the results to the local computer, you can run the Receive-Job command as a local command.

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

    C:\PS>Stop-Computer -comp Server01 -Impersonation anonymous -Authentication PacketIntegrity

    Description
    ———–
    This command restarts the Server01 remote computer. The command uses customized impersonation and authentication settings.

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

    C:\PS>$s = Get-Content domain01.txt

    C:\PS> $c = Get-Credential domain01\admin01

    C:\PS> Stop-Computer -ComputerName $s -Force -ThrottleLimit 10 -Credential $c

    Description
    ———–
    These commands force an immediate shut down of all of the computers in Domain01.

    The first command gets a list of computers in the domain and saves it in the $s Variable.

    The second command gets the credentials of a domain administrator and saves them in the $c Variable.

    The third command shuts down the computers. It uses ComputerName parameter to submit the list of computers in the $s Variable, the Force parameter to force an immediate shutdown, and the Credential parameter to submit the credentials saved in the $c Variable. It also uses the ThrottleLimit parameter to limit the command to 10 concurrent connections.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135263
    Add-Computer
    Checkpoint-Computer
    Remove-Computer
    Restart-Computer
    Restore-Computer
    Test-Connection

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-Alias

NAME
    Set-Alias

SYNOPSIS
    Creates or changes an Alias (alternate name) for a cmdlet or other command element in the current Windows PowerShell session.

SYNTAX
    Set-Alias [-Name] <string> [-Value] <string> [-Description <string>] [-Force] [-Option {None | ReadOnly | Constant | Private | AllScope}] [-PassThru] [-Scope <string>] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Set-Alias cmdlet creates or changes an Alias (alternate name) for a cmdlet or for a command element, such as a Function, a script, a file, or other executable. You can also use Set-Alias to reassign a current Alias to a new command, or to change any of the properties of an Alias, such as its description. Unless you add the Alias to the Windows PowerShell profile, the changes to an Alias are lost when you exit the session or close Windows PowerShell.

PARAMETERS
    -Description <string>
        Specifies a description of the Alias. You can type any string. If the description includes spaces, enclose it quotation marks.

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

    -Force [<SwitchParameter>]
        Allows the cmdlet to set a read-only Alias. Use the Option parameter to create a read-only Alias. The Force parameter cannot set a constant Alias.

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

    -Name <string>
        Specifies the new Alias. You can use any alphanumeric characters in an Alias, but the first character cannot be a number.

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

    -Option <ScopedItemOptions>
        Sets the value of the Options property of the Alias.

        Valid values are:

        — None: Sets no options. (default)

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

        — Constant: The Alias 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 Alias to Constant.

        — Private: The Alias is available only within the scope specified by the Scope parameter. It is invisible in all other scopes.

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

        To see the Options property of the Aliases, type “Get-Alias | Format-Table -property Name, Definition, Options -autosize”.

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

    -PassThru [<SwitchParameter>]
        Returns an object representing the Alias. 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>
        Specifies the scope in which this Alias is valid. 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 <string>
        Specifies the name of the cmdlet or command element that is being Aliased.

        Required?                    true
        Position?                    2
        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
    None
        You cannot pipe input to this cmdlet.

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

NOTES

        An Alias is an alternate name or nickname for a cmdlet or command element. To run the cmdlet, you can use its full name or any valid Alias. For more information, see about_aliases.

        To create a new Alias, use Set-Alias or New-Alias. To delete an Alias, use Remove-Item.

        A cmdlet can have multiple Aliases, but an Alias can only be associated with one cmdlet at a time. If you use Set-Alias to associate the Alias with a different cmdlet, it is no longer associated with the original cmdlet.

        You can create an Alias for a cmdlet, but you cannot create an Alias for a command with parameters and values. For example, you can create an Alias for Set-Location, but you cannot create an Alias for “Set-Location C:\Windows\System32″. To create an Alias for a command, create a Function that includes the command, and then create an Alias to the Function.

        To save the Aliases from a session and use them in a different session, add the Set-Alias command to your Windows PowerShell profile. Profiles do not exist by default. To create a profile in the path stored in the $profile Variable, type “New-Item -type file -Force $profile”. To see the value of the $profile Variable, type “$profile”.

        You can also save your Aliases by using Export-Alias to copy the Aliases from the session to a file, and then use Import-Alias to add them to the Alias list for a new session.

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

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

    C:\PS>Set-Alias -Name list -Value Get-ChildItem

    Description
    ———–
    This command creates the Alias “list” for the Get-ChildItem cmdlet. After you create the Alias, you can use “list” in place of “Get-ChildItem” at the command line and in scripts.

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

    C:\PS>Set-Alias list Get-Location

    Description
    ———–
    This command associates the Alias “list” with the Get-Location cmdlet. If “list” is an Alias for another cmdlet, this command changes its association so that it now is the Alias only for Get-Location.

    This command uses the same format as the command in the previous example, but it omits the optional parameter names, -Name and -Value. When you omit parameter names, the values of those parameters must appear in the specified order in the command. In this case, the value of -Name (“list”) must be the first parameter and the value of -Value (“Get-Location“) must be the second parameter.

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

    C:\PS>Set-Alias scrub Remove-Item -Option readonly -PassThru | Format-List

    Description
    ———–
    This command associates the Alias “scrub” with the Remove-Item cmdlet. It uses the “ReadOnly” option to prevent the Alias from being deleted or assigned to another cmdlet.

    The PassThru parameter directs Windows PowerShell to pass an object that represents the new Alias through the pipeline to the Format-List cmdlet. If the PassThru parameter were omitted, there would be no output from this cmdlet to display (in a list or otherwise).

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

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

    Description
    ———–
    This command associates the Alias, “np”, with the executable file for Notepad. After the command completes, to open Notepad from the Windows PowerShell command line, just type “np”.

    This example demonstrates that you can create Aliases for executable files and elements other than cmdlets.

    To make the command more generic, you can use the “Windir” Environment Variable (${env:windir}) to represent the C\Windows directory. The generic version of the command is “Set-Alias np ${env:windir}\notepad.exe”.

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

    C:\PS>function CD32 {Set-Location c:\windows\system32}

    C:\PS>Set-Alias go cd32

    Description
    ———–
    These commands show how to assign an Alias to a command with parameters, or even to a pipeline of many commands.

    You can create an Alias for a cmdlet, but you cannot create an Alias for a command that consists of a cmdlet and its parameters. However, if you place the command in a Function or a script, then you can create a useful Function or script name and you can create one or more Aliases for the Function or script.

    In this example, the user wants to create an Alias for the command “Set-Location c:\windows\system32″, where “Set-Location” is a cmdlet and “C:\Windows\System32” is the value of the Path parameter.

    To do this, the first command creates a Function called “CD32” that contains the Set-Location command.

    The second command creates the Alias “go” for the CD32 Function. Then, to run the Set-Location command, the user can type either “CD32” or “go”.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113390
    Get-Alias
    New-Alias
    Export-Alias
    Import-Alias