This article explains how to use a PowerShell script to safely restore the Snow Update Service on a Windows server. The script includes robust error handling and safety checks to prevent accidental misconfiguration.
The PowerShell script deletes and recreates the Snow Update Service with proper validation and confirmation prompts. It ensures the service is restored correctly and runs under the LocalSystem account.
What the script does
- Accepts installation directory
- You can specify the installation directory for the service executable.
- Default:
C:\Program Files\Snow Software\Snow Update Service
- Checks for service existence
- If the service (SnowUpdateService) exists, the script manages it.
- If not, it prepares to create the service.
- Stops the service safely
- If the service is running, the script attempts to stop it.
- If the service is stuck in a “stop pending” state, it forcibly stops the process.
- Prompts for confirmation
- If the service exists, you must confirm whether to delete and recreate it.
- Validates executable path
- The script checks if the executable exists at the specified path.
- It halts execution if the path does not start with
C:\(for safety and consistency).. - Deletes and recreates the service
- If confirmed, the script deletes the existing service and creates a new one with the specified executable, display name, and automatic start.
- Sets service description
- Adds a description to the service for clarity.
- Error handling
- Errors are caught and displayed at every step, so you know exactly what went wrong if something fails.
Safety features
- The script will not proceed if the executable is missing or not on the
C:\drive. - It will not delete or recreate the service without explicit confirmation.
- It forcibly stops the service if it is stuck in a stopping state.
- Save the script as
Restore-SnowUpdateService.ps1. - Open PowerShell as Administrator.
- Run the script:
- For the default install location:
PowerShell
.\Restore-SnowUpdateService.ps1
- For a custom install location:
PowerShell
.\Restore-SnowUpdateService.ps1 -InstallDir "C:\Custom\Path\To\Snow Update Service"
- Follow prompts:
- Confirm whether to delete and recreate the service.
- If the executable path is not on
C:\, the script halts and displays an error.
Script
param(
[string]$InstallDir = "C:\Program Files\Snow Software\Snow Update Service"
)
$ServiceName = "SnowUpdateService"
$DisplayName = "Snow Update Service"
$Executable = "SnowSoftware.Update.Service.exe"
$ExePath = Join-Path $InstallDir $Executable
function Throw-IfFailed {
param (
[int]$ExitCode,
[string]$Action
)
if ($ExitCode -ne 0) {
throw "$Action failed with exit code $ExitCode."
}
}
try {
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if ($service) {
Write-Host "Service '$ServiceName' already exists."
# Attempt to stop the service if it's running
if ($service.Status -ne 'Stopped') {
Write-Host "Stopping service..."
try {
Stop-Service -Name $ServiceName -Force -ErrorAction Stop
Write-Host "Service stopped successfully."
} catch {
Write-Host "ERROR: Failed to stop service normally. Checking for 'stop pending' state..."
# Check for services stuck in 'stop pending'
$Services = Get-WmiObject -Class win32_service -Filter "state = 'stop pending'"
if ($Services) {
foreach ($svc in $Services) {
Write-Host "Force stopping process for service: $($svc.Name)"
try {
Stop-Process -Id $svc.processid -Force -PassThru -ErrorAction Stop
Write-Host "Process $($svc.processid) for service $($svc.Name) stopped."
}
catch {
Write-Warning -Message "Unexpected Error. Error details: $_.Exception.Message"
}
}
}
else {
Write-Output "There are currently no services with a status of 'Stopping'."
}
}
}
$confirm = Read-Host "Do you want to delete and recreate the service? (Y/N)"
if ($confirm -eq "Y") {
Write-Host "Deleting service..."
$deleteResult = sc.exe delete $ServiceName
Throw-IfFailed $LASTEXITCODE "Service deletion"
Start-Sleep -Seconds 2
Write-Host "Service deleted. Proceeding to recreate..."
} else {
Write-Host "Operation cancelled. Service was not recreated."
exit
}
}
if (!(Test-Path $ExePath)) {
throw "Executable not found at $ExePath. Please check the installation directory."
}
# Halt if the path does not start with C:\
if ($ExePath -notlike "C:\*") {
throw "ERROR: Executable path is not on C:\ drive: $ExePath. Operation halted."
}
Write-Host "Creating service..."
$createResult = sc.exe create $ServiceName binPath= "`"$ExePath`"" DisplayName= "`"$DisplayName`"" start= auto obj= "LocalSystem"
Throw-IfFailed $LASTEXITCODE "Service creation"
Write-Host "Setting service description..."
$descResult = sc.exe description $ServiceName "Automatically checks your installed Snow Software products and updates the software to the latest version available."
Throw-IfFailed $LASTEXITCODE "Setting service description"
Write-Host "Service '$DisplayName' restored with executable path: $ExePath"
}
catch {
Write-Host "ERROR: $_"
}Related Articles
PowerShell script to rebuild the Snow MongoDB Windows service 8Number of Views PowerShell script to delete the Snow MongoDB service 5Number of Views Snow Update Service fails to start with error 1053 (SUS fails to load or has stopped) 408Number of Views How To: Perform an Offline Update using Snow Update Service (SUS) 230Number of Views URLs used for the Snow Update Service 342Number of Views
Hi, I am Reva - Ask me anything.
No new updates
Thanks for the feedback!
Your feedback has been saved.Rate this response:
Add Additional feedback ( Optional )
Are you sure you want to cancel
the case creation?
Are you sure you want to cancel the case creation?
Are you sure you want to close this case
| Products | Region | Phone Numbers |
|---|---|---|
| FlexNet Operations FlexNet Embedded FlexNet Publisher FlexNet Connect FlexNet Code Insight InstallAnywhere InstallShield |
North America * |
+1 630-332-2513 (toll) +1 877-279-2853 (toll-free in North America) |
| Europe * |
+44 1925 944367 (toll) +44 800 047 8642 (toll-free in Europe) |
|
| Japan * | +81 3-4540-5335 (select option 2) | |
| Australia * |
+61 3 9895 2177 +61 1800 560 603 (toll-free in Australia) |
|
|
Usage Intelligence (formerly
Revulytics) Compliance Intelligence |
Please use the Case Portal to submit your support ticket or reach out to your Revenera contact. | |
Case id: 00001065
Activity: Status change: 2 hours ago