(As soon as I though of this post name, I had this song stuck in my head. I’m sure (hopeful!) most of you are probably old enough to remember the Windows 95 Commercial. It’s a great song and a short post so if you want a bit of background music while you’re reading then open this in a new tab and enjoy.)

Recently I wanted to get the start times for a few SQL instances I have running. I immediately thought of the Get-Process cmdlet, so I checked out the members of get-process:

powershellget-process|get-member

2013-07-11-10_31_42-powershell-v2-e1374761519250_png

Looking through this list, I noticed that there was a start-time Property.

starttime-e1374763452574_png

Bingo! That’s the one I need. I know that what I am looking for is the sqlservr process, so I define the executable name and pipe that into Select-Object to get the pertinent information.

powershellget-process sqlservr | select-object name, starttime, id, productversion

2013-07-11-10_38_58-powershell-e1374763552615_png

Let’s make things look neater by piping into the Format-List cmdlet.

2013-07-11-10_40_36-powerhsell-e1374763613377_png

powershellget-process sqlservr | select-object name, starttime, id, productversion | format-list

Tidy. So this also works for everything right?

2013-07-11-10_47_43-powershell-e1374763690315_png

Wrong. It looks like that you need to be running PowerShell as an administrator to access the details via Get-Process. So certain processes don’t return the full list if you don’t have the correct permissions. Fortunately there is a workaround to get the start time, I’ve yet to find a solution that supplies the product version. In this case we use the Get-WmiObject cmdlet. It’s still the de-facto sysadmin cmdlet to use in routine tasks.


$a = gwmi win32_process | ? { $_.name -eq "msmdsrv.exe" }
$a | Select-Object name, processId, @{Name="StartTime"; Expression={ $_.ConvertToDateTime( $_.CreationDate )}} | Format-List

2013-07-11-11_45_16-powershell_png

2013-07-11-11_47_26-powershell_png

Here’s the scripts if you want to run this remotely:


Get-Process -computername server01 sqlservr| Select-Object name, starttime, id, productversion | Format-List

 

[code langauge=“powershell”]

$a = gwmi win32_process -computername $server01 | ? { $.name -eq "msmdsrv.exe" } $a | Select-Object name, processId, @{Name="StartTime"; Expression={ $.ConvertToDateTime( $_.CreationDate )}} | Format-List


If anyone does know of a way to get the Product Version then let me know as it's super useful to know what version I am running without going to admin mode.