none
Adding bulk contacts in Excahnge 2007 and hiding automatically RRS feed

  • Question

  • 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

    Sunday, April 15, 2012 10:54 AM

Answers

  • 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
    • Proposed as answer by emma.yoyo Monday, April 16, 2012 8:03 AM
    • Marked as answer by emma.yoyo Monday, April 23, 2012 2:03 AM
    Sunday, April 15, 2012 9:30 PM
  • 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

    • Marked as answer by emma.yoyo Monday, April 23, 2012 2:03 AM
    Tuesday, April 17, 2012 2:53 AM

All replies

  • 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
    • Proposed as answer by emma.yoyo Monday, April 16, 2012 8:03 AM
    • Marked as answer by emma.yoyo Monday, April 23, 2012 2:03 AM
    Sunday, April 15, 2012 9:30 PM
  • 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

    Monday, April 16, 2012 8:03 AM
  • 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
    Monday, April 16, 2012 10:09 PM
  • 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

    • Marked as answer by emma.yoyo Monday, April 23, 2012 2:03 AM
    Tuesday, April 17, 2012 2:53 AM
  • 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
    Wednesday, April 18, 2012 2:15 AM
  • I couldn't get the syntax to work using the $c.distinguishedname parameter, so I ended up using -Identity instead.  Example: import-csv c:\contact.csv | ForEach-Object {New-Mailcontact -FirstName $_.FirstName -Lastname $_.Lastname -Name$_.DisplayName -OrganizationalUnit $_.OrgUnit -ExternalEmailAddress $_.ExternalEmailAddress;Set-MailContact -Identity $_.DisplayName -HiddenFromAddressListsEnabled:$True}
    Monday, January 29, 2018 11:02 PM