This requires the ExcelImport module
Import-Module
ImportExcel
$fileName
=
"NotLoggedInRecently.xlsx"
$sheetName
=
"NotLoggedInRecently"
$excel
=
$queryResults
|
Select-Object
*
-ExcludeProperty RowError,
RowState,
Table,
ItemArray,
HasErrors
|
Export-Excel
-Path
$exportPathWithFileName
-FreezeTopRow
-AutoSize -AutoFilter
-BoldTopRow
-Show
-WorksheetName
$sheetName
-PassThru
$excelWorkSheet
=
$excel.Workbook.Worksheets[$sheetName]
Set-ExcelRange
-Address
$excelWorkSheet.Cells["B:B"]
-Width
25
$excel.Save()
$excel.Dispose()