Last active
July 23, 2024 19:15
-
-
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`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(@" | |
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 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.