Powershell scripting using where-object -
i trying write powershell script exchange management shell, importing list of contacts csv file distribution group.
i start out with
import-csv c:\filename.csv | foreach-object {new-mailcontact .......}
this works well, except entries in csv file have blank email address, , create teh new contact craps out because externalemailaddress blank. so, tried:
import-csv c:\filename.csv | foreach-object { where-object {$_.externalemailaddress -ne "" } | new-mailcontact -name $_.name -externalemailaddress $_.externalemailaddress....}
but didn't seem work - didn't filter out entries blank email addresses.
what doing wrong?
i think might want use where-object
prior foreach-object
because filter objects passed along pipeline.
depending on new-mailcontact cmdlet supports might able pipe results directly or may have pass them 1 one.
all @ once (not using foreach-object
):
import-csv c:\filename.csv | where-object {$_.externalemailaddress -ne "" } | new-mailcontact -name $_.name -externalemailaddress $_.externalemailaddress }
one 1 (by using foreach-object
):
import-csv c:\filename.csv | where-object {$_.externalemailaddress -ne "" } | foreach-object { new-mailcontact -name $_.name -externalemailaddress $_.externalemailaddress }
Comments
Post a Comment