title: Detecting if windows service is already installed using puppet exec
body: <p>I have below <code>exec</code> resource which is used to install a window service. </p>
  
  <p>I want to it to execute only if the window service is not installed. So I use the <code>onlyif</code> command but the command is not working. It is running the install all the time:</p>
  
  <pre><code>exec { "install-${target_path}/${binary_name}":
      command   =&gt; "${installUtil_filepath} /i /servicename=\"${service_name}\" /displayname=\"${display_name}\" /description=\"${description}\" \"${target_path}\\${binary_name}\"",
      onlyif    =&gt; "if((Get-Service \"${service_name}\" -ErrorAction SilentContinue).DisplayName -eq  ${display_name}) { exit 1 } else { exit 0 }",
      logoutput =&gt; true,
      provider =&gt; powershell,
    } 
  </code></pre>
  
  <p>This worked</p>
  
  <pre><code>if(Get-Service \"${service_name}\") { exit 1 } else { exit 0 }
  </code></pre>