Author Posts

April 24, 2018 at 8:26 pm

Hi, has anyone used data access classes before with PowerShell?

I have a custom class and inside it is a method to add the object to a directory with

$Object | ConvertTo-Yaml | Out-File -Path $Object.Path
$Object | Export-CLiXml -Depth 9999 -Path $Object.MachinePath

to store the object in YAML format and to store the export-clixml output so i can rehydrate my object for when I want to run a Get-Object function.

I didn't know export-clixml and import-clixml returned different object types, and casting the object to original type on import-clixml fails.

Apparently a data access class gets around this, but I've never seen the structure of this. Can anyone point me in the right direction?

The class object is a subclass of a base class which has nothing in the default constructor, but populates some information by default which would change the object.

Is there a way forward here?

Thanks ,

AJ

May 19, 2018 at 2:07 pm

The change in class type is deliberate due to the way the PowerShell ETS works; it helps the various things that cue on class type understand that it's a deserialized object, not a "live" one. Deserialized objects don't have any code in them – no methods. They're just static representations.

So I guess... what's the end goal, here? Like, what are you ultimately trying to accomplish?