1

I am a newbie in powershell script. I want to uninstall a service on remote machine and re-install it again. I am able to stop the service, change the files that service is using and again start it. But, now I want to completely uninstall it.

One more thing, I will be executing these scripts via TeamCity.

I have tried following ways, but each one is giving trouble:

  • using wmi class
  • running installutil command on remote machine. But, cant execute this on remote machine since there is problem in accessing that service.
  • Using Get-WmiObject command and then calling delete() on retrieved service.

Is there any promising solution ?? Any help will be appreciable..

Community
  • 1
  • 1
ms_27
  • 1,484
  • 15
  • 22
  • Did you see this post for deleting?: [Check if a Windows Service Exists and Delete in Powershell](http://stackoverflow.com/questions/4967496/check-if-a-windows-service-exists-and-delete-in-powershell) If that fails, you can always call a batch script instead, or possibly add a command line step in TeamCity, to call `sc delete yourServiceName` – Damon Dec 23 '13 at 22:36
  • Thanks for your response.. I have tried using sc command, But it was giving error. Right now, I am trying to use "installutil" command with "-verb RunAs" attribute while starting a new process as powershell. But, when I execute my batch file by remotely logging in onto server, a "RunAs" dialog box appears. I want to eradicate that automatically. could you help. – ms_27 Dec 24 '13 at 06:34
  • My guess is it is a permissions issue. If you can remote into the machine in question, try running each command with and without elevated privileges. I would remote in as the user that Team City is using, and test that out. Also, I haven't worked with it much there are some permissions and configurations needed for PowerShell; my guess is you will probably need to configure that under the account Team City is connecting with. – Damon Dec 24 '13 at 20:26
  • Thanks @Damon, you were right. I have used 'wmic' command and used it over that specific server, and passed required credentials having admin rights through TC parameters. And, it worked out. The issue was related with permissions for executing the PowerShell. – ms_27 Jan 04 '14 at 12:29

1 Answers1

1

After playing a lot with TC and many commands, finally I got my answer to uninstall a service on remote computer, and its working properly.

I have made use of "wmic" command and provided the remote computer name, username and password for /node:, /username:, and /password: parameters. And, provided 'installutil.exe' command to be executed remotely. Here, the actual command is..

"wmic /NODE:$serverName /USER:$userName /PASSWORD:$password process call create '$path_to_installutil_exe\installutil /u $exe_location_path_of_service'"
ms_27
  • 1,484
  • 15
  • 22