title: Powershell export result to xlsx file
body: <p>If I want to change the export file format to excel, is there any way to do it?</p>
  
  <p>Thanks.</p>
  
  <p><strong><em>Powershell Script</em></strong></p>
  
  <pre><code>Import-Module ActiveDirectory
  
  $refDate = (Get-Date).AddDays(1).Date
  New-PSDrive -Name UNCPath -PSProvider FileSystem -Root "\\Test-PC\Test\"
  $logTime = Get-Date -Format "yyyyMMdd"
  $logFile = 'UNCPath:\Log\'+$logTime+".log"
  
  start-transcript $logFile
  
  $users = Get-AdUser -Filter {AccountExpirationDate -eq $refDate} –Properties EmailAddress, AccountExpirationDate -ErrorAction SilentlyContinue
  if ($users) {
        $fileOut = 'UNCPath:\'+ 'ExpiryUserList' + ".csv"
      $users | Select-Object -Property SamAccountName, Name, EmailAddress, AccountExpirationDate | 
      Export-CSV -Path $fileOut -NoTypeInformation
      Write-Host ""
      Write-Host "Result: Record have found!"
      Write-Host ""
      Stop-Transcript
  }
  else {     
     Write-Host ""
     Write-Host "Result: No expired accounts found!"
     Write-Host ""
     Stop-Transcript
  }
  </code></pre>