问:在输出到.csv文件之前,我需要一些关于如何使用if else if else条件比较的建议。
if $_.sideIndicator -eq "=>" output to test.csv
else if $_.sideIndicator -eq "<=" output to test.csv
else echo "there is no changes" output to test.csv
目前的代码是:
clear-host
$northdb = Import-Csv "C:\temp\cep\Book1.csv" -Header "InstanceName", "DatabaseName" | Sort-object -Property "InstanceName", "DatabaseName" -Unique
$sdb = Import-Csv "C:\temp\cep\Book2.csv" -Header "InstanceName", "DatabaseName" |Sort-Object -Property "InstanceName", "DatabaseName" -Unique
Compare-Object $northdb $sdb -Property "InstanceName", "DatabaseName" -PassThru | Where-Object{$_.SideIndicator -eq '=>'} | Select-Object "InstanceName", "DatabaseName" | export-csv C:\temp\cep\gogo.csv -NoTypeInfo
答案 0 :(得分:0)
应该是这样的:
if ($_.sideIndicator -eq "=>")
{$Something| export-csv "C:\csvPath"}
elseif ($_.sideIndicator -eq "<=")
{$Something| export-csv "C:\csvPath"}
else
{Write-Output "there is no changes"}