Exchange Server Forums

Forums | Register | Login | My Profile | Inbox | RSS RSS icon | My Subscription | My Forums | Address Book | Member List | Search | FAQ | Ticket List | Log Out

create mail contact for AD users

Users viewing this topic: none

Logged in as: Guest
  Printable Version
All Forums >> [Microsoft Exchange 2007] >> Management >> create mail contact for AD users Page: [1]
Login
Message << Older Topic   Newer Topic >>
Limited time MSExchange.org offer! -- 1.Sep.2008 1:00:00 PM
TechGenix and SolarWinds have partnered to provide free copies of SolarWinds Exchange Monitor to all visitors who join the MSExchange.org Forums. SolarWinds Exchange Monitor is a handy desktop dashboard that continuously monitors Microsoft Exchange to deliver real-time insight into Exchange services, mail queue sizes, and host server health. Learn more about Exchange Monitor and the free offer!
create mail contact for AD users - 2.Mar.2008 10:20:04 PM   
hankoll

 

Posts: 3
Joined: 29.Feb.2008
Status: offline
I am currently  migrating all users to Exchange.  I have the windowsemailaddress field populated for every AD user with their old email address.  What I want is to create a mail contact in the GAL for any user not on exchange but have this list updated daily as I move users to Exchange.  I can delete all mail contacts and run a script daily to "refresh" the list

Currently, I am doing a CSV export of AD fields and running this command to do a new-mailcontact.

Import-Csv C:\scripts\userexport.csv | foreach {New-MailContact -ExternalEmailAddress $_.mail -Name $_.sAMAccountName -displayname $_.displayname -alias $_.sAMAccountName -LastName $_.sn -FirstName $_.givenname -OrganizationalUnit "Contacts"}

This works fine, but is a manual process and I cannot destingush between exchange users and non-exchange users, so I have mailbox entry and mail contact entry for exchange users

I can run this command and get my user list:
get-user -OrganizationalUnit "OU=Users,DC=domain,DC=com" -ResultSize 100000 | where-object {$_.RecipientType -eq "User"} > C:\scripts\users.txt

which gives me a list of all users without exchange mailboxes - perfect.

How can I turn that output into a new-mailcontact command?

Post #: 1
RE: create mail contact for AD users - 7.Mar.2008 4:43:06 PM   
hankoll

 

Posts: 3
Joined: 29.Feb.2008
Status: offline
As an update, here is where I am now.  I assume that I am probably doing this much harder than I can probably do it with a carefully drafted powershell script, but it is "better" that where I was:

#run this command to export all members of the staff users group who do not have an exchange mailbox
(Get-Group "staff users").members | where { $_.Parent -eq "contoso.com/Some Users/Faculty and Staff" -or $_.Parent -eq "contoso.com/Some Users/Miis Disabled Users"} | Get-User | where { $_.RecipientType -eq "User"} | Export-Csv C:\scripts\staff_users.csv

#run this command to export all members of the student users group who do not have an exchange mailbox
(Get-Group "Student users").members | where { $_.Parent -eq "contoso.com/Some Users/Students" -or $_.Parent -eq "contoso.com/Some Users/Miis Disabled Users"} | Get-User | where { $_.RecipientType -eq "User"} | Export-Csv C:\scripts\student_users.csv

# Remove mail contacts before refresh
Get-MailContact -resultsize 100000 | where { $_.OrganizationalUnit -eq "contoso.com/Contacts/Students" -or  $_.OrganizationalUnit -eq "contoso.com/Contacts" } | remove-mailcontact

# remove row 1 from the csv then run the next command
Import-Csv C:\scripts\staff_users.csv | foreach {New-MailContact -ExternalEmailAddress $_.windowsemailaddress -Name $_.sAMAccountName -displayname $_.displayname -alias $_.sAMAccountName -LastName $_.lastname -FirstName $_.firstname -OrganizationalUnit "Contacts" }

# remove row 1 from the csv then run the next command
Import-Csv C:\scripts\student_users.csv | foreach {New-MailContact -ExternalEmailAddress $_.windowsemailaddress -Name $_.sAMAccountName -displayname $_.samaccountname -alias $_.sAMAccountName -LastName $_.lastname -FirstName $_.firstname -OrganizationalUnit "OU=Students,OU=Contacts,DC=contoso,DC=com"}

# Set CustomAttribute1 to Staff for the "Faculty and Staff Address List
Import-Csv C:\scripts\staff_users.csv | foreach {set-MailContact -identity $_.sAMAccountName -CustomAttribute1 "Staff"}

# Set customAttribute1 to Student for the "Students" Address List
Import-Csv C:\scripts\student_users.csv | foreach {set-MailContact -identity $_.sAMAccountName -CustomAttribute1 "Student"}

# Set customAttribute for all Exchange Mailboxes to Staff for the "Faculty and Staff Address List
Get-Mailbox | select identity | Set-Mailbox -CustomAttribute1 "Staff"

# Update all address lists
Get-AddressList | Update-AddressList

I only need to run this process until all the users are migrated to exchange.

Where I want to be....
I want to be able to run a command to remove a mail contact for all users who have an exchange mailbox.
I want to create a mail contact for an AD user who does not have one.
I want this to be a script I can run daily and I do not have to interact with.

As you can see, I have been working hard to figure this out and am not just "asking for a handout"  Any help will be greatly appreciated.  If I figure it out before someone answers it, I will post my updates.

(in reply to hankoll)
Post #: 2
RE: create mail contact for AD users - 7.Mar.2008 7:12:17 PM   
t0ta11ed

 

Posts: 274
Joined: 2.Feb.2007
From: Mars
Status: offline
Since Exchange's underlying command line interface is Powershell, that and Task Scheduler will be your friend....

_____________________________

Invasion Plans - http://dev.marzopolis.com

(in reply to hankoll)
Post #: 3
RE: create mail contact for AD users - 9.Mar.2008 4:51:15 PM   
hankoll

 

Posts: 3
Joined: 29.Feb.2008
Status: offline
Problem is, my csv export requires that I delete the first row of the csv for the import to work.

I guess my real question is...
how can I get the output from this command:

(Get-Group "staff users").members | where { $_.Parent -eq "contoso.com/Some Users/Faculty and Staff" -or $_.Parent -eq "contoso.com/Some Users/Miis Disabled Users"} | Get-User | where { $_.RecipientType -eq "User"}

Into this command:

New-MailContact -ExternalEmailAddress $_.windowsemailaddress -Name $_.sAMAccountName -displayname $_.samaccountname -alias $_.sAMAccountName -LastName $_.lastname -FirstName $_.firstname -OrganizationalUnit "OU=Students,OU=Contacts,DC=contoso,DC=com"

the only way I have found is to export to CSv because every time I try to pipeline, I get null variables.


< Message edited by hankoll -- 9.Mar.2008 10:26:12 PM >

(in reply to t0ta11ed)
Post #: 4

Page:   [1] << Older Topic    Newer Topic >>
All Forums >> [Microsoft Exchange 2007] >> Management >> create mail contact for AD users Page: [1]
Jump to:

New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts