I got a problem with understanding of output CSV file from powershell script!
I have a Request to restapi server and I'm getting a variable which contain 10 or more lines, like:
>$ExpenseDescription
Taxi to airport
Taxi to seaport
Taxi to spaceport
Taxi to home
And the I'm creating table
$tableExpenses=@"
Created On | Description | Expense Category
$ExpenseCreatedOnt | $ExpenseDescription |$ExpenseReport
$tableExpense|Out-File C:\Users\book.xls
$tableExpense|Out-File C:\Users\book.csv
And as output file I'm getting .xls and .csv!
So the problem is that I have 10 lines in variable $ExpenseDescriptionand the OutFile contain all 10 lines in 1 cell in book.xls!
How can I split them in code and make OutFile in format like this:
Created On | Description | Expense Category
10.10.2018|Taxi to airport| Money
11.10.2018|Taxi to seaport| Visa
Because now I'm having this in output
Created On | Description | Expense Category
10.10.2018 11.10.2018|Taxi to airport Taxi to seaport| Money Visa|
OK, I'll add more code)
WebRequest
$ReportURI = ("https://api.rest.com/data/query")
$ReportQuery =
@{"q"="SELECT Category,Description,CreatedOn from Expense"}
Try
{$ResponseReport = Invoke-RestMethod -Method Post -Uri $ReportURI -Headers @{"Authorization" = $SessionId} -Body ( $ReportQuery | ConvertTo-Json) -ContentType "application/json" -ErrorAction Stop}
Write-Host $ResponseReport}
ConvertTo-Json $ResponseReport
variables
$ExpenseCreatedOn = $ResponseReport.CreatedOn
$ExpenseDescription = $ResponseReport.Description
$ExpenseReport = $ResponseReport.Category.Name
table_format
$tableExpense=@"
Created On Description Expense Category
$ExpenseCreatedOn $ExpenseDescription $ExpenseReport
$tableExpense|Out-File C:\Users\book.xls
$tableExpense|Out-File C:\Users\book.csv