I have last month excel sheet with following
Current month excel sheet with following
Now i would like find what is new server Name added in current month then list them out as shown below
So far i got following code. any idea would be appreciated ? i will be scheduling this with windows scheduler task .This should be powershell since i will be adding more code later how to pick right excel sheet from SMB share.
i am trying this
$oldbk = Import-Excel -Path '\\hcohesity05\cohesity_reports\2022\7\07-29\Cohesity_FETB_Report-2022-07-29-14-26-48.xlsx'
$newbk = Import-Excel -Path '\\hcohesity05\cohesity_reports\2022\8\08-26\Cohesity_FETB_Report-2022-08-26-14-26-48.xlsx'
$Compare = Compare-Object $oldbk $newbk -Property "Server Name" -includeDifferent -PassThru
$Compare | Export-Excel -Path '.\diff.xlsx'
but getting message A parameter cannot be found that matches parameter name 'includeDifferent'.
CodePudding user response:
By looking at your code I'm assuming you're only interested in finding the servers not present in the old Excel document, if that's the case you only need Where-Object
for filtering:
$oldbk = Import-Excel -Path 'path\to\oldfile.xlsx'
Import-Excel -Path 'path\to\newfile.xlsx' | Where-Object {
$_."Server Name" -notin $oldbk."Server Name"
} | Export-Excel -Path 'path\to\diff.xlsx'
As for the error message, Compare-Object
does not have a -IncludeDifferent
parameter and shows differences between two objects by default.
$Compare = Compare-Object $oldbk $newbk -Property "Server Name" -PassThru