-
-
Save unbaiat/985a2cd8a45737759b52babdf9eb96b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$serviceName = "MyService" | |
if (Get-Service $serviceName -ErrorAction SilentlyContinue) | |
{ | |
$serviceToRemove = Get-WmiObject -Class Win32_Service -Filter "name='$serviceName'" | |
$serviceToRemove.delete() | |
"service removed" | |
} | |
else | |
{ | |
"service does not exists" | |
} | |
"installing service" | |
$secpasswd = ConvertTo-SecureString "MyPassword" -AsPlainText -Force | |
$mycreds = New-Object System.Management.Automation.PSCredential (".\MYUser", $secpasswd) | |
$binaryPath = "c:\servicebinaries\MyService.exe" | |
New-Service -name $serviceName -binaryPathName $binaryPath -displayName $serviceName -startupType Automatic -credential $mycreds | |
"installation completed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment