title: Why is my Powershell script checking if process is running giving error if it cannot find the process?
body: <p>I have the following ps1 script:</p>
  
  <pre><code> $process_check = Get-Service "Process" | findstr -i "Process" 
  echo $process_check
  
  </code></pre>
  
  <p>When I execute it finds my process called "process" and gives the output</p>
  
  <pre><code>*output*
  Running  Process        Process_displayName
  </code></pre>
  
  <p>I want to make sure my script gives me the expected output if "Process" is not running. To check this i created a new variable this time checking for process "QWERTY" so my full script is:</p>
  
  <pre><code>$process_check = Get-Service "Process" | findstr -i "Process" 
  $qwerty_check = Get-Service "QWERTY" | findstr -i "QWERTY" 
  echo $process_check
  echo $qwerty_check
  </code></pre>
  
  <p>This outputs the following:</p>
  
  <pre><code>*output*
  Running  Process        Process_displayName
  
  Get-Service : Cannot find any service with service name 'qwerty'.
  At C:\Users\proc_checks.ps1:5 char:14
  + $qwerty_check = Get-Service "qwerty" | findstr -i "qwerty"
  +              ~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : ObjectNotFound: (qwerty:String) [Get-Service], ServiceCommandException
      + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetServiceCommand 
  </code></pre>
  
  <p>Is there a way I can have the script not error if it cant find the process by my set process name (in this case "Process" and "qwerty") </p>
  
  <p>Do I perhaps need an if statment checking for null before I assign my variables?</p>