Hi guys,
I’m creating a little tool and i’m having issues getting it to do what I need. I’d like to for users to use this to check for stopped services. If the services are stopped, then prompt if they want to start…
Here is what i’m working with… May be time to blow it out of the water completely…
I know there is quite a few errors… I can’t even get $services to show properly… If i do not set it to a variable it shows fine…
$credential = XXX
$Server= MyService
do{
write-host " 1) Check for stopped Services on Servers"
$selectedOption = read-host
switch ($selectedOption)
{
1{
Write-Host "Checking for stopped Services...
"
$Services = Invoke-Command $Server {Get-WmiObject win32_service -Filter "startmode = 'auto' AND state = 'running' and Name like 'MY%'"} -Credential $credential
if ($Services -ne $null)
{Clear-host
$Services
## So if Services are stopped then Prompt
#Write-Host "What would you like to do?"
#Write-Host "1.) Attempt to start the Stopped Services"
#Write-Host "2.) Take no Action"
$UserAction = read-host
switch ($UserAction)
{
1{
ForEach ( $svc IN $services) {
invoke-command {Start-Service $svc} -credential $credential
}
}
2{
Write-Host "No Action Taken"
}
}
else
{
Clear-host
Write-Host ("No stopped services found!")
}
}