-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ConvertFrom-Clixml (Fixes #721)
- 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.
There are no files selected for viewing
This file contains 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
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 | ||
} | ||
)) | ||
} | ||
} | ||
|
||
|