title: How to get Log On As account for Windows Service via PowerShell
body: <p>New to powershell and I'm guessing this exists but I cannot find.  I am looking for a powershell command that will show me the account being used to run a Windows Service?  I am first as going to check it is running, then make sure it is running using the correct AD account.  I have the following so far...</p>
  
  <pre><code>$serviceName = '&lt;my service name&gt;'
  
  If (Get-Service $serviceName -ErrorAction SilentlyContinue) {
  
      If ((Get-Service $serviceName).Status -eq 'Running') {
          $status = "$serviceName found and is running."
  
      } Else {
          $status = "$serviceName found, but it is not running."
      }
  
      #Here is where I should check Log On As name
  
  } Else {
  
      $status = "$serviceName not found."
  }
  
  write-host "Status: $status`n"
  
  pause
  </code></pre>
  
  <p>Most of my searches lead me to Get-WmiObject, but I did not find what I was looking for.  Thanks in advance for any help.</p>