title: Powershell writing data into excel file
body: <p>hoping to get some help with what i'am trying to achieve here.</p>
  
  <p>i have two arrays $ActiveUsers and $InactiveUsers with 4 fields and following data in each</p>
  
  <pre><code>$ActiveUsers = fahe532|Allyson Sullivan|34563|Cain,Ashley J
                 pers274|Martha Walsh|53732|Mckenny,Josh
                 fgh8458|Kayla Benson|95463|Trot,Cook K
                 ndcf846|Sam Huff|56737|Mcghee,John
                 vdfg456|Mark Jones |67843|Hart,Josh W
                 fasf345|Amber Sean|24678|John,Kneel G
  
  $InavtiveUsers = fasd034|Colin Hart|35473|David, Casper
                   aertp56|Andy Matthews|56849|Debby, Gould K
                   ahshb86|Mark Michael|46848|Ty, Justin H
                   gkr5057|Josh Meeker|56848|Ashley, Rhonda R
                   irrk106|Tom Mortin|64838|Becks, Alan
                   eqer348|Nathan Willis|469894|Baker ,John T
  </code></pre>
  
  <p>Now, i'am trying to pull each row from $ActiveUsers and adding it to a excel file i'am creating. I did the same for each row in $InactiveUsers and added them into a new Excel file</p>
  
  <p>There was a slight change in the requirement, instead of having two arrays added into two Excel files i have to put everything in one excel file, Also i need to highlight(with some color) the rows i'am getting from $InactiveUsers in that one excel file where i'am writing everything.</p>
  
  <p>Is there a way i can loop through two arrays simultaneoulsly and write rows into one excel file by higlighting the rows i get from $InactiveUsers? Below is what i wrote so far</p>
  
  <pre><code>$ExcelObject = new-Object -comobject Excel.Application  
  $ExcelObject.visible = $false 
  $ExcelObject.DisplayAlerts =$false
  $date= get-date -format "yyyyMMddHHss"
  $strPath1="o:\UserCert\Active_Users_$date.xlsx" 
  if (Test-Path $strPath1) {  
    #Open the document  
  $ActiveWorkbook = $ExcelObject.WorkBooks.Open($strPath1)  
  $ActiveWorksheet = $ActiveWorkbook.Worksheets.Item(1)  
  } else {  
  # Create Excel file  
  $ActiveWorkbook = $ExcelObject.Workbooks.Add()  
  $ActiveWorksheet = $ActiveWorkbook.Worksheets.Item(1)  
  
  #Add Headers to excel file
  $ActiveWorksheet.Cells.Item(1,1) = "User_Id"  
  $ActiveWorksheet.cells.item(1,2) = "User_Name" 
  $ActiveWorksheet.cells.item(1,3) = "CostCenter"
  $ActiveWorksheet.cells.item(1,4) = "Approving Manager"
  $format = $ActiveWorksheet.UsedRange
  $format.Interior.ColorIndex = 19
  $format.Font.ColorIndex = 11
  $format.Font.Bold = "True"
  } 
  #Loop through the Array and add data into the excel file created.
  foreach ($line in $Activeusers){
       ($user_id,$user_name,$Costcntr,$ApprMgr) = $line.split('|')
        $introw = $ActiveWorksheet.UsedRange.Rows.Count + 1  
        $ActiveWorksheet.cells.item($introw, 1) = $user_id  
        $ActiveWorksheet.cells.item($introw, 2) = $user_name
        $ActiveWorksheet.cells.item($introw, 3) = $Costcntr
        $ActiveWorksheet.cells.item($introw, 4) = $ApprMgr 
        $ActiveWorksheet.UsedRange.EntireColumn.AutoFit();
        }
  </code></pre>
  
  <p>I repeated the above for $InactiveUsers.</p>