Best effort fix errors while exporting objects #15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Export-Clixml sometimes fails to exports all (gc)ADobjects, due to invalid encoded characters in some attributes.
Error observed usually during such events:
We end up with a truncated XML files, here is an example of such files:
This does not seem to impact ingestion into splunk (maybe because extraction is done via regex?).
It is "kind of easily" reproductible by replacing a random attribute of such object with the following value:
$adobjects[0].random_attribute="should-not-be-$([char]0xffff)-exportable"
Nonetheless, it would be nice to exclude un-exportable objects and retry afterwards. The following PR uses the following static function to detect such objects:
[System.Management.Automation.PSSerializer]::Serialize
Note that it is a best-effort fix only, and has limitation (PSSerializer does not allow to set the encoding as in current code (UTF8), and has a default depth of 1 instead of 2 for export-clixml