在PowerShell中使用foreach循环if语句

时间:2019-07-11 07:59:29

标签: powershell loops if-statement foreach

我想在PowerShell中使用if来循环foreach语句。

$Result = @()
foreach ($get in $a ) {
    $b = $get.rows |select asset_tag, serial, notes 
    $g = $get.rows |select custom_fields 
    $h = $get.rows |select Ueberschreibschutz 
    $i = $get.rows.custom_fields.Ueberschreibschutz | select value 
    $j = $get.rows.custom_fields | select Mediensatz 
    $k = $get.rows.custom_fields.Mediensatz | select value 
    $l = $get.rows |select status_label 
    $m = $get.rows.status_label | select name 

    $ResultItem = New-Object PSObject;
    $ResultItem | Add-Member NoteProperty "asset_tag" $b.asset_tag;
    $ResultItem | Add-Member NoteProperty "SNR" $b.serial;
    $ResultItem | Add-Member NoteProperty "status_label" $l.status_label.name;
    $ResultItem | Add-Member NoteProperty "notes" $b.notes;
    $ResultItem | Add-Member NoteProperty "Ueberschreibschutz" $g.custom_fields.Ueberschreibschutz.value;
    $ResultItem | Add-Member NoteProperty "Mediensatz" $g.custom_fields.Mediensatz.value;
    $Result += $ResultItem;

    if ($weekly -eq $g.custom_fields.Mediensatz.value) {
        if ($CurrentDate -ge $i) {
            Write-Host -ForegroundColor Green "correct" $b.asset_tag 
        }
        else {
            Write-Host -ForegroundColor yellow "false" $b.asset_tag 
        }
    }
    else {
        Write-Host -ForegroundColor Red "false"
    }
}

我想为每个结果循环if语句。结果应该是这样的:

correct $asset_tag 
correct $asset_tag 
  false $asset_tag 
    .............. 

0 个答案:

没有答案