Thursday, September 12, 2013

Powershell Quickee

As this title rolled off my fingers it made me laugh a little.

But hey, isn't everything in PowerShell a little quicker?  At least that is the intent.  Over the past few years I keep dabbling in PowerShell from time to time.  I have just enough experience to know what can reasonably be done in the tool - without over extending it.  <soapbox> It looks like there are some people who take this tool and use it to bang every nail they have.  But that is another blog entry. </soapbox>

Here is the script I crufted up today for showing me all the services that are on a server set to run at startup (aka Automatic) and yet are NOT running now.

I was using the get-service cmdlet but it did not seem to be return the StartMode and State properties from a remote server (works locally fine).  So I Googled up an alternative that uses WMI.

foreach ($ServerName in $ServerList)
{
$ServerName
Get-WmiObject Win32_Service -ComputerName $ServerName |
Where-Object { $_.StartMode -eq 'Auto' -and $_.State -ne 'Running' } |
Format-Table -AutoSize @(
'Name'
'DisplayName'
@{ Expression = 'State'; Width = 9 }
@{ Expression = 'StartMode'; Width = 9 }
'StartName'
)
}

No comments:

Post a Comment