Reputation: 1016
Is there a way to get numbered output list lets say
Get-Service | where {$_.Status -eq "Running"} | out-file "C:\services.log"
I get all services but it is not numbered.
Running AudioEndpointBu... Windows Audio Endpoint Builder
Running Audiosrv Windows Audio
Running BFE Base Filtering Engine
How can I get numbered list like this?
1> Running AudioEndpointBu... Windows Audio Endpoint Builder
2> Running Audiosrv Windows Audio
3> Running BFE Base Filtering Engine
Upvotes: 2
Views: 3344
Reputation: 1016
This will be more better if anyone need actually I need this to out-put logs while creating bulk ad users
$a=1;
Get-service |ForEach-Object {"$($a).) $($_.name)"; $a++} | out-file c:\services.log
Upvotes: 2
Reputation: 247163
Try this
$global:i=0
Get-Service | where {$_.Status -eq "Running" } | Select @{Name="Item#";Expression={$global:i++;$global:i.Tostring() + ">"}},Status,Name,Displayname | out-file "C:\services.log"
$global:i=0
Don't forget to reset global:i to zero (0) when done.
Found it here PowerShell Problem Solver: Create Numbered Output Lists with PowerShell
Upvotes: 1