Group on multiple machines

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of Wei-Yen Tan Wei-Yen Tan 1 year, 7 months ago.

  • Author
    Posts
  • #32659
    Profile photo of Wei-Yen Tan
    Wei-Yen Tan
    Participant

    I am using a cmdlet like Get-Eventlog on multiple machines.

    Everything works but I am not quite sure how to have theevents group by computername and then indented by service.
    I saw Don doing something like that...i thought it might be group-object but this gave me a count of all events

    I did this/:

    get-eventlog -ComputerName server1, server2 | select status, name, displayname, machinename | group machinename

    But its trying to group all the events in a category as a pose by computername. any suggestions?

  • #32663
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    Which event log are you looking at? I checked the system, application and security event logs and none of them, and none of them on my systems have status, name, or displayname as valid properties.

    And what do you mean by indented by service?

  • #32664
    Profile photo of Wei-Yen Tan
    Wei-Yen Tan
    Participant

    It's my bad Curtis. I was referring to get-service.

    But I mean display like

    Server1
    ____________
    Name , displayname , status,

    server2
    ___________
    Name,displayname,status

  • #32665
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    You can do something like this

    Get-Service -ComputerName localhost, remotehost | 
    Select-Object MachineName, Name, DisplayName, Status |
    Group-Object -Property MachineName |
    ForEach-Object {
                    $_.Name
                    "----------------"
                    $_.Group | 
                    ForEach-Object {
                                    "$($_.Name), $($_.DisplayName), $($_.Status)"
                                   }
                    ""
                   }
    

    Results like:
    Truncated lists to reduce post size.

    localhost
    ----------------
    AdobeActiveFileMonitor11.0, Adobe Active File Monitor V11, Stopped
    AdobeARMservice, Adobe Acrobat Update Service, Running
    AdobeFlashPlayerUpdateSvc, Adobe Flash Player Update Service, Stopped
    AeLookupSvc, Application Experience, Running
    AESTFilters, Andrea ST Filters Service, Running
    ALG, Application Layer Gateway Service, Stopped
    AppIDSvc, Application Identity, Stopped
    Appinfo, Application Information, Running
    Apple Mobile Device Service, Apple Mobile Device Service, Running
    
    remotehost
    ----------------
    AdobeARMservice, Adobe Acrobat Update Service, Running
    AdobeFlashPlayerUpdateSvc, Adobe Flash Player Update Service, Stopped
    AeLookupSvc, Application Experience, Running
    ALG, Application Layer Gateway Service, Stopped
    AppIDSvc, Application Identity, Stopped
    Appinfo, Application Information, Running
    AppMgmt, Application Management, Stopped
    aspnet_state, ASP.NET State Service, Stopped
    AudioEndpointBuilder, Windows Audio Endpoint Builder, Running
    AudioSrv, Windows Audio, Running
    
    
  • #32666
    Profile photo of Christian Sandfeld
    Christian Sandfeld
    Participant

    If I understand correctly, I believe what you are after, is something like this:

    Get-Service -ComputerName server1,server2 | Sort-Object -Property MachineName | Format-Table Name, DisplayName, Status -GroupBy MachineName
    

    So with this I get the services from a number of computers, sort by the 'MachineName' property (necessary for the grouping to work), and use Format-Table to select the properties I want, and use the GroupBy method to do the grouping you asked for. The GroupBy method is available in the Format-List Cmdlet as well

    This will produce output such as:

       MachineName: server1
    
    Name            DisplayName                        Status
    ----            -----------                        ------
    AdobeARMservice Adobe Acrobat Update Service      Running
    AJRouter        AllJoyn Router Service            Stopped
    ALG             Application Layer Gateway Service Stopped
    AppIDSvc        Application Identity              Stopped
    Appinfo         Application Information           Running
    
    
       MachineName: server2
    
    Name            DisplayName                        Status
    ----            -----------                        ------
    AdobeARMservice Adobe Acrobat Update Service      Running
    AJRouter        AllJoyn Router Service            Stopped
    ALG             Application Layer Gateway Service Stopped
    AppIDSvc        Application Identity              Stopped
    Appinfo         Application Information           Running
    
  • #32667
    Profile photo of Wei-Yen Tan
    Wei-Yen Tan
    Participant

    Thank you Christian, thats the result i wanted. thanks for the explaination

You must be logged in to reply to this topic.