Functions/Data/ConvertFrom-StringDataOrdered.ps1

Function ConvertFrom-StringDataOrdered
{
    [cmdletbinding()]
    Param
        (
        # Input Herestring
        [Parameter(Mandatory=$true,position=0,ValueFromPipeline=$true)]
        [string]
        $StringData
        )
    Process
    {
        # Instantiate Ordered Hash Table
        $Hashtable = [System.Collections.Specialized.OrderedDictionary]::new()

        # Split input herestring on Newline
        $Split = $StringData -split "`n"

        # Add values to Hashtable
        foreach ($line in $Split)
        {
            $LS = ($Line -split '=')
            $KEY = if($LS[0]){$LS[0].trim()}else{$null}
            $VAL = if($LS[1]){$LS[1].trim()}else{$null}
            if($KEY){$Hashtable[$LS[0].trim()] = $LS[1].trim()}
        }
          
        # Output Ordered Hash Table
        $Hashtable
    }
}