I'm having some trouble with a script I've created and hoping someone can help. I need to create over 100 thousand 'Mail Contacts' and hide them from the Exchange Gal while creating them. I've been able to complete a script which creates the users and then sets the hidden from exchange list after creating the users, but would like to combine the commands together. I've added my script that is currently working below, I'm struggling with the syntax to make this one command.
get-mailcontact -organizationalunit "OU Path" -resultsize unlimited | Remove-Mailcontact -Confirm:$false
$Users = import-Csv "path to.csv"
$users | ForEach-object{New-MailContact -Name $_.Name -ExternalEmailAddress $_.ExternalEmailAddress -OrganizationalUnit "OU Path"}
get-mailcontact -OrganizationalUnit "OU Path" -resultsize unlimited | set-mailcontact -hiddenfromaddresslistsenabled $true