As with most of my Windows 2008 administration scripts I prefer to only "touch" the system if it needs updating otherwise leave it alone. The script below shows how to detect if a service is set to manual, change to automatic and start if required. Oddly the Get-Service cmdlet doesn't return the start type in PowerShell 2.0 for some reason.
function SetServiceStartToAutoMatic($serviceName = $(throw "Service Name was not specified")){
$service = Get-Service $serviceName
$startType = Get-WmiObject -Query "Select StartMode From Win32_Service Where Name='$($serviceName)'"
if ($startType.StartMode -eq "Manual"){
Set-Service $serviceName –StartupType Automatic
}
}
function StartServiceIfStopped($serviceName = $(throw "Service Name was not specified")){
$service = Get-Service $serviceName
if ($service.Status -eq "Stopped"){
Start-Service $serviceName
}
}
function Main(){
$smtpServiceName = "SMTPSVC"
SetServiceStartToAutoMatic $smtpServiceName
StartServiceIfStopped $smtpServiceName
}
Main
102aff40-4ee6-4b9b-8a19-aa615e1711d3|0|.0