Author Posts

July 30, 2014 at 11:06 am

Please understand that I am in the process of learning Powershel.
Thank you

$comments = @'

Purpose: How Export Users Contacts for Email Migration
'@
#——————————————————–
$TempPath="$env:Userprofile\appdata\local\microsoft\outlook\"
$strname=$env:username
#New-Item c:\myscripts\output -type directory
New-Item \\x.x.x.x\backupemail\users\$strname -ItemType directory
New-Item \\x.x.x.x\backupemail\users\$strname\contacts -ItemType directory
$Outlook=NEW-OBJECT –comobject Outlook.Application

$Contacts=$Outlook.session.GetDefaultFolder(10).items

$Contacts | Format-Table FullName,CompanyName,JobTitle,FileAs,Email1Address,WebPage,IMAddress,BusinessTelephoneNumber,BusinessFaxNumber,MobileTelephoneNumber,BusinessAddress | out-file \\x.x.x.x.\backupemail\users\$strname\contacts\contacts.txt

July 30, 2014 at 11:11 am

Out-File presents information basically exactly as it would show up at the console (including using the same console width, if I remember correctly.) If you want to allow really long lines in the file, you can pass a large value to Out-File's -Width parameter. Or, alternatively, you could use something like a CSV file instead. The difference there would be whether you intend for a script or program to read this data later, or if it's meant to be more readable for people instead. Format-Table produces a human-readable format, but one that would be very annoying to have to read in with a script. CSV is intended for programs and scripts to parse, and can be opened directly with programs like Microsoft Excel.

out-file \\x.x.x.x.\backupemail\users\$strname\contacts\contacts.txt -Width 100000

July 30, 2014 at 11:23 am

Dave,
Thank you for the wealth of information. You are correct I will want to read the data back in after.
So If I am understanding this correctly I should be changing this line to something else to import the information back in later.

$Contacts | Format-Table FullName,CompanyName,JobTitle,FileAs,Email1Address,WebPage,IMAddress,BusinessTelephoneNumber,BusinessFaxNumber

July 30, 2014 at 11:26 am

Yep. Instead of Format-Table, you would use Select-Object, and then pipe the results to Export-Csv instead of Out-File. That would allow you to use Import-Csv on the file later (or to open it with Excel.)

In this example, I've split the command into multiple lines to make it a bit easier to read:

$properties = 'FullName','CompanyName','JobTitle','FileAs','Email1Address','WebPage','IMAddress','BusinessTelephoneNumber','BusinessFaxNumber'

$Contacts |
Select-Object -Property $properties |
Export-Csv -NoTypeInformation -Path \\x.x.x.x.\backupemail\users\$strname\contacts\contacts.csv

July 30, 2014 at 12:13 pm

Dave,
Thank you for the code. I will take a look at this in 30 min or first thing tomorrow.