A PowerShell script that switches between different installed versions of a Windows service by renaming folders and restarting the service.
This script allows you to quickly switch between major versions of a service installed on a system. It safely stops the service, renames the active and target version folders, and restarts the service.
- Windows PowerShell
- Admin rights (to stop/start services and rename folders)
Config.jsonfile in the same directory as the script
Create a Config.json file like this in the same folder as the script:
{
"Service": "MyService",
"ServicePath": "C:\\Path\\To\\MyService\\Installations",
"VersionList": [201, 202, 203]
}Service: Base name of the service folder and executable (e.g.,MyService.exe)ServicePath: Directory containing all version foldersVersionList: Valid major versions to recognize
From PowerShell:
.\Flip-Service.ps1 -Version 202The script will:
- Stop the running service
- Rename the current root folder to include the version
- Promote the target version folder to become the root
- Start the service again
- Log all actions to
logger.log
C:\Path\To\MyService\Installations\
├── MyService\
│ └── MyService.exe (v201)
├── MyService 202\
│ └── MyService.exe (v202)
└── MyService 203\
└── MyService.exe (v203)
After flipping to version 202, the structure becomes:
C:\Path\To\MyService\Installations\
├── MyService\
│ └── MyService.exe (v202)
├── MyService 201\
│ └── MyService.exe (v201)
└── MyService 203\
└── MyService.exe (v203)
All actions and errors are written to logger.log in the script directory.
.\Flip-Service.ps1 -Version 203Output:
[2025-05-05 12:00:00] Starting service flip...
[2025-05-05 12:00:01] Stopping service: MyService
[2025-05-05 12:00:02] Renaming root folder to: MyService 201
[2025-05-05 12:00:03] Renaming MyService 203 to: MyService
[2025-05-05 12:00:04] Starting service: MyService
[2025-05-05 12:00:05] Service flip complete. Now running version 203