我正在比较2个 .csv 文件并将结果输出到另一个 .csv 文件。我似乎无法弄清楚如何进一步处理在if..elseif...else{}
语句中使用的比较对象结果,以根据sideIndicator
结果打印结果。请进一步建议。是否需要包含任何捕获以确保脚本能够正确处理?
clear-host
$northdb = Import-Csv "C:\temp\cep\Book1.csv" -Header "InstanceName", "DatabaseName", "PrinicipalName", "PrinicipalType", "Permission", "ObjectTypeLevel", "ObjectName" | Sort-object -Property "InstanceName", "DatabaseName", "PrinicipalName", "PrinicipalType", "Permission", "ObjectTypeLevel", "ObjectName" -unique
$sdb = Import-Csv "C:\temp\cep\Book2.csv" -Header "InstanceName", "DatabaseName", "PrinicipalName", "PrinicipalType", "Permission", "ObjectTypeLevel", "ObjectName" | Sort-object -Property "InstanceName", "DatabaseName", "PrinicipalName", "PrinicipalType", "Permission", "ObjectTypeLevel", "ObjectName" -unique
$result = Compare-Object $northdb $sdb -Property "InstanceName", "DatabaseName", "PrinicipalName", "PrinicipalType", "Permission", "ObjectTypeLevel", "ObjectName" -PassThru |
if ($_SideIndicator -eq '=>') {Select-Object "InstanceName", "DatabaseName", "PrinicipalName", "PrinicipalType", "Permission", "ObjectTypeLevel", "ObjectName" | export-csv C:\temp\cep\gogo.csv -NoTypeInfo}
elseif ($_.sideIndicator -eq '=>') {Select-Object "InstanceName", "DatabaseName", "PrinicipalName", "PrinicipalType", "Permission", "ObjectTypeLevel", "ObjectName" | export-csv C:\temp\cep\gogo.csv -NoTypeInfo}
else {write-host "there is no changes"}