I can't seem to find any information anywhere on how to add header filters to a CSV file exported from powershell. See script below which exports a report on specific AD group members:
$Date = (Get-Date).ToString("dd/MM/yyyy hh:mm:ss")
$DateSh = (Get-Date).ToString("yyyyMMdd")
$CSVfile = “C:\Documents\Group Membership Report\Reports\$DateSh-GroupAccountsReport.csv”
$groups = ("Group1","Group2")
$groups | ForEach-Object {
$curgroup = $_; $_
} | Get-ADGroupMember -Recursive | Get-ADUser -Properties * -ErrorAction SilentlyContinue | Select Name,ObjectClass,Enabled,SamAccountName,LastLogonDate, @{N='Group';E={$curgroup}} | Export-Csv -NoTypeInformation $CSVfile
The rest of the script sends an email with this CSV as an attachment.
I would like to be able to add filters to the headers in the CSV file to make it easier to sort, which I can do manually, but I need the script to do this itself, see image below:
I'm not sure if how simple a task it is, if it's just a case of adding a few extra lines to my existing script or needing a whole new one. I think it would need to be converted to an xls doc and formatted as a table. Any help is appreciated,
Thanks