I have the code below which imports an Excel file and then exports the workbook into one sheet:
$sheets = (Get-ExcelSheetInfo -Path 'C:\TEMP\Template\TemplateName.xlsx').Name
$i = 1
foreach ($sheet in $sheets) {
Import-Excel -WorksheetName $sheet -Path 'C:\TEMP\Template\TemplateName.xlsx' -StartRow 5 -HeaderName 'Property','Current settings','Proposed settings' | Export-Excel -Path C:\Temp\Template\Changes.xlsx -AutoSize
Write-Progress -Activity "Generating Changes" -Status "Worksheet $i of $($sheets.Count) completed" -PercentComplete (($i / $sheets.Count) * 100)
$i++
}
The problem with the code above is that it outputs the xlsx file last row first and then goes in reverse. I would like to maintain the original order of the imported file.
Secondly, I've been playing with different ways to assign columns to PS Object and use Where-Object to filter the output, but can't figure it out.
What I'd like to do is if the Column "Current settings" is blank or does NOT match text in column "Proposed settings", then leave that row out of the export. Essentially, I would just like to fill in rows where "Current settings" is not blank and -notmatch "Proposed settings.