Skip to content

Instantly share code, notes, and snippets.

@B-Art
Last active July 23, 2024 19:15
Show Gist options
  • Save B-Art/4b64c2490bfc508b610d14a39fb5f4cc to your computer and use it in GitHub Desktop.
Save B-Art/4b64c2490bfc508b610d14a39fb5f4cc to your computer and use it in GitHub Desktop.
#Powershell #Pwsh #Core SplitANDconcer `Transform a list of Named Values into an object`
(@"
naam: ZBVAHAP001
SN: CNGHJSS8S2
Mac: B0B367C976F0
Naam: ZBVAHAP010
SN: CNG7JSSJ2G
Mac: 904C81C8AC22
Naam: ZBVAHAP009
SN: CNGHJSS8RM
MAC: B0B867C97A4E
"@).replace( "`n","`"`n" ).split( "`n" ).replace( ': ', '="' ) | ForEach-Object { $i=0; $c=''; $d=@() }{ if (++$i % 3 -eq 0){ $c += $_; $d += Invoke-Expression "[pscustomobject]@{$c}"; $c='' } else { $c += "$_;" } } { $d }
@B-Art
Copy link
Author

B-Art commented Nov 14, 2023

If you have a certain amount of rows of key v.s. value (in this case every 3 lines). This code can help transform it into an array object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment