en-US/about_Invoke-RestartService.help.txt
|
## about_Invoke-RestartService
### SHORT DESCRIPTION Restarts a named Windows service locally or on one or more remote computers. ### LONG DESCRIPTION Invoke-RestartService performs a controlled restart of a specific service using the shared Restart-ServiceWorker logic. It supports both local and remote execution, handling session management for remote targets automatically. #### Workflow Summary - Initializes TechToolbox runtime. - Iterates through each target in ComputerName. - Uses a local path for the current host/localhost. - Uses a remote PowerShell session path for non-local targets. - Calls Restart-ServiceWorker with ServiceName, TimeoutSeconds, and Force. - Cleans up remote sessions in finally blocks. - Logs per-target progress and errors via Write-Log. The function supports ShouldProcess (-WhatIf/-Confirm). When WhatIf or Confirm blocks an action, restart is skipped for that target. ### PARAMETERS #### -ServiceName Specifies the name of the Windows service to restart. This parameter is mandatory. Required? true Position? named Default value Accept pipeline input? false Accept wildcard characters? false #### -ComputerName Specifies one or more computer names to target. Defaults to the current computer ($env:COMPUTERNAME). Accepts values from pipeline input. Local targets include: - Current computer name ($env:COMPUTERNAME) - localhost Non-local targets are handled through Start-NewPSRemoteSession and Invoke-Command. Required? false Position? named Default value $env:COMPUTERNAME Accept pipeline input? true (ByValue) Accept wildcard characters? false #### -TimeoutSeconds Specifies the maximum number of seconds to wait for restart operations in the worker. Default is 30 seconds. Required? false Position? named Default value 30 Accept pipeline input? false Accept wildcard characters? false #### -Force Indicates that this cmdlet forces the operation without prompting for confirmation if not already specified by ShouldProcess. Required? false Position? named Default value False Accept pipeline input? false Accept wildcard characters? false #### -Credential Specifies a user account that has permission to perform this action. The default is the current user. Required? false Position? named Default value Accept pipeline input? false Accept wildcard characters? false ### INPUTS System.String (via ComputerName parameter) ### OUTPUTS None. Invoke-RestartService does not return any output objects. ### NOTES - The function relies on Restart-ServiceWorker for the actual restart logic. - Remote execution requires appropriate permissions and PowerShell remoting configuration. - Use -WhatIf to preview actions without executing them. - Use -Confirm to prompt for confirmation before restarting each service. ### EXAMPLE 1: Local Service Restart PS C:\> Invoke-RestartService -ServiceName "Spooler" This command restarts the Print Spooler service on the local computer. ### EXAMPLE 2: Remote Service Restart with Timeout PS C:\> Invoke-RestartService -ServiceName "WinRM" -ComputerName "Server01", "Server02" -TimeoutSeconds 60 This command restarts the WinRM service on Server01 and Server02, waiting up to 60 seconds for each. ### EXAMPLE 3: Forced Restart with Confirmation Prompt PS C:\> Invoke-RestartService -ServiceName "BITS" -Force This command forces a restart of the Background Intelligent Transfer Service without prompting for confirmation. |