Automation

 View Only
  • 1.  restart windows service and all dependecies

    Posted Oct 16, 2015 05:21 AM

    trying to restart a windows service which has 4 other dependecies and all need to be restarted

    $servers = get-content u:\servers.txt

    foreach ($server in $servers){

    $servicename = gwmi win32_service -filter 'displayname="Symantec Private Branch Exchange"' -computername $server

    $servicename.stop()

    $servicename.start()

    }

    but getting this error



  • 2.  RE: restart windows service and all dependecies

    Posted Oct 16, 2015 06:01 AM

    The System.Management.ManagementObject#root\cimv2\Win32_Service objects return by the gwmi win32_service command don't have a stop and start method. The methods are name StartService and StopService. So you can use:

    $servicename.StopService()

    $servicename.StartService()



  • 3.  RE: restart windows service and all dependecies

    Posted Oct 16, 2015 09:09 AM

    get-wmiobject win32_service -computername $servername | where {$_.Displayname -match "Netbackup*" -and $_.startmode -eq "auto"}

    but I also need service "Symantec*"

    how do I add that in?



  • 4.  RE: restart windows service and all dependecies

    Posted Oct 16, 2015 07:03 AM

    thank you for correcting that

    I havent tried this yet but do you think this will work?

    $servers = get-content u:\servers.txt

    $services = @("Symantec Private Branch Exchange", "Netbackup Client Service", "Netbackup Legacy Client Service", "Netbackup Legacy Network Service")

    foreach ($server in $servers){

    $servicename = gwmi-object win32_service -filter 'displayname=$services'

    $servicename.stopservice()

    $servicename.startservice()

    }



  • 5.  RE: restart windows service and all dependecies

    Posted Oct 16, 2015 09:16 AM

    do I need some kind of wait task between stopservice() and startservice()