Question:
How can I convert the below exported text to csv so that i can use it as objects in powershell. Eg:
1 2 |
where{$_.qlimit -eq 27} |
Text:
1 2 3 4 5 6 7 8 |
samid qlimit qused Administrator -1 0 Guest -1 0 admin 27 8 krbtgt -1 0 r -1 0 admin2 44 0 |
Answer:
Use the Get-Content cmdlet to load the file, replace two or more whitespaces with a comma and convert it to CSV
using the ConvertFrom-Csv cmdlet:
1 2 |
$object = (Get-Content 'your_file').Trim() -replace '\s{2,}', ',' | ConvertFrom-Csv |
If you now query your object:
1 2 |
$object | where qlimit -eq 27 |
You get the desired output:
1 2 3 4 |
samid qlimit qused ----- ------ ----- admin 27 8 |