Output import results - using PS1 script
I was asked to import over 1000 mail contacts which I was able to do... for the most part. However, as a certain number of contacts were already in the global address list, there were errors. This is because our mail contacts can have various statuses: Friend, Neighbor, Parent, etc. (just making those up, OK?) So, if a contact is already included as a "friend" (and located in the "Friends" OU), they cannot be imported again, at least not with the very same SMTP address, as a "neighbor" in the "Neighbors" OU. I want to output the operations that fill the screen of EMS as they are performed, but take up so much space that I can only see the last operations performed (first in, first out). So just to make sure I get all the errors listed, I want to output this to a file as well. Here's my script (just below). Import-CSV "F:\Scripts\NewContacts.csv" | ForEach { New-MailContact -Name $_.displayName -FirstName $_.givenName -LastName $_.sn -ExternalEmailAddress $_.mail -OrganizationalUnit "contoso.com/EmailContacts" } Where should I put... out-file C:\ImportOp1.txt ??? Inside brackets, right? And just at the end? But wait, I don't want PS to do this once for each entry. I want ONE .txt file displaying the overall results of the operation. So outside the brackets? Would test this myself on a practice server but only have a E2K3 machine available for the moment. Might try a small test group on the production server but thought I'd ask here too. Don't like "testing" too much on a production server...
September 20th, 2011 3:30pm

Inside the curly braces you can add a semicolon to the end of the command that's in there and add a second command that executes afterward, or you can put the next command on the next line. However that Out-File won't do what you want it to do. What you want instead is the following. Import-CSV "F:\Scripts\NewContacts.csv" | ForEach { New-MailContact -Name $_.displayName -FirstName $_.givenName -LastName $_.sn -ExternalEmailAddress $_.mail -OrganizationalUnit "contoso.com/EmailContacts" 2>> C:\ImportOp1.txt } The 2>> operator redirects the error stream, in this case appending the file. http://technet.microsoft.com/en-us/library/dd315283.aspx Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
Free Windows Admin Tool Kit Click here and download it now
September 20th, 2011 3:46pm

Hi, Please update. ThanksSophia Xu
September 21st, 2011 10:17pm

It looks like adding thousands of contacts to the GAL is not the best choice: http://social.technet.microsoft.com/Forums/en-US/exchangesvradmin/thread/22fde8ad-4fc4-4bac-bb52-188c84ea5b63 But the answer will be useful for my scripting in the future.
Free Windows Admin Tool Kit Click here and download it now
September 22nd, 2011 8:39am

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

Other recent topics Other recent topics