none
Compare Windows Services with PowerShell

    Question

  • Hello

    I have 21 Web servers running Windows 2008 R2 Enterprise.  As these servers has to be exactly the same in terms on configuration, I want to have all their services on the same state.  I've seen the script to check the service after patching but I want to get all the servicesof all servers same as the 'master' one.

    can someone help me?

    Regards,

    Olivier

    Monday, March 04, 2013 5:54 AM

Answers

  • so you want to do somethign like this:

    $servers = get-content c:\webservers.txt # Get the names of each server
    $OKserervices = get-service 'reference machine name'
    Foreach ($OKService in $Okservices) {
      Foreach ($server in $servers) {
        $state = Get-Service $okservice $server
            ...  use details of the service to ensure that service ($OKSERVICE) is  hte same as on that machine (Eserver)
        }
    }

    You will need to fill in the blanks since I;m still not quite sure what you want to do. You may need to use WMI to get/set service details.

    Have a go at that  - and repost what doesn't work.


    Thomas Lee <DoctorDNS@Gmail.Com>


    Monday, March 04, 2013 7:20 PM

All replies

  • Oliver,

    I'm afraid your question is one you may not get an answer to in this forum. In general, this place is not here for us to write your scripts for you, as noted i the first post in this forum (http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/a0def745-4831-4de0-a040-63b63e7be7ae).#We can, and will, answer specific questions (when I try to use the xxx cmdlet, I get this error).

    You probalby want something that looks like this:

    $servers = get-conent c:\webservers.txt # Get the names of each serve
    $servicestate foreach ($server in $servers) {
       $services = get-service -computername $Server
       <do what you you need to each service
    }

    You do not sayu what you mean by 'configuration as to be the same' nore where you plan to get that service configuration detail from.

    You need to go back, work out what you really want, then try to write it. When you have trouble then come back.

    FWIW: group policy is probably a better approach to doing this tasks.

    Sorry if this is not the answer you want.,


    Thomas Lee <DoctorDNS@Gmail.Com>


    Monday, March 04, 2013 6:41 AM
  • Hello

    I have 21 Web servers running Windows 2008 R2 Enterprise.  As these servers has to be exactly the same in terms on configuration, I want to have all their services on the same state.  I've seen the script to check the service after patching but I want to get all the servicesof all servers same as the 'master' one.

    can someone help me?

    Regards,

    Olivier

    This is normally done with Group Policy.  We create a GP object that sets all of the required services to the correct state and apply this policy to a group containing the target servers.

    Post in the Group Policy forum for detailed instructions.


    ¯\_(ツ)_/¯

    Monday, March 04, 2013 6:43 AM
  • Hi Thomas,

    thank you for you answer.  Maybe I've not explain my issue well.  

    I wanted to get all the windows services running on one server be the same on the 20 other one via Powershell.  I've been inspired by the script to check the services after patching but dont know how to get the script runnning with a master server comparaison.

    Anyway I'll give the group Policy a try.

    Regards,

    Olivier

    Monday, March 04, 2013 10:06 AM
  • so you want to do somethign like this:

    $servers = get-content c:\webservers.txt # Get the names of each server
    $OKserervices = get-service 'reference machine name'
    Foreach ($OKService in $Okservices) {
      Foreach ($server in $servers) {
        $state = Get-Service $okservice $server
            ...  use details of the service to ensure that service ($OKSERVICE) is  hte same as on that machine (Eserver)
        }
    }

    You will need to fill in the blanks since I;m still not quite sure what you want to do. You may need to use WMI to get/set service details.

    Have a go at that  - and repost what doesn't work.


    Thomas Lee <DoctorDNS@Gmail.Com>


    Monday, March 04, 2013 7:20 PM