PowerShell Eliminates Serialization and Deserialization

Are procedures available for serializing and deserializing objects from PowerShell (how is PowerShell Remoting performed)?

I would like not to write objects to disk (using Export-CliXML) and read it back using (Import-CliXML).

Basically, I want to get the property packages that deserialization creates so that I can add them to the AppFabric object cache. Otherwise, AppFabric tries to use .NET serialization, which is not suitable for a number of standard object types.

Perhaps through the variables $ host or $ executecontext?

+6
source share
2 answers

They published the PowerShell Remoting Specification, which will provide you with the specification, but the source code that they used to implement it is not currently publicly available. http://msdn.microsoft.com/en-us/library/dd357801(PROT.10).aspx

+3
source

Oh, I see what you are asking, you are looking for ConvertTo-CliXml, similar to how ConvertTo-Csv works instead of Export-Csv. At first glance, it seems that you are trying to completely eliminate CliXml.

In this case, there is one on PoshCode: ConvertTo-CliXml ConvertFrom -CliXml

Here's a verbatim copy to give you an idea (I have not tested this for correctness):

function ConvertTo-CliXml { param( [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] [ValidateNotNullOrEmpty()] [PSObject[]]$InputObject ) begin { $type = [PSObject].Assembly.GetType('System.Management.Automation.Serializer') $ctor = $type.GetConstructor('instance,nonpublic', $null, @([System.Xml.XmlWriter]), $null) $sw = New-Object System.IO.StringWriter $xw = New-Object System.Xml.XmlTextWriter $sw $serializer = $ctor.Invoke($xw) $method = $type.GetMethod('Serialize', 'nonpublic,instance', $null, [type[]]@([object]), $null) $done = $type.GetMethod('Done', [System.Reflection.BindingFlags]'nonpublic,instance') } process { try { [void]$method.Invoke($serializer, $InputObject) } catch { Write-Warning "Could not serialize $($InputObject.GetType()): $_" } } end { [void]$done.Invoke($serializer, @()) $sw.ToString() $xw.Close() $sw.Dispose() } } 
+1
source

Source: https://habr.com/ru/post/885651/


All Articles