Formatting Assistance

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Andrew Andrew 5 months, 2 weeks ago.

  • Author
    Posts
  • #63652
    Profile photo of Andrew
    Andrew
    Participant

    Hi Community,

    I am trying to get the below to output into a more readable format – perhaps to Out-gridview

    $services = Get-Service

    $services | Where-Object {$_.requiredservices} | Select-Object -Property name, @{n='requiredservices'; e={$_.requiredservices.name}}, @{n='Status';e={$_.requiredservices.status}}

    I would like to try and get requiredservices and status to 'ungroup' and be on a separate line each so AppIDSvc would have 3 x lines with each required service and status? Any ideas appreciated

    Name requiredservices Status
    —- —————- ——
    AppIDSvc {RpcSs, CryptSvc, AppID} {Running, Running, Stopped}
    Appinfo {RpcSs, ProfSvc} {Running, Running}
    AudioEndpointBuilder PlugPlay Running
    AudioSrv {MMCSS, RpcSs, AudioEndpointBuilder} {Stopped, Running, Running}
    AxInstSV rpcss Running
    BFE RpcSs Running
    BITS {RpcSs, EventSystem} {Running, Running}
    Browser {LanmanServer, LanmanWorkstation} {Running, Running}

  • #63658
    Profile photo of Daniel Krebs
    Daniel Krebs
    Moderator

    Below works for me. Let me know what you think.

    Get-Service | ForEach-Object {
        if ($_.RequiredServices) {
            foreach ($service in $_.RequiredServices) {
                [PSCustomObject] @{
                    'Name' = $_.Name
                    'RequiredService' = $service.Name
                    'Status' = $service.Status
                }
            }
        }
    }
    
    • #63708
      Profile photo of Andrew
      Andrew
      Participant

      Hey Daniel,

      works for me as well – thanks so much

You must be logged in to reply to this topic.