我想在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
..............