Skip to content

Commit

Permalink
feat: ConvertFrom-Clixml (Fixes #721)
Browse files Browse the repository at this point in the history
  • Loading branch information
StartAutomating authored and StartAutomating committed Nov 23, 2023
1 parent 1eb603c commit 2a92dd0
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Commands/CliXml/ConvertFrom-CliXml.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
function ConvertFrom-CliXml {
<#
.Synopsis
Converts CliXml into PowerShell objects
.Description
Converts CliXml strings or compressed CliXml strings into PowerShell objects
.Example
dir | ConvertTo-Clixml | ConvertFrom-Clixml
.Link
ConvertTo-Clixml
.Link
Import-Clixml
.Link
Export-Clixml
#>
[OutputType([string])]
param(
# The input object.
# This is expected to be a CliXML string or XML object
[Parameter(Mandatory,Position,ValueFromPipeline)]
[ValidateScript({
$validTypeList = [System.String],[System.Xml.XmlDocument]
$thisType = $_.GetType()
$IsTypeOk =
$(@( foreach ($validType in $validTypeList) {
if ($_ -as $validType) {
$true;break
}
}))
if (-not $isTypeOk) {
throw "Unexpected type '$(@($thisType)[0])'. Must be 'string','xml'."
}
return $true
})]

[PSObject]
$InputObject
)
process {
$inputAsXml = $InputObject -as [xml]
[Management.Automation.PSSerializer]::Deserialize($(
if ($inputAsXml) {
$inputAsXml.OuterXml
} else {
$InputObject
}
))
}
}


0 comments on commit 2a92dd0

Please sign in to comment.