Created
June 19, 2017 20:12
-
-
Save yaplex/3d295f50f138762c7e1cd16bc5d4b502 to your computer and use it in GitHub Desktop.
This file contains hidden or 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