Skip to content

Instantly share code, notes, and snippets.

@bielawb
Created September 18, 2014 22:08
Show Gist options
  • Save bielawb/4a716f46156d87805672 to your computer and use it in GitHub Desktop.
Save bielawb/4a716f46156d87805672 to your computer and use it in GitHub Desktop.
ConvertFrom-String - nested properties (improved).
$data = @'
=
Adam Nowacki
Domowy:123 456 789
Praca:999 999 999
[prywatny/[email protected]]
[sluzbowy/[email protected]]
=
Anna Kowalska
Domowy:123 456 789
Komorka:999 999 999
[prywatny/[email protected]]
[sluzbowy/[email protected]]
=
Wojciech Malinowski
Komorka:123 456 789
Praca:999 999 999
[prywatny/[email protected]]
[sluzbowy/[email protected]]
'@
$template = @'
=
{f*:Adam} {l:Nowacki}
{tel:{t*:Domowy}:{n:123 456 789}
{t*:Praca}:{n:999 999 999}}
{mail:[{mt*:prywatny}/{m:[email protected]}]
[{mt*:sluzbowy}/{m:[email protected]}]}
=
{f*:Anna} {l:Kowalska}
{tel:{t*:Domowy}:{n:123 456 789}
{t*:Komorka}:{n:999 999 999}}
{mail:[{mt*:prywatny}/{m:[email protected]}]
[{mt*:sluzbowy}/{m:[email protected]}]}
'@
$data | cfs -tc $template | fc
<# Output:
class PSCustomObject
{
ExtentText = Adam Nowacki
Domowy:123 456 789
Praca:999 999 999
[prywatny/[email protected]]
[sluzbowy/[email protected]]
=
f = Adam
l = Nowacki
tel =
class PSCustomObject
{
ExtentText = Domowy:123 456 789
Praca:999 999 999
Items =
[
class PSCustomObject
{
ExtentText = Domowy:123 456 789
t = Domowy
n = 123 456 789
}
class PSCustomObject
{
ExtentText = Praca:999 999 999
t = Praca
n = 999 999 999
}
]
}
mail =
class PSCustomObject
{
ExtentText = [prywatny/[email protected]]
[sluzbowy/[email protected]]
Items =
[
class PSCustomObject
{
ExtentText = prywatny/[email protected]]
[
mt = prywatny
m = [email protected]
}
class PSCustomObject
{
ExtentText = sluzbowy/[email protected]]
mt = sluzbowy
m = [email protected]
}
]
}
}
class PSCustomObject
{
ExtentText = Anna Kowalska
Domowy:123 456 789
Komorka:999 999 999
[prywatny/[email protected]]
[sluzbowy/[email protected]]
=
f = Anna
l = Kowalska
tel =
class PSCustomObject
{
ExtentText = Domowy:123 456 789
Komorka:999 999 999
Items =
[
class PSCustomObject
{
ExtentText = Domowy:123 456 789
t = Domowy
n = 123 456 789
}
class PSCustomObject
{
ExtentText = Komorka:999 999 999
t = Komorka
n = 999 999 999
}
]
}
mail =
class PSCustomObject
{
ExtentText = [prywatny/[email protected]]
[sluzbowy/[email protected]]
Items =
[
class PSCustomObject
{
ExtentText = prywatny/[email protected]]
[
mt = prywatny
m = [email protected]
}
class PSCustomObject
{
ExtentText = sluzbowy/[email protected]]
mt = sluzbowy
m = [email protected]
}
]
}
}
class PSCustomObject
{
ExtentText = Wojciech Malinowski
Komorka:123 456 789
Praca:999 999 999
[prywatny/[email protected]]
[sluzbowy/[email protected]]
f = Wojciech
l = Malinowski
tel =
class PSCustomObject
{
ExtentText = Komorka:123 456 789
Praca:999 999 999
Items =
[
class PSCustomObject
{
ExtentText = Komorka:123 456 789
t = Komorka
n = 123 456 789
}
class PSCustomObject
{
ExtentText = Praca:999 999 999
[prywatny/[email protected]]
[sluzbowy/[email protected]]
t = Praca
n = 999 999 999
}
]
}
mail =
class PSCustomObject
{
ExtentText = [prywatny/[email protected]]
[sluzbowy/[email protected]]
Items =
[
class PSCustomObject
{
ExtentText = prywatny/[email protected]]
[
mt = prywatny
m = [email protected]
}
class PSCustomObject
{
ExtentText = sluzbowy/[email protected]]
mt = sluzbowy
m = [email protected]
}
]
}
}
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment