I have a string with structured data (see below). I need to take this string and convert it to an object, so I can export it to .csv (or whatever else is requested of me). I ran the following code:
$data = $string -replace "\s*:\s*","="
But my output looks like this:
City=Country=Department=DisplayName=John Doe
DistinguishedName=CN=John Doe, CN=Users, DC=domain, DC=com
[email protected]
Enabled=False
Fax=GivenName=John
MobilePhone=Name=John Doe
ObjectClass=user
ObjectGUID=cdb9a45c-80f4-4919-bf43-5db8d9ca83da
Office=OfficePhone=PostalCode=SamAccountName=jdoe
SID=S-1-5-21-2025429266-2000478354-1606980848-16934
State=StreetAddress=Surname=Doe
[email protected]
This is clearly not correct. What is a better way to make this conversion? I thought about using ConvertFrom-String with the TemplateContent parameter, but haven't been able to make that work yet.
Here are the first two entries in the string (which contains several users worth of data):
$string = @"
City :
Country :
Department :
DisplayName : John Doe
DistinguishedName : CN=John Doe,CN=Users,DC=domain,DC=com
EmailAddress : [email protected]
Enabled : False
Fax :
GivenName : John
MobilePhone :
Name : John Doe
ObjectClass : user
ObjectGUID : cdb9a45c-80f4-4919-bf43-5db8d9ca83da
Office :
OfficePhone :
PostalCode :
SamAccountName : jdoe
SID : S-1-5-21-2025429266-2000478354-1606980848-16934
State :
StreetAddress :
Surname : Doe
Title :
UserPrincipalName : [email protected]
City :
Country :
Department :
DisplayName : DiscoverySearchMailbox{D919BA15-46A6-415f-80AD-7E09334BB852}
DistinguishedName : CN=DiscoverySearchMailbox {D919BA15-46A6-415f-80AD-7E09334BB852},CN=Users,DC=domain,DC=com
EmailAddress : DiscoverySearchMailbox{D919BA15-46A6-415f-80AD-7E09334BB852}@domain.com
Enabled : False
Fax :
GivenName :
MobilePhone :
Name : DiscoverySearchMailbox{D919BA15-46A6-415f-80AD-7E09334BB852}
ObjectClass : user
ObjectGUID : 0f35137a-de93-472f-9114-5488a462d178
Office :
OfficePhone :
PostalCode :
SamAccountName : SM_2187102a90634829b
SID : S-1-5-21-2438891277-1009865731-3229889747-3109
State :
StreetAddress :
Surname : MsExchDiscoveryMailbox D919BA15-46A6-415f-80AD-7E09334BB852
Title :
UserPrincipalName : DiscoverySearchMailbox{D919BA15-46A6-415f-80AD-7E09334BB852}@domain.com
"@
Thanks.