Convert LDIF group file to CSV
hi!
here's ldif file. it's file listing group , theres members:
dn: dn1
ufn: ufn1
member: member1
member: member2
member: member3
cn: cn1
dn: dn2
ufn: ufn2
member: member1
member: member2
cn: cn2
dn: dn3
ufn: ufn3
member: member1
member: member2
member: member3
member: member4
cn:
i need convert file csv file ";" separated:
"dn";"ufn";"member";"cn"
"dn1";"ufn1";"member1";"cn1"
"dn1";"ufn1";"member2";"cn1"
"dn1";"ufn1";"member3";"cn1"
"dn2";"ufn2";"member1";"cn2"
"dn2";"ufn2";"member2";"cn2"
"dn3";"ufn3";"member1";""
"dn3";"ufn3";"member2";""
"dn3";"ufn3";"member3";""
"dn3";"ufn3";"member4";""
i can catch dn, ufn , cn .split problem catch multiple member.
thx help
$lines=@' dn: dn1 ufn: ufn1 member: member1 member: member2 member: member3 cn: cn1 dn: dn2 ufn: ufn2 member: member1 member: member2 cn: cn2 dn: dn3 ufn: ufn3 member: member1 member: member2 member: member3 member: member4 cn: cn3 '@ -split "`n" $lines| foreach-object{ $name,$value=$_ -split ':' switch ($name){ 'dn' { if($cn){ $members|%{ $p=@{dn=$dn;member=$_;cn=$cn} new-object psobject -property $p } $cn=$null $members=@() } $dn=$value } 'member' {$members+=$value} 'cn' {$cn=$value} } }
¯\_(ツ)_/¯
Windows Server > Windows PowerShell
Comments
Post a Comment