Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Script create contact and set forwarding address (script doesn't seem to use csv for "ExternalEmailAddress" to create contact).

$
0
0

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 $person
foreach ($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!


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>