Forum Discussion
Thatcoder
Feb 20, 2022Copper Contributor
Script to update files
I'm writing a chocolatey installation script which installs a service from a zip file. (ziplocation = C:\Reference\file.zip) At the end of script, I want to stop the service, replace/update the file...
Feb 20, 2022
Don't know what service it is and how it behaves, but a stop-service -force:$true is perhaps an option and a check before starting the service if it's actually stopped and kill it if not? Something like: if ((get-service -name nameofservice).status -ne 'Stopped') {get-process nameofprocess | stop-process -force}
Thatcoder
Feb 20, 2022Copper Contributor
Thanks perhaps it helps.
- Feb 27, 2022What was your final version of the script?
- ThatcoderFeb 28, 2022Copper ContributorI wrote something like this
$servicepath = “zip file location”
$servicename = “installer”
$servicestatus = get-service-name $servicename -erroraction silentlycontinue
If ($servicestatus.status -eq running) {
Stop-process -name $servicename -force }
Expand-Archive -literalpath $servicepath -destinationpath c:/users/ -force
Start-service