title: how can i save event log information in a excel using powershell
body: <p>i'm new to ps scripting , i want to export certain data from event logs. I tried following</p>
  <pre><code>$events = Get-WinEvent -FilterHashtable @{logname=&quot;Microsoft-Windows-Storage-Storport/Health&quot;; id=511}
  
  # get the first event raw XML
  $event = [xml]$events[0].ToXml()
  $event.Event.EventData.Data | Where-Object {$_.name -eq &quot;BootDevice&quot;}
  </code></pre>
  <p>and i was getting output as:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Name</th>
  <th>#text</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>BootDevice</td>
  <td>true</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>but when i tried to export its value to excel it gives me error.</p>
  <p>Here is my complete code:</p>
  <pre><code>$Myexcel = New-Object -ComObject excel.application
  $Myexcel.visible = $true
  $Myworkbook = $Myexcel.workbooks.add()
  $Sheet1 = $Myworkbook.worksheets.item(1)
  $Sheet1.name = &quot;summary&quot;
  $Sheet1.cells.item(1,1) = 'BootDevice'
  $events = Get-WinEvent -FilterHashtable @{logname=&quot;Microsoft-Windows-Storage-Storport/Health&quot;; id=511}
  
  # get the first event raw XML
  $event = [xml]$events[0].ToXml()
  
  # display its content
  #$event.Event.EventData.Data
  $BootDevice=$event.Event.EventData.Data | Where-Object {$_.name -eq &quot;BootDevice&quot;}
  write-output $BootDevice
  $Sheet1.cells.item(2,1) = $BootDevice
  $Sheet1.Columns.AutoFit()
  $Myfile = 'E:\tmp\test.csv'
  $Myworkbook.Saveas($Myfile)
  $Myexcel.displayalerts = $true
  </code></pre>
  <p>But its giving error</p>
  <pre><code>Exception from HRESULT: 0x800A03EC
  At line:16 char:1
  +$Sheet1.cells.item(2,1) = $BootDevice
  </code></pre>
  <p>And a blank excel is generated.</p>
  <p>Any help will be thankfull.</p>