Powershell · 2016-04-20

PowerShell – Get “Logon As” Information From Remote (or local) Server

This was made possible by the Scripting Guy.  I have boiled it down to the answer.

If you want to use PowerShell to query for the log on account that normally is displayed in the services.msc service properties window:

 

Here is the PowerShell script:

 

$server_name = "name_of_server"; 
$services = Get-WmiObject win32_service -ComputerName $server_name |Where-Object {$_.name -like "*SQL*"}; 
$services|select StartName,name; 

This bothered me a little bit because Get-Service seemed to grab the data that I wanted very quickly and it seemed like the place that login information would be stored.  Unfortunately, it didn't work.  So, this Get-WmiObject approach takes 5-10 seconds to run, but it's worth it.