Skip to content

Instantly share code, notes, and snippets.

@bielawb
Created September 18, 2014 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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/adam@nowacki.pl]
[sluzbowy/AdamNowacki@firma.pl]
=
Anna Kowalska
Domowy:123 456 789
Komorka:999 999 999
[prywatny/ania@wp.pl]
[sluzbowy/Anna.Kowalska@firma.pl]
=
Wojciech Malinowski
Komorka:123 456 789
Praca:999 999 999
[prywatny/wojtek@op.pl]
[sluzbowy/Wojciech.Malinowski@firma.pl]
'@
$template = @'
=
{f*:Adam} {l:Nowacki}
{tel:{t*:Domowy}:{n:123 456 789}
{t*:Praca}:{n:999 999 999}}
{mail:[{mt*:prywatny}/{m:wojtek@op.pl}]
[{mt*:sluzbowy}/{m:Wojciech.Malinowski@firma.pl}]}
=
{f*:Anna} {l:Kowalska}
{tel:{t*:Domowy}:{n:123 456 789}
{t*:Komorka}:{n:999 999 999}}
{mail:[{mt*:prywatny}/{m:ania@wp.pl}]
[{mt*:sluzbowy}/{m:Anna.Kowalska@firma.pl}]}
'@
$data | cfs -tc $template | fc
<# Output:
class PSCustomObject
{
ExtentText = Adam Nowacki
Domowy:123 456 789
Praca:999 999 999
[prywatny/adam@nowacki.pl]
[sluzbowy/AdamNowacki@firma.pl]
=
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/adam@nowacki.pl]
[sluzbowy/AdamNowacki@firma.pl]
Items =
[
class PSCustomObject
{
ExtentText = prywatny/adam@nowacki.pl]
[
mt = prywatny
m = adam@nowacki.pl
}
class PSCustomObject
{
ExtentText = sluzbowy/AdamNowacki@firma.pl]
mt = sluzbowy
m = AdamNowacki@firma.pl
}
]
}
}
class PSCustomObject
{
ExtentText = Anna Kowalska
Domowy:123 456 789
Komorka:999 999 999
[prywatny/ania@wp.pl]
[sluzbowy/Anna.Kowalska@firma.pl]
=
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/ania@wp.pl]
[sluzbowy/Anna.Kowalska@firma.pl]
Items =
[
class PSCustomObject
{
ExtentText = prywatny/ania@wp.pl]
[
mt = prywatny
m = ania@wp.pl
}
class PSCustomObject
{
ExtentText = sluzbowy/Anna.Kowalska@firma.pl]
mt = sluzbowy
m = Anna.Kowalska@firma.pl
}
]
}
}
class PSCustomObject
{
ExtentText = Wojciech Malinowski
Komorka:123 456 789
Praca:999 999 999
[prywatny/wojtek@op.pl]
[sluzbowy/Wojciech.Malinowski@firma.pl]
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/wojtek@op.pl]
[sluzbowy/Wojciech.Malinowski@firma.pl]
t = Praca
n = 999 999 999
}
]
}
mail =
class PSCustomObject
{
ExtentText = [prywatny/wojtek@op.pl]
[sluzbowy/Wojciech.Malinowski@firma.pl]
Items =
[
class PSCustomObject
{
ExtentText = prywatny/wojtek@op.pl]
[
mt = prywatny
m = wojtek@op.pl
}
class PSCustomObject
{
ExtentText = sluzbowy/Wojciech.Malinowski@firma.pl]
mt = sluzbowy
m = Wojciech.Malinowski@firma.pl
}
]
}
}
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment