Start service but unable to view status running

D Vijayakumar VLR 126 Reputation points
2022-01-16T16:24:30.73+00:00

Hi All,

I have simple single line script the service started and running able to view in powershell, But unable to view in remote server servie is started but in remote server screen shows it not started screeb refresh we are able to view status running for that screen refersh any powershell command is there ? i tried many but no luck manaul screen refersh we able to view rhe status running otherwise not able to view help me on that , and i want this need to implement on mulitple remote server and few more services need to add.

Get-Service -ComputerName Server -Name winrm | Start-Service

This command service start started able to view in powershell but unable to view in remote server

i tried set-service -Status Running or $service .Refersh all not working no luck

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2022-01-16T16:31:36.787+00:00

    If I understand you right you want to check the service status on servers via PowerShell?

    If so, maybe this helps (same question you asked before ;-) ): https://learn.microsoft.com/en-us/answers/questions/334116/how-to-check-service-status-are-running-or-stopped.html

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


  2. MotoX80 36,291 Reputation points
    2022-01-16T17:52:30.323+00:00

    But not able to view in remote server we manaul screen refersh we able to view for that sreen automatic refersh any command is there ?

    I'm not sure that I completely understand your question, but if you want to monitor a service with Powershell and have it automaitically refresh then you will need a loop of some kind.

    cls;
    while ($true) {
        $svc = get-service -name BranchCache 
        write-host -nonewline "`r$(Get-Date -format 'yyyy/MM/dd hh:mm:ss') Service $($svc.name) - $($svc.Status)" 
        start-sleep -seconds 5
    }
    

  3. Shane Walsh 31 Reputation points
    2022-01-18T14:58:59.11+00:00

    Not quite sure what you want to achieve but you could try this:

    invoke-command -computername SERVERNAME -scriptblock { get-service winrm | Set-Service -StartupType Automatic -PassThru | Start-Service }
    

  4. MotoX80 36,291 Reputation points
    2022-01-18T16:10:23.71+00:00

    but im unable to view service started and runing i manual refersh services page screen then i able to view service

    Something like this? Note that in my testing, get-ciminstance ran faster than get-service. You can select which call works best for you.

    $servers = @('localhost','test10')
    $services = @('LanmanServer')              # add additional services to monitor if needed 
    while ($true) {           # infinite loop, use ctrl+c to terminate
        cls
        "{0} - Service Status" -f (get-date)
        foreach ($srvr in $servers) {
            foreach ($svc in $services) {
                $TheService = Get-CimInstance -ClassName Win32_Service -Computername $srvr -Filter "Name like '$svc'"
                "{0} - {1} - {2}" -f $srvr, $TheService.DisplayName , $TheService.State
                #$TheService = Get-Service -Computername $srvr -Name "$svc"
                #"{0} - {1} - {2}" -f $srvr, $TheService.DisplayName , $TheService.Status            
            }
        }
        start-sleep -Seconds 60
    }
    
    0 comments No comments

  5. MotoX80 36,291 Reputation points
    2022-02-17T13:50:17.833+00:00

    but few servers it won't work manaul go to each server kill that service and then start the service after that service running for service kill

    I'm sorry but I don't understand what you are trying tell us. When it doesn't work, what error do you get?

    You're not really modifying the WinRM service are you? Invoke-Command uses WinRM to execute the remote command. Test with a different service. I use Fax.

    The main problem with the code that you have posted is that you are not testing the current status of the service. If it is already running, there is no need to issue a start for it.

    Do it like this and display more information about what the script sees and performs. Note that the Fax service will not actually start. Replace Fax with the name of your service.

     Invoke-Command -ComputerName test10   -ScriptBlock {
        $SvcName = 'Fax'
        $Report = $false 
        $Svc =  get-service -Name $SvcName
        "The {0} service is {1} and the start type is {2}" -f  $SvcName, $Svc.Status,  $Svc.StartType
        if ($Svc.Status -eq "Stopped") {
            "Starting the service"
            Start-Service -Name $SvcName
            Start-Sleep -Seconds 5
            $Report = $true 
        }
        if ($Svc.Status -ne "Automatic") {
            "Setting to Automatic startup."
            Set-Service -Name $SvcName  -StartupType Automatic
            $Report = $true
        }
        if ($Report) {
            $Svc =  get-service -Name $SvcName
            "After changes, the {0} service is {1} and the start type is {2}" -f  $SvcName, $Svc.Status,  $Svc.StartType
        }
    
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.