Last active
October 15, 2025 17:08
-
-
Save 1RedOne/ebd7147f377738694446064a7768deef to your computer and use it in GitHub Desktop.
ConvertTo-StringData - Converting a complex object into StringData
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
| Function ConvertTo-StringData($object, $propertyOverride){ | |
| $fields = $object | get-member -MemberType NoteProperty | |
| foreach($field in $fields){ | |
| if (IsArray($field)){ | |
| OutputArrayMember -object $object -field $field | |
| } | |
| else{ | |
| OutputMember -object $object -propertyName $field.name -propertyOverride $propertyOverride | |
| } | |
| } | |
| } | |
| Function IsArray($object){ | |
| $object.Definition -match '.*\[\].*' | |
| } | |
| Function OutputMember($object,$propertyName, $propertyOverride){ | |
| if ($propertyOverride){ | |
| "$($propertyOverride).$($propertyName)=$($object.$($propertyName))" | |
| } | |
| else{ | |
| "$($propertyName)=$($object.$($propertyName))" | |
| } | |
| } | |
| Function OutputArrayMember($object, $field){ | |
| $global:testObject = $object | |
| $global:testfield = $field | |
| $base = $field.Name | |
| $i = 0 | |
| foreach ($item in $object.$($field.Name)){ | |
| ConvertTo-StringData -object $object.$($field.Name)[$i] -propertyOverride "$base[$i]" | |
| $i++ | |
| } | |
| } | |
| Function Drill ($object, $parentPath){ | |
| if ($null -ne $parentPath){ | |
| $parentPath = $parentPath+$function:parentPath | |
| $parentPath = $parentPath.TrimStart('.') | |
| } | |
| $parentPath | |
| #select next leaf | |
| if (hasChildren $object){ | |
| "drilling down into $object" | |
| $props = GetNoteProperties $object | |
| $var = getObjectByProperty $object $props | |
| drill $var -parentPath "$($parentPath).$($props.Name)" | |
| } | |
| else{ | |
| ConvertTo-StringData -object $object -propertyOverride $parentPath | |
| $global:test = $object | |
| } | |
| } | |
| Function hasChildren($object){ | |
| [bool](($object | gm -MemberType NoteProperty).Definition -match 'System.Management.Automation.PSCustomObject') | |
| } | |
| function GetNoteProperties($object){ | |
| get-member -InputObject $object -MemberType NoteProperty | |
| } | |
| function getObjectByProperty($object, $propertyName){ | |
| $object.$($propertyName.Name) | |
| } |
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
| $json ='{ | |
| "name": "John", | |
| "age": 30, | |
| "married": true, | |
| "cars": [ | |
| {"model": "BMW 230", "mpg": 27.5}, | |
| {"model": "Ford Edge", "mpg": 24.1} | |
| ]} | |
| ' | |
| $object = $json | ConvertFrom-Json | |
| $object | ConvertTo-StringData | |
| #result | |
| age=30 | |
| cars[0].model=BMW 230 | |
| cars[0].mpg=27.5 | |
| cars[1].model=Ford Edge | |
| cars[1].mpg=24.1 | |
| married=True | |
| name=John | |
| #complex json | |
| $json2 = ' | |
| { "Logging": { "LogLevel": { "Default": "None", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "None", "System.Net.Http.HttpClient.SDSEmployeeMaster.ClientHandler[100]": "None" } } } | |
| ' | |
| $object2 = $json2 | convertfrom-json | |
| drill $object2 | |
| Logging.LogLevel | |
| Logging.LogLevel.Default=None | |
| Logging.LogLevel.Microsoft=Warning | |
| Logging.LogLevel.Microsoft.Hosting.Lifetime=None | |
| Logging.LogLevel.System.Net.Http.HttpClient.SDSEmployeeMaster.ClientHandler[100]=None |
Author
1RedOne
commented
Oct 11, 2025
via email
lol
…On Fri, Oct 10, 2025 at 10:56 PM alvinlees805-netizen < ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Are you searching for a real spell caster ?
It is amazing how quickly Dr. Excellent brought my husband back to me.
My name is Heather Delaney. I married the love of my life Riley on
10/02/15 and we now have two beautiful girls Abby & Erin, who are conjoined
twins, that were born 07/24/16. My husband left me and moved to be with
another woman. I felt my life was over and my kids thought they would never
see their father again. I tried to be strong just for the kids but I could
not control the pains that tormented my heart, my heart was filled with
sorrows and pains because I was really in love with my husband. I have
tried many options but he did not come back, until i met a friend that
directed me to Dr. Excellent a spell caster, who helped me to bring back my
husband after 11hours. Me and my husband are living happily together again,
This man is powerful, contact Dr. Excellent if you are passing through any
difficulty in life or having troubles in your marriage or relationship, he
is capable of making things right for you. Don't miss out on the
opportunity to work with the best spell caster.
Here his contact. Call/WhatsApp him at: +2348084273514 "
Or email him at: ***@***.*** ,
For more information visit his website:
https://drexcellentspellcaster.godaddysites.com
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/1RedOne/ebd7147f377738694446064a7768deef#gistcomment-5798210>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJQTCXMITDJTASCXEBWU3T3XBWUVBFHORZGSZ3HMVZKMY3SMVQXIZNMON2WE2TFMN2F65DZOBS2WR3JON2EG33NNVSW45FGORXXA2LDOOIYFJDUPFYGLJDHNFZXJJLWMFWHKZNJGEYTAMZZGU2TINVKMF2HI4TJMJ2XIZLTSOBKK5TBNR2WLKJSGM3TGNRSGA2DRJDOMFWWLKDBMN2G64S7NFSIFJLWMFWHKZNEORZHKZNENZQW2ZN3ORUHEZLBMRPXAYLSORUWG2LQMFXHIX3BMN2GS5TJOR4YFJLWMFWHKZNEM5UXG5FENZQW2ZNLORUHEZLBMRPXI6LQMU>
.
You are receiving this email because you authored the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment