If this script is run, it errors out with "operation couldn't be performed because object "object" couldn't be found on "domain controller."
Then it prompts for information:
"ExternalEmailAddress: "
If I enter an email address when it prompts for one it actually creates the contact with that external email address and sets the fowarding.
Script --
# Loop through the object returned by Import-Csv with each element represented by $personforeach ($person in (Import-Csv .\forwardtest.csv))
{
# Check the Mailbox for the person exists
If ((Get-Mailbox -ResultSize Unlimited $person.SamAccountName))
{
# Check the mail contact doesn't exist and if not add it
If (!(Get-MailContact $person.ForwardingAddress))
{
New-MailContact $person.ForwardingAddress -OrganizationalUnit "OU=tempusercontactsou,OU=Contacts,DC=domain,DC=local"
}
# Set the Forwarding Address on the Mailbox
Set-Mailbox $person.SamAccountName -DeliverToMailboxAndForward:$True -ForwardingAddress $person.ForwardingAddress
}
}
Any thoughts/ideas? I'm going to continue to play with this. It should use the "ForwardAddress" field in the CSV file to create the contact with an external address.
Thanks!