Jump to content


  • 0
mutant27

Powershell script to detect that service has been stopped

Question

I have a script that shuts the PcaSvc (Program Compatibility Assistant Service) before installing another program. However, I need a script to detect that it's Stopped so I can use it for SCCM AppModel detection.

 

I have this, but I'm getting erros......yes I'm a Powershell newbie......

 

$PcaSvc = Get-WmiObject win32_service | where Name -eq "PcaSvc"
if ($PcaSvc.State -eq "Stopped") {
$true
} else {
$false
}
Please assist...thanks!

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

It makes no sense to use it for the detection rule, because the status will alter once the service gets started again and your application will start to install once again. You will create a endless loop.

Just create an installation wrapper script that shuts down the service before starting the setup and restart the service when the installer is finished.

 

Anyways, the answer to your question is a simple single line.

 

if ((Get-Service -Name PcaSvc ).Status -eq "Stopped"){Return $true}

 

Any output in a scripted detection counts as success.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.