Adding bulk contacts in Excahnge 2007 and hiding automatically
Hi I have the following script to create contacts in Bulk Import-Csv Contacts.csv | ForEach { New-MailContact -Name $_.DisplayName -ExternalEmailAddress $_.EmailAddress -OrganizationalUnit "MailContacts" } Can this be piped to another command that will hide all contacts when they are created Thanks
April 15th, 2012 6:59am

On Sun, 15 Apr 2012 10:54:19 +0000, exchinfo wrote: > > >Hi > >I have the following script to create contacts in Bulk > >Import-Csv Contacts.csv | ForEach { New-MailContact -Name $_.DisplayName -ExternalEmailAddress $_.EmailAddress -OrganizationalUnit "MailContacts" } > >Can this be piped to another command that will hide all contacts when they are created > Import-Csv Contacts.csv | ForEach { $c = New-MailContact -Name $_.DisplayName -ExternalEmailAddress $_.EmailAddress -OrganizationalUnit "MailContacts"; Set-MailContact $c.distinguishedname -HiddenFromAddressListsEnabled } You should add the "-domaincontroller <server>" to the new-mailcontact and set-mailcontact commands if you have multiple DCs. Otherwise it's possible, well "probable", that the 'new' and 'set' commands will use a different DC and the set will fail because replication hasn't had time enough to replicate the AD modification. --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
April 15th, 2012 5:36pm

Import-Csv Contacts.csv | ForEach { $c = New-MailContact -Name $_.DisplayName -ExternalEmailAddress $_.EmailAddress -OrganizationalUnit "MailContacts"; Set-MailContact $c.distinguishedname -HiddenFromAddressListsEnabled } Good point. But seems like you have to add a value($True) to property -HiddenFromAddressListsEnabled. Set-MailContact $c.distinguishedname -HiddenFromAddressListsEnabled $true Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.Frank Wang TechNet Community Support
April 16th, 2012 4:08am

On Mon, 16 Apr 2012 08:03:18 +0000, Frank.Wang wrote: >Import-Csv Contacts.csv | ForEach { $c = New-MailContact -Name $_.DisplayName -ExternalEmailAddress $_.EmailAddress -OrganizationalUnit "MailContacts"; Set-MailContact $c.distinguishedname -HiddenFromAddressListsEnabled } > >Good point. But seems like you have to add a value($True) to property -HiddenFromAddressListsEnabled. Well, that would be a direct contradiction to the Powershell syntax that states the presence of the "[switch]" implies a value of "$true". >Set-MailContact $c.distinguishedname -HiddenFromAddressListsEnabled $true This, too, is incorrect. A "[switch]" desn't take any parameters. If you're going to provide a value to the [switch] then is should be separated from the [switch] with a colon. E.g.: -HiddenFromAddressListsEnabled:$true --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
April 16th, 2012 6:15pm

Anyhow, both cmdlets work in my test lab. Set-MailContact $c.distinguishedname -HiddenFromAddressListsEnabled $true Set-MailContact $c.distinguishedname -HiddenFromAddressListsEnabled:$true Hi exchinfo, any updates?Frank Wang TechNet Community Support
April 16th, 2012 10:59pm

Anyhow, both cmdlets work in my test lab. Set-MailContact $c.distinguishedname -HiddenFromAddressListsEnabled $true Set-MailContact $c.distinguishedname -HiddenFromAddressListsEnabled:$true Hi exchinfo, any updates?Frank Wang TechNet Community Support
Free Windows Admin Tool Kit Click here and download it now
April 17th, 2012 5:53am

On Tue, 17 Apr 2012 02:53:44 +0000, Frank.Wang wrote: > > >Anyhow, both cmdlets work in my test lab. I didn't say that they didn't work. I said that the correct way to make a switch return a $true or $false value is to follow the switch name with a colon and then the boolean value. I think you'll find that some cmdlets don't work if you don't do that. Chalk it up to the immaturity of the language and to the inconsistent implementation of cmdlets. What I also said was that if simply using the switch (-HiddenFromAddressListsEnabled in this case) works differently to following the switch name with "$true" then something in the cmdlet (or Powershell) is broken and needs to be bugged. >Set-MailContact $c.distinguishedname -HiddenFromAddressListsEnabled $true > >Set-MailContact $c.distinguishedname -HiddenFromAddressListsEnabled:$true --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
April 17th, 2012 10:21pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics