title: How can I add a new column and fill said column in powershell using excel?
body: <p>(For this example I'm going to use the command Get-Service) When I do the command Get-Service, something like this is returned:</p>
  <pre><code>    Status    Name  
    Running    service1
    Stopped    service2
    Running    service3 
  </code></pre>
  <p>I put the results of this command in an excel file, using the module ImportExcel</p>
  <pre><code>Get-Service | Select-Object Server, Status, Name |Export-Excel -path F:\file.xlsx
  </code></pre>
  <p>Notice that I added the column &quot;Server&quot; to the file. I need this column to be fieled with the name of a server from an array</p>
  <pre><code>$servers = @('Server1', 'Server2')
  </code></pre>
  <p>Meaning it would be something like this:</p>
  <pre><code> Server     Status    Name  
   Server1   Running    service1
   Server1   Stopped    service2
   Server1   Running    service3
   Server2   Running    service1
   Server2   Stopped    service2
   Server2   Running    service3
  </code></pre>
  <p>Meanig that for each server I want to run the command get-servive, add the column with the server name to the excel file and fill each row of each service with the server name.
  Here is what I have so far:</p>
  <pre><code> $servers = @('Service1', 'Service2')
   $services=@(Get-Service).Count
   foreach($server in $servers)
   {
     for($i=0; $i -lt $services; $i++){
        #for each service add column with the server name
     } 
   }
  
  
   #at the end export everything to excel file
       $something|Export-Excel -path F:\file.xlsx
  </code></pre>
  <p>I'm not sure if my explanation made sence but if anyone could help me with this I would appreciated</p>