Skip to content

Instantly share code, notes, and snippets.

@JJK96
Created June 21, 2023 13:07
Show Gist options
  • Save JJK96/d8a7998606d23c1b911cb1c62401b509 to your computer and use it in GitHub Desktop.
Save JJK96/d8a7998606d23c1b911cb1c62401b509 to your computer and use it in GitHub Desktop.
Powershell Convert list of : separated fields to actual objects
/* Input example
Name: test
A: abc
B: def
Name: obj2
A: xyz
B: abc
*/
function to-objects {
BEGIN {
$object = New-Object -TypeName PSCustomObject
}
process {
if($_ -ne ""){
$key, $value = $_ -split ":"
$object | Add-Member -MemberType NoteProperty -Name $key -Value $value.Trim()
}
else {
Write-Output $object
$object = New-Object -TypeName PSCustomObject
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment