title: Delete a windows service, and then re-install it using powershell
body: <p>How can I use powershell to delete a service, and then re-install it right afterwards?</p>
  
  <p>What I'm trying right now:</p>
  
  <ul>
  <li>using sc.exe stop "servicename"</li>
  <li>after that i do sc.exe delete "servicename"
  
  <ul>
  <li>sometimes this actually returns an error saying service is marked for deletion</li>
  </ul></li>
  <li>after that I do get-service "servicename" again to see if the service is deleted
  
  <ul>
  <li>this doesn't work as it says the service still exists</li>
  </ul></li>
  </ul>
  
  <p>As far as I know, all services windows are closed, server management, task manager, etc are all closed. However get-service consistently returns that a service exists even when it should be deleted.</p>
  
  <p>Is there a magic way to completely delete / reinstall services in one script? </p>