2

I'm having an issue using the cmdlet Group-Object. Take this for example:

PS C:\Windows> get-service | Group-Object -Property status

        Count Name      Group           
        ----- ----      -----   
        114 Running   {AdobeARMservice, Appinfo, AppMgmt...}
        128 Stopped   {AdobeFlashPlayerUpdateSvc, AJRouter...}

See how the group column doesn't show all the names but rather truncates them with an ellipsis. I know I can pipe Select-Object -expandproperty group cmdlet afterwards to get the full list but that will only output the group column and not the count and name columns. I know I can also replace group-object and just use format-table -wrap to get the list expanded with the other columns but I need the count column and that wouldn't show up without Group-Object.

Anyone know how to do this while still using Group-Object? This is not just specifically for get-service but other stuff that I use group-object with. Get-service is just a generic example that anyone can relate to. Thanks.

  • What do you want to do with it after you are done? The output of Group-Object really is never going to be great to look at. But you could write some code to add custom formatting for display, or manipulate it any way you want. Anyway, my point is that the solution will be context sensitive. – Zoredache Dec 15 '16 at 17:52
  • It's more for visual satisfaction but also for reporting. With my example I want the count of the service status but I also want to see all the services in that group. Visual satisfaction. I could expand the property but I would lose the other 2 columns. If so then I would have to manually copy & paste things in my report to look like I want it. Reporting. Daniel did come up with a way to show the hidden data but it doesn't work in powerCLI. – Jon Dec 15 '16 at 19:40
3

Well, like I said in my comment, what you do with the output of Group-Object is entirely situation dependent. But here is an example of how you can see all the Service Names.

Get-Service | Group-Object -Property Status |
Select-Object Count, Name, @{Name="Services";Expression={$_.Group.Name -join ','}} |
Format-Table -Wrap

Count Name    Services
----- ----    --------
  108 Running AdaptiveSleepService,AMD External Events Utility,AppIDSvc,Appinfo,Apple Mobile Device
              Service,AudioEndpointBuilder,Audiosrv,BDESVC,BFE,BITS,Bonjour Service,BrokerInfrastructure,CDPSvc,
  132 Stopped AJRouter,ALG,AppMgmt,AppReadiness,AppVClient,AppXSvc,AxInstSV,Browser,BthHFSrv,bthserv,ClipSVC,COMSysApp,
              CscService,DcpSvc,defragsvc,DeviceInstall,DevQueryBroker,diagnosticshub.standardcollector.service,DmEnrol,
| improve this answer | |
  • Thanks that works both in powershell and powerCLI. I saw a similar example when searching for a way but couldn't figure it out. This is a regular expression or hash table? – Jon Dec 16 '16 at 0:41
1

This works for me.

$FormatEnumerationLimit=-1
Get-Service | Group-Object -Property Status | ft -Wrap
| improve this answer | |
  • Thanks Daniel for letting me know about this variable. It's a hidden gem. It did expand the values within powershell. However, it doesn't seem to work in powerCLI. It might be the way they've implemented powershell in it. Not sure if you have it but if you try the following code it will show up with ellipsis. Get-VMHost | get-vm | Group-Object -Property vmhost | ft -Wrap – Jon Dec 15 '16 at 16:04
  • I don't have powercli. But my solutions seems not like the preferred choice anyway. I'm certain there is a better one. – Daniel Dec 15 '16 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.