Turncated Issue on outfile

This topic contains 4 replies, has 2 voices, and was last updated by  Chat Only 3 years ago.

  • Author
  • #17627

    Chat Only

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

    $comments = @'

    Purpose: How Export Users Contacts for Email Migration
    #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 | 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

  • #17630

    Dave Wyatt

    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
  • #17632

    Chat Only

    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

  • #17634

    Dave Wyatt

    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
  • #17642

    Chat Only

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

You must be logged in to reply to this topic.