title: How do I add a column of incrementing values to cmdlet output?
body: <p>Suppose I call <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service?view=powershell-5.1" rel="nofollow noreferrer"><code>Get-Service</code></a> and want to assign a new column <code>ID</code> with the cmdlet output that prints incrementing integers so that:</p>
  
  <pre><code>ID  Status Name                            DisplayName
  --  ------ ----                            -----------
   0 Running AdobeARMservice                 Adobe Acrobat Update Service
   1 Stopped AeLookupSvc                     Application Experience
   2 Stopped ALG                             Application Layer Gateway Service
  </code></pre>
  
  <p>I'm trying to use <a href="http://technet.microsoft.com/en-us/library/hh849895.aspx" rel="nofollow noreferrer"><code>Select-Object</code></a> right now to add this column, but I don't quite understand how to iterate a variable in this sort of expression.  Here's what I've got:</p>
  
  <pre><code>Get-Service |
  Select-Object @{ Name = "ID" ; Expression= {  } }, Status, Name, DisplayName |
  Format-Table -Autosize
  </code></pre>
  
  <p>Is there a way to iterate integers within <code>Expression= {  }</code>, or am I going about this problem the wrong way?</p>