Compare services state with XML

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Albert van Boerum Albert van Boerum 1 week, 4 days ago.

  • Author
    Posts
  • #66204
    Profile photo of Albert van Boerum
    Albert van Boerum
    Participant

    Hi everyone,

    I am trying to compare the situation of my windows services before updates and after updates.

    It seems a good idee to export the current state of the services to an XML file and later compare this with the running situation. I want to check if there is a differance in the state, startup type, new or removed services, etc.. It seems that the XML files provides me with that information.

    So, I run this command first.

    Get-Service | Export-Clixml -Path C:\temp\service-ref.xml

    The XML file is populated with all the information I need.

    Next I do my "things" on the computer and After this I want to check if there are any differances.

    For this I run the next commands.

    Compare-Object -ReferenceObject (Import-Clixml C:\temp\service-ref.xml)  -DifferenceObject (get-service)

    I would expect it returns the differances. The result is however blanc.

    The following shows the result of the XML compare. The result with get-content shows that the files are different.

    PS C:\> get-service VeeamDeploySvc
    
    Status   Name               DisplayName                           
    ------   ----               -----------                           
    Running  VeeamDeploySvc     Veeam Installer Service               
    
    PS C:\> Get-Service | Export-Clixml -Path C:\temp\service-ref.xml
    
    PS C:\> get-service VeeamDeploySvc | Stop-Service
    
    PS C:\> get-service VeeamDeploySvc
    
    Status   Name               DisplayName                           
    ------   ----               -----------                           
    Stopped  VeeamDeploySvc     Veeam Installer Service               
    
    PS C:\> Get-Service | Export-Clixml -Path C:\temp\service-dif.xml
    
    PS C:\> Compare-Object -ReferenceObject (Import-Clixml C:\temp\service-ref.xml) -DifferenceObject (Import-Clixml C:\temp\service-dif.xml)
    
    PS C:\> Compare-Object -ReferenceObject (Get-Content C:\temp\service-ref.xml) -DifferenceObject (Get-Content C:\temp\service-dif.xml)
    
    InputObject                             SideIndicator
    -----------                             -------------
                  false  =>           
                  Stopped =>           
                  false  =>           
                  Stopped =>           
                  false  =>           
                  Stopped =>           
          false          =>           
            Stopped    =>           
            1                    =>           
                  false  =>           
                  Stopped =>           
                  true   < =           
                  Running <=           
                  true   <=           
                  Running <=           
                  true   <=           
                  Running <=           
          true           <=           
            Running    <=           
            4                    <=           
                  true   <=           
                  Running  
    

    What am I missing here?

  • #66210
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

    If you want to "verify" the result of the compare-object you could use the parameter -IncludeEqual. Then you see what's compared and the result.

  • #66232
    Profile photo of Albert van Boerum
    Albert van Boerum
    Participant

    Hi Olaf,

    Thanks for the reply. This is the result I get:

    PS C:\> Compare-Object -ReferenceObject (Import-Clixml C:\temp\service-ref.xml) -DifferenceObject (Import-Clixml C:\temp\service-dif.xml) -IncludeEqual
    
    InputObject                                            SideIndicator
    -----------                                            -------------
    AdobeFlashPlayerUpdateSvc                              ==           
    AERTFilters                                            ==           
    AJRouter                                               ==           
    ALG                                                    ==           
    AppIDSvc                                               ==           
    Appinfo                                                ==           
    Apple Mobile Device Service                            ==           
    AppMgmt                                                ==           
    AppReadiness                                           ==           
    AppVClient                                             ==           
    AppXSvc                                                ==           
    AudioEndpointBuilder                                   ==           
    and so on.....
    

    It looks like it is comparing the top level in the XML and not de details of the service.

    • #66252
      Profile photo of Olaf Soyk
      Olaf Soyk
      Participant

      If you wnat to compare a special property you can specify the property with the parameter property. It seems for me that your services are just the same as they've been before.

      Edith: You can specify the parameter -PassThru as well to see even more what's going on.
      Also you should read the complete help for the cmdlets you're using including the examples ... usually it is really helpful. 😉

  • #66255
    Profile photo of Albert van Boerum
    Albert van Boerum
    Participant

    Hi Olaf,

    the property parameter did the trick.

    PS C:\> Compare-Object -ReferenceObject (Import-Clixml C:\temp\service-ref.xml)  -DifferenceObject (get-service) -Property name,status
    
    name            status SideIndicator
    ----            ------ -------------
    ClipSVC        Stopped =>           
    gpsvc          Stopped =>           
    QWAVE          Running =>           
    VeeamDeploySvc Stopped =>           
    wuauserv       Stopped =>           
    ClipSVC        Running < =           
    gpsvc          Running <=           
    QWAVE          Stopped <=           
    VeeamDeploySvc Running <=           
    wuauserv       Running <=  
    

    Now this is working I can focus on the script and format.

    Thanks,
    Albert

You must be logged in to reply to this topic.