As @Theo mentioned, the problem is definitely in the comparison operator -ne
. @Theo's comment is an acceptable solution, but I'd point out there's a lot of unnecessary stuff going on here. Import-Csv
already outputs PSCustomObjects, there's no reason to create new objects inside a ForEach-Object
loop. Once that's realized you can condense this to a single pipeline like:
Import-CSv 'C:ITInventory.csv' |
Where-Object{ $_.SystemName -notmatch '^HP' } |
Export-Csv -NoTypeInformation -Path 'C:ITInventory-New.csv'
Note: Even if you needed objects with only a subset of the original properties I'd use Select-Object
before resorting to creating new objects. Select-Object
also outputs PSCustomObjects.
In above sample I used -notmatch
with the RegEx anchor ^
. The Where clause effectively means where doesn't start with "HP". However, that's just for demonstration sake. -notlike "*HP*"
or "HP*"
may work just as well all depending on your data.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…