csv - Simplify Powershell Where-Object -
i have working import-csv statement uses where-object
import-csv d:\script\my.csv | where-object {$_.sourceip -like '10.251.22.11*' -or $_.sourceip -like '10.251.22.*' -or $_.destinationip -like '10.251.22.11*' -or $_.destinationip -like '10.251.22.*'}
if try simplify statement, doesn't work
import-csv d:\script\my.csv | where-object {($_.sourceip -like ('10.251.22.11*' -or '10.251.22.*')) -or ($_.destinationip -like ('10.251.22.11*' -or '10.251.22.*'))}
google not helping :-(
instead of -like, use -match in case.
import-csv d:\script\my.csv | where-object {$_.sourceip -match '^10\.251\.22\.*' -or $_.destinationip -match '^10\.251\.22\.*'}
also, 10.251.22.* match 10.251.22.11*, can combine them.
Comments
Post a Comment