0

I am trying to read the data and write it into a .txt file using PowerShell.

But the in the result it get trimmed.

#Get the photo path of the students 
$commandAD = $connection.CreateCommand()

#Retrieving student photo records.
$commandAD.CommandText = "SELECT [Barcode],[ImageURL]   FROM 
[iSAMS_Custom].[dbo].[vwDestinyLibrary_Student_photo1]"
$resultPhoto = $commandAD.ExecuteReader()
$tablePhoto = new-object "System.Data.DataTable"
$tablePhoto.Load($resultPhoto)

#Export Hash Table to Txt File
$tablePhoto | Out-File c:\Users\nimmy.pk\Documents\inputphoto.txt 

How I can format the data?

2
  • Maybe save it as a csv, it seems like the object is a table Commented Oct 19, 2017 at 9:06
  • I need the result as in txt format Commented Oct 19, 2017 at 9:07

1 Answer 1

2

You can use the -Width parameter from Out-File:

$tablePhoto | Out-File -Width 4096 -Path c:\Users\nimmy.pk\Documents\inputphoto.txt
Sign up to request clarification or add additional context in comments.

3 Comments

now the url showing completely, but all the results showing in a single column rather than in two.
I tried to delete the blank spaces between the columns but it doesn't work :( ... I am quite new to PowerShell and recently started learning. Anyone can help on the formatting of the output file to see the full result???
The use a CSV like @guiwhatsthat mentioned, $tablePhoto | Export-CSV -delimiter "`t" -path c:\Users\nimmy.pk\Documents\inputphoto.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.