基于导出文件和一些检查我正在使用以下代码块创建一个数组:
$Result += New-Object PSObject -Property @{
FQDN = $($Server.FQDN)
IP = $($Server.IP)
Description = $($Server.Description)
Remarks = $("")
}
当我重复使用此$ Result时,如果要进行其他检查,如何在“备注”属性中添加额外信息?
If ($Result.IP.Contains($IP.number)){
$Result.Remarks += "Attention for this server" | Where-Object $Result.IP -eq $IP.number
}
答案 0 :(得分:0)
您需要遍历$Result
数组并使用正确的IP
值修改特定元素:
# Loop through array
$Result = foreach($object in $Result)
{
# Check if array element is interesting
if($object.IP -eq $IP.Number)
{
# Modify the object in question
$object.Remarks += "Attention!"
}
# Write the (potentially modified) object back to the array
$object
}