Streamlining Windows Services Management

Streamlining Windows Services Management: Share of a Handy PowerShell Script for Automatic Startup

Are you grappling with Windows services that refuse to start after a server reboot, despite their startup type being set to automatic? I personally encounter this issue frequently. For instance, every month when performing Windows patches and rebooting the server, users often complain about email disruptions or difficulty launching Citrix applications from StoreFront.

The root cause, in my case, lies in the Hypervisor disks experiencing high latency. With a server using the normal HDD and a heavy workload, it slows down all VMs, preventing services from starting promptly and resulting in user complaints.

While manually starting these services is possible, it becomes tedious and time-consuming to log in to each server individually. To streamline this process, I want to share a PowerShell script that automatically checks and starts services with automatic and delayed automatic startup types, eliminating the need for manual intervention.

Here's an overview of what the script accomplishes:

1. Log File Setup:

 

  • Defines a variable ($logFilePath) for the log file path (C:\PowerShell-Script-Logs\service_startup_log.txt).
  • Creates a log folder (C:\PowerShell-Script-Logs) if it doesn't exist.

2. Remote Signing Check and Configuration:

 

  • Examines the registry key HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell to check if remote signing is enabled.
  • If not enabled, sets the registry value ExecutionPolicyRemoteSigned to 1, enabling remote signing. Displays a message on the console.

3. Get Services with Specific Startup Types:

 

  • Retrieves a list of services using Get-Service and filters based on startup types ('Automatic' or 'AutomaticDelayedStart').

4. Start Services:

 

  • Iterates through the selected services, starting each service if not already running. Tracks the names of started services in the $startedServices array.

5. Logging:

 

  • Creates a log message with the current date and names of started services.
  • Appends this log message to the specified log file ($logFilePath).

6. Console Output:

  • Writes a message to the console indicating script execution completion and mentions the location of the log file.

7. Revert Remote Signing (if changed):

  • If the original state of remote signing was not enabled, reverts the ExecutionPolicyRemoteSigned registry value back to its original state (0) and writes a message to the console.

Feel free to use and modify this script if you face similar challenges.

Download it here: [Script Link]

B/streamliningwindows