Create a table-like custom object from a variable with CSV content

Biju Mathew 481 Reputation points
2023-01-30T01:12:41.1666667+00:00

Hi,

I have contents in a variable called $file

echo $file gives this

Timestamp,Category,OperationName

2022-10-26 19:21:23.5114273,Warning,Insert

2022-10-26 19:21:23.5114273,Warning,Update

As you see, the variable is really a CSV.

I want to create a table-like custom object from this variable. Similar to what Import-Csv does - but Import-Csv requires you to read from a file on disk. I want to achieve the same from a variable.

Please can someone help.

Thanks

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,517 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,489 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Biju Mathew 481 Reputation points
    2023-01-30T01:27:35.5066667+00:00

    I got this.

    $p=ConvertFrom-Csv -InputObject $file -Delimiter ','

    0 comments No comments

  2. Biju Mathew 481 Reputation points
    2023-01-30T01:47:14.2566667+00:00

    yeah, i got this

    $p=ConvertFrom-Csv -InputObject $file -Delimiter ','

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.