0

With some help I was able to import the .CSV file and read the first and last row elements, but I want to assign only the batch id to a variable, but when I include it in a email body, I get the whole object rather than value.

    $getBatchIds=(Import-csv $file.FullName)
    $firstElement= $getBatchIds | Select-Object -First 1 batch_id
    $lastElement= $getBatchIds | Select-Object -Last 1  batch_id

$getBatchIds to import the file

$firstElement $lastElement to get the last row elements

This is the object that is included in the email body, that assigns them to individual variables and I output them in the email body

1       12-06-2019 07:54:47 @{Batch_Id=2129475} @{Batch_Id=2138701}

2       11-06-2019 09:40:41 @{Batch_Id=2103516} @{Batch_Id=2129456}
1
  • 1
    what is the question? i don't understand your post ... [blush] Commented Jun 13, 2019 at 8:54

1 Answer 1

1

Use -ExpandProperty:

$getBatchIds  = Import-Csv -Path $file.FullName
$firstElement = $getBatchIds | Select-Object -First 1 -ExpandProperty "batch_id"
$lastElement  = $getBatchIds | Select-Object -Last 1 -ExpandProperty "batch_id"
Sign up to request clarification or add additional context in comments.

Comments

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.