Category Archives: Start

Start-Job

NAME
    Start-Job

SYNOPSIS
    Starts a Windows PowerShell background job.

SYNTAX
    Start-Job [-ScriptBlock] <scriptblock> [[-InitializationScript] <scriptblock>] [-ArgumentList <Object[]>] [-Authentication {Default | Basic | Negotiate | NegotiateWithImplicitCredential | Credssp | Digest | Kerberos}] [-Credential <PSCredential>] [-InputObject <psobject>] [-Name <string>] [-RunAs32] [<CommonParameters>]

    Start-Job [[-FilePath] <string>] [[-InitializationScript] <scriptblock>] [-ArgumentList <Object[]>] [-Authentication {Default | Basic | Negotiate | NegotiateWithImplicitCredential | Credssp | Digest | Kerberos}] [-Credential <PSCredential>] [-InputObject <psobject>] [-Name <string>] [-RunAs32] [<CommonParameters>]

DESCRIPTION
    The Start-Job cmdlet starts a Windows PowerShell background job on the local computer.

    A Windows PowerShell background job runs a command “in the background” without interacting with the current session. When you start a background job, a job object is returned immediately, even if the job takes an extended time to complete. You can continue to work in the session without interruption while the job runs.

    The job object contains useful information about the job, but it does not contain the job results. When the job completes, use the Receive-Job cmdlet to get the results of the job. For more information about background jobs, see about_jobs.

    To run a background job on a remote computer, use the AsJob parameter that is available on many cmdlets, or use the Invoke-Command cmdlet to run a Start-Job command on the remote computer. For more information, see about_remote_Jobs.

PARAMETERS
    -ArgumentList <Object[]>
        Specifies the arguments (parameter values) for the script that is specified by the FilePath parameter.

        Because all of the values that follow the ArgumentList parameter name are interpreted as being values of ArgumentList, the ArgumentList parameter should be the last parameter in the command.

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

    -Authentication <AuthenticationMechanism>
        Specifies the mechanism that is used to authenticate the user’s credentials. Valid values are Default, Basic, Credssp, Digest, Kerberos, Negotiate, and NegotiateWithImplicitCredential. The default value is Default.

        CredSSP authentication is available only in Windows Vista, Windows Server 2008, and later versions of Windows.

        For information about the values of this parameter, see the description of the System.Management.Automation.Runspaces.AuthenticationMechanism enumeration in MSDN.

        CAUTION: Credential Security Service Provider (CredSSP) authentication, in which the user’s credentials are passed to a remote computer to be authenticated, is designed for commands that require authentication on more than one resource, such as accessing a remote network share. This mechanism increases the security risk of the remote operation. If the remote computer is compromised, the credentials that are passed to it can be used to control the network session.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        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?                    named
        Default value                Current user
        Accept pipeline input?     false
        Accept wildcard characters? false

    -FilePath <string>
        Runs the specified local script as a background job. Enter the path and file name of the script or pipe a script path to Start-Job. The script must reside on the local computer or in a directory that the local computer can access.

        When you use this parameter, Windows PowerShell converts the contents of the specified script file to a script block and runs the script block as a background job.

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

    -InitializationScript <scriptblock>
        Specifies commands that run before the job starts. Enclose the commands in braces ( { } ) to create a script block.

        Use this parameter to prepare the session in which the job runs. For example, you can use it to add Functions, snap-ins, and modules to the session.

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

    -InputObject <psobject>
        Specifies input to the command. Enter a Variable that contains the objects, or type a command or expression that generates the objects.

        In the value of the ScriptBlock parameter, use the $input automatic Variable to represent the input objects.

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

    -Name <string>
        Specifies a friendly name for the new job. You can use the name to identify the job to other job cmdlets, such as Stop-Job.

        The default friendly name is Job#, where “#” is an ordinal number that is incremented for each job.

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

    -RunAs32 [<SwitchParameter>]
        Runs the job in a 32-bit process.

        Use this parameter to force the job to run in a 32-bit process on a 64-bit operating system.

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

    -ScriptBlock <scriptblock>
        Specifies the commands to run in the background job. Enclose the commands in braces ( { } ) to create a script block. This parameter is required.

        Required?                    true
        Position?                    1
        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 file path to Start-Job.

OUTPUTS
    System.Management.Automation.RemotingJob
        Start-Job returns an object that represents the job that it started.

NOTES

        To run in the background, Start-Job runs in its own session within the current session. When you use the Invoke-Command cmdlet to run a Start-Job command in a session on a remote computer, Start-Job runs in a session within the remote session.

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

    C:\PS>Start-Job -ScriptBlock {Get-Process}

    C:\PS> Start-Job -command “Get-Process

    Id    Name State    HasMoreData Location Command
    — —- —–    ———– ——– ——-
    1     Job1 Running True         localhost Get-Process

    Description
    ———–
    This command starts a background job that runs a Get-Process command. The command returns a job object with information about the job. The command prompt returns immediately so that you can work in the session while the job runs in the background.

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

    C:\PS>$jobWRM = Invoke-Command -computerName (Get-Content servers.txt) -ScriptBlock {Get-Service winrm} -jobname WinRM -throttlelimit 16 -AsJob

    Description
    ———–
    This command uses the Invoke-Command cmdlet and its AsJob parameter to start a background job that runs a “Get-Service winrm” command on numerous computers. Because the command is running on a server with substantial network traffic, the command uses the ThrottleLimit parameter of Invoke-Command to limit the number of concurrent commands to 16.

    The command uses the ComputerName parameter to specify the computers on which the job runs. The value of the ComputerName parameter is a Get-Content command that gets the text in the Servers.txt file, a file of computer names in a domain.

    The command uses the ScriptBlock parameter to specify the command and the JobName parameter to specify a friendly name for the job.

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

    C:\PS>$j = Start-Job -ScriptBlock {Get-Eventlog -log system} -Credential domain01\user01

    C:\PS> $j | Format-List -property *

    HasMoreData : True
    StatusMessage :
    Location     : localhost
    Command     : Get-Eventlog -log system
    JobStateInfo : Running
    Finished     : System.Threading.ManualResetEvent
    InstanceId    : 2d9d775f-63e0-4d48-b4bc-c05d0e177f34
    Id            : 1
    Name         : Job1
    ChildJobs     : {Job2}
    Output        : {}
    Error         : {}
    Progress     : {}
    Verbose     : {}
    Debug         : {}
    Warning     : {}
    StateChanged :

    C:\PS> $j.JobStateInfo.state
    Completed

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

    C:\PS> $results
    Index Time         Type        Source                EventID Message
    —– —-         —-        ——                ——- ——-
    84366 Feb 18 19:20 Information Service Control M…     7036 The description…
    84365 Feb 18 19:16 Information Service Control M…     7036 The description…
    84364 Feb 18 19:10 Information Service Control M…     7036 The description…
    …

    Description
    ———–
    These commands manage a background job that gets all of the events from the System log in Event Viewer. The job runs on the local computer.

    The first command uses the Start-Job cmdlet to start the job. It uses the Credential parameter to specify the user account of a user who has permission to run the job on the computer. Then it saves the job object that Start-Job returns in the $j Variable.

    At this point, you can resume your other work while the job completes.

    The second command uses a pipeline operator (|) to pass the job object in $j to the Format-List cmdlet. The Format-List command uses the Property parameter with a value of all (*) to display all of the properties of the job object in a list.

    The third command displays the value of the JobStateInfo property. This contains the status of the job.

    The fourth command uses the Receive-Job cmdlet to get the results of the job. It stores the results in the $results Variable.

    The final command displays the contents of the $results Variable.

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

    C:\PS>Start-Job -filepath c:\scripts\sample.ps1

    Description
    ———–
    This command runs the Sample.ps1 script as a background job.

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

    C:\PS>Start-Job -Name WinRm -ScriptBlock {Get-Process winrm}

    Description
    ———–
    This command runs a background job that gets the WinRM process on the local computer. The command uses the ScriptBlock parameter to specify the command that runs in the background job. It uses the Name parameter to specify a friendly name for the new job.

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

    C:\PS>Start-Job -Name GetMappingFiles -InitializationScript {Import-Module MapFunctions} -ScriptBlock {Get-Map -Name * | Set-Content D:\Maps.tif} -RunAs32

    Description
    ———–
    This command starts a job that collects a large amount of data and saves it in a .tif file. The command uses the InitializationScript parameter to run a script block that imports a required module. It also uses the RunAs32 parameter to run the job in a 32-bit process even if the computer has a 64-bit operating system.

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

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

Start-Sleep

NAME
    Start-Sleep

SYNOPSIS
    Suspends the activity in a script or session for the specified period of time.

SYNTAX
    Start-Sleep -Milliseconds <int> [<CommonParameters>]

    Start-Sleep [-Seconds] <int> [<CommonParameters>]

DESCRIPTION
    The Start-Sleep cmdlet suspends the activity in a script or session for the specified period of time. You can use it for many tasks, such as waiting for an operation to complete or pausing before repeating an operation.

PARAMETERS
    -Milliseconds <int>
        Specifies how long the resource sleeps in milliseconds. The parameter can be abbreviated as “-m”.

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

    -Seconds <int>
        Specifies how long the resource sleeps in seconds. You can omit the parameter name (“Seconds”), or you can abbreviate it as “-s”.

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

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

INPUTS
    System.Int32
        You can pipe the number of seconds to Start-Sleep.

OUTPUTS
    None
        This cmdlet does not return any output.

NOTES

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

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

    C:\PS>Start-Sleep -s 15

    Description
    ———–
    This command makes all commands in the session sleep for 15 seconds.

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

    C:\PS>Start-Sleep -m 500

    Description
    ———–
    This command makes all the commands in the session sleep for one-half of a second (500 milliseconds).

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113407

Start-Transaction

NAME
    Start-Transaction

SYNOPSIS
    Starts a transaction.

SYNTAX
    Start-Transaction [-Independent] [-RollbackPreference {Error | TerminatingError | Never}] [-Timeout <int>] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Start-Transaction cmdlet starts a transaction, which is a series of commands that are managed as a unit. A transaction can be completed (“committed”), or it can be completely undone (“rolled back”) so that any data changed by the transaction is restored to its original state. Because the commands in a transaction are managed as a unit, either all commands are committed or all commands are rolled back.

    By default, transactions are rolled back automatically if any command in the transaction generates an error, but you can use the RollbackPreference parameter to change this behavior.

    The cmdlets used in a transaction must be designed to support transactions. Cmdlets that support transactions have a UseTransaction parameter. To perform transactions in a provider, the provider must support transactions. The Windows PowerShell Registry provider in Windows Vista and later versions of Windows supports transactions. You can also use the Microsoft.PowerShell.Commands.Management.TransactedString class to include expressions in transactions on any version of Windows that supports Windows PowerShell. Other Windows PowerShell providers can also support transactions.

    Only one transaction can be active at a time. If you start a new, independent transaction while a transaction is in progress (neither completed nor undone), the new transaction becomes the active transaction, and you must commit or roll back the new transaction before making any changes to the original transaction.

    The Start-Transaction cmdlet is one of a set of cmdlets that support the transactions feature in Windows PowerShell. For more information, see about_transactions.

PARAMETERS
    -Independent [<SwitchParameter>]
        Starts a transaction that is independent of any transactions in progress. By default, if you use Start-Transaction while another transaction is in progress, a new subscriber is added to the transaction in progress. This parameter has an effect only when a transaction is already in progress in the session.

        By default, if you use Start-Transaction while a transaction is in progress, the existing transaction object is reused and the subscriber count is incremented. The effect is much like joining the original transaction. An Undo-Transaction command rolls back the entire the transaction. To complete the transaction, you must enter a Complete-Transaction command for each subscriber. Because most transactions that are in progress at the same time are related, the default is sufficient for most uses.

        If you use the Independent parameter, a new transaction is created that can be completed or undone without affecting the original transaction. However, because only one transaction can be active at a time, you must complete or roll back the new transaction before resuming work on the original transaction.

        Required?                    false
        Position?                    named
        Default value                Reuse the original transaction object.
        Accept pipeline input?     false
        Accept wildcard characters? false

    -RollbackPreference <RollbackSeverity>
        Specifies the conditions under which a transaction is automatically rolled back. The default value is “Error”.

        Valid values are:

        — Error: The transaction is rolled back automatically if a terminating or non-terminating error occurs. “Error” is the default.
        — Terminating error: The transaction is rolled back automatically if a terminating error occurs.
        — Never: The transaction is never rolled back automatically.

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

    -Timeout <int>
        Specifies the maximum time, in minutes, that the transaction is active. When the time-out expires, the transaction is automatically rolled back.

        By default, there is no time-out for transactions that are started at the command line. When transactions are started by a script, the default time-out is 30 minutes.

        Required?                    false
        Position?                    named
        Default value                No timeout (infinite)
        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
        This cmdlet does not generate any output.

NOTES

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

    C:\PS>cd hkcu:\software

    PS HKCU:\software> Start-Transaction

    PS HKCU:\software> New-Item MyCompany -UseTransaction

    PS HKCU:\software> New-Itemproperty MyCompany -name MyKey -value 123 -UseTransaction

    PS HKCU:\software> Undo-Transaction

    Description
    ———–
    These commands start and then roll back a transaction. Because the transaction is rolled back, no changes are made to the Registry.

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

    C:\PS>cd hkcu:\software

    PS HKCU:\software> Start-Transaction

    PS HKCU:\software> New-Item MyCompany -UseTransaction

    PS HKCU:\software> New-Itemproperty MyCompany -name MyKey -value 123 -UseTransaction

    PS HKCU:\software> Complete-Transaction

    Description
    ———–
    These commands start and then complete a transaction. No changes are made to the Registry until the Complete-Transaction command is used.

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

    C:\PS>cd HKCU:\software
    PS HKCU:\software> Start-Transaction
    PS HKCU:\software> New-Item -path NoPath -name MyCompany -UseTransaction
    PS HKCU:\software> New-Item -path . -name MyCompany -UseTransaction

    PS HKCU:\software> Start-Transaction -RollbackPreference never
    PS HKCU:\software> New-Item -path NoPath -name MyCompany -UseTransaction
    PS HKCU:\software> New-Item -path . -name MyCompany -UseTransaction

    # Start-Transaction (-RollbackPreference error)

    PS HKCU:\software> Start-Transaction
    PS HKCU:\software> New-Item -path NoPath -Name MyCompany -UseTransaction
    New-Item : The Registry key at the specified path does not exist.
    At line:1 char:9
    + New-Item <<<< -path NoPath -Name MyCompany -UseTransaction

    PS HKCU:\software> New-Item -path . -name MyCompany -UseTransaction
    New-Item : Cannot use transaction. The transaction has been rolled back or has timed out.
    At line:1 char:9
    + New-Item <<<< -path . -name MyCompany -UseTransaction

    # Start-Transaction (-RollbackPreference never)
    PS HKCU:\software> Start-Transaction -RollbackPreference never
    PS HKCU:\software> New-Item -path NoPath -name MyCompany -UseTransaction
    New-Item : The Registry key at the specified path does not exist.
    At line:1 char:9
    + New-Item <<<< -path NoPath -name MyCompany -UseTransaction

    PS HKCU:\software> New-Item -path . -name MyCompany -UseTransaction
     Hive: HKEY_CURRENT_USER\Software

    SKC VC Name                         Property
    — — —-                         ——–
     0 0 MyCompany                     {}

    PS HKCU:\Software> Complete-Transaction
    # Succeeds

    Description
    ———–
    This example demonstrates the effect of changing the RollbackPreference parameter value.

    In the first set of commands, the Start-Transaction command does not use the RollbackPreference parameter. As a result, the default value (“Error”) is used. When an error occurs in a transaction command (the specified path does not exist), the transaction is automatically rolled back.

    In the second set of commands, the Start-Transaction command uses the RollbackPreference parameter with a value of “Never”. As a result, when an error occurs in a transaction command, the transaction is still active and can be completed successfully.

    Because most transactions must be performed without error, the default value of the RollbackPreference parameter is typically preferred.

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

    C:\PS>cd HKCU:\software

    PS HKCU:\software> Start-Transaction
    PS HKCU:\software> New-Item MyCompany -UseTransaction

    PS HKCU:\software> Start-Transaction
    PS HKCU:\software> Get-Transaction
    PS HKCU:\software> New-Item MyCompany2 -UseTransaction

    PS HKCU:\software> Complete-Transaction
    PS HKCU:\software> Complete-Transaction

    PS HKCU:\Software> Get-Transaction

    RollbackPreference SubscriberCount Status
    —————— ————— ——
    Error                2                 Active

    Description
    ———–
    This example shows the effect of using the Start-Transaction command while a transaction is in progress. The effect is much like joining the transaction in progress.

    Although this is a simplified command, this scenario commonly occurs when the transaction involves running a script that includes a complete transaction.

    The first Start-Transaction command starts the transaction. The first New-Item command is part of the transaction.

    The second Start-Transaction command adds a new subscriber to the transaction. The Get-Transaction command now returns a transaction with a subscriber count of 2. The second New-Item command is part of the same transaction.

    No changes are made to the Registry until the entire transaction is completed. To complete the transaction, you must enter two Complete-Transaction commands, one for each subscriber. If you were to roll back the transaction at any point, the entire transaction would be rolled back for both subscribers.

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

    C:\PS>cd HKCU:\software
    PS HKCU:\software> Start-Transaction
    PS HKCU:\software> New-Item MyCompany -UseTransaction

    PS HKCU:\software> Start-Transaction -Independent
    PS HKCU:\software> Get-Transaction
    PS HKCU:\software> Undo-Transaction

    PS HKCU:\software> New-Itemproperty -path MyCompany -name MyKey -value 123 -UseTransaction
    PS HKCU:\software> Complete-Transaction
    PS HKCU:\software> dir my*

    PS HKCU:\Software> Get-Transaction

    RollbackPreference SubscriberCount Status
    —————— ————— ——
    Error                1                 Active

    PS HKCU:\software> Undo-Transaction
    PS HKCU:\software> New-Itemproperty -path MyCompany -name MyKey -value 123 -UseTransaction

    MyKey
    —–
    123

    PS HKCU:\software> Complete-Transaction
    PS HKCU:\software> dir my*

     Hive: HKEY_CURRENT_USER\Software

    SKC VC Name                         Property
    — — —-                         ——–
     0 1 MyCompany                     {MyKey}

    Description
    ———–
    This example shows the effect of using the Independent parameter of Start-Transaction to start a transaction while another transaction is in progress. In this case, the new transaction is rolled back without affecting the original transaction.

    Although the transactions are logically independent, because only one transaction can be active at a time, you must roll back or commit the newest transaction before resuming work on the original transaction.

    The first set of commands starts a transaction. The New-Item command is part of the first transaction.

    In the second set of commands, the Start-Transaction command uses the Independent parameter. The Get-Transaction command that follows shows the transaction object for the active transaction (the newest one). The subscriber count is equal to 1, showing that the transactions are unrelated.

    When the active transaction is rolled back by using an Undo-Transaction command, the original transaction becomes active again.

    The New-ItemProperty command, which is part of the original transaction, completes without error, and the original transaction can be completed by using the Complete-Transaction command. As a result, the Registry is changed.

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

    C:\PS>cd hkcu:\software

    PS HKCU:\software> Start-Transaction
    PS HKCU:\software> New-Item MyCompany1 -UseTransaction
    PS HKCU:\software> New-Item MyCompany2
    PS HKCU:\software> New-Item MyCompany3 -UseTransaction

    PS HKCU:\software> dir my*

    PS HKCU:\software> Complete-Transaction
    PS HKCU:\software> dir my*

    PS HKCU:\Software> dir my*

     Hive: HKEY_CURRENT_USER\Software

    SKC VC Name                         Property
    — — —-                         ——–
     0 0 MyCompany2                     {}

    PS HKCU:\Software> Complete-Transaction

    PS HKCU:\Software> dir my*

     Hive: HKEY_CURRENT_USER\Software

    SKC VC Name                         Property
    — — —-                         ——–
     0 0 MyCompany1                     {}
     0 0 MyCompany2                     {}
     0 0 MyCompany3                     {}

    Description
    ———–
    This example demonstrates that commands that are submitted while a transaction is in progress can be included in the transaction or not included. Only commands that use the UseTransaction parameter are part of the transaction.

    The first and third New-Item commands use the UseTransaction parameter. These commands are part of the transaction. Because the second New-Item command does not use the UseTransaction parameter, it is not part of the transaction.

    The first “dir” command shows the effect. The second New-Item command is completed immediately, but the first and third New-Item commands are not effective until the transaction is committed.

    The Complete-Transaction command commits the transaction. As a result, the second “dir” command shows that all of the new items are added to the Registry.

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

    C:\PS>Start-Transaction -Timeout 2

    # Wait two minutes…

    C:\PS> Get-Transaction

    C:\PS> New-Item HKCU:\Software\MyCompany -UseTransaction

    C:\PS> Start-Transaction -Timeout 2

    # Wait two minutes…

    C:\PS>> Get-Transaction

    RollbackPreference SubscriberCount Status
    —————— ————— ———–
    Error                1                 RolledBack

    C:\PS> New-Item HKCU:\Software\MyCompany -UseTransaction
    New-Item : Cannot use transaction. The transaction has been rolled back or has timed out.
    At line:1 char:9
    + New-Item <<<< MyCompany -UseTransaction

    Description
    ———–
    This command uses the Timeout parameter of Start-Transaction to start a transaction that must be completed within two minutes. If the transaction is not complete when the timeout expires, it is rolled back automatically.

    When the timeout expires, you are not notified, but the Status property of the transaction object is set to RolledBack and commands that use the UseTransaction parameter fail.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135262
    about_transactions
    Get-Transaction
    Complete-Transaction
    Undo-Transaction
    Use-Transaction

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