source/.old/ConvertFrom-PowerShellDataFile.psm1.old.ps1

# ┌────────────────────────────────┐
# │ ConvertFrom-PowerShellDataFile │
# └────────────────────────────────┘
#───────────────────────────────────
#

function ConvertFrom-PowerShellDataFile {
    <#PSScriptInfo
        .SYNOPSIS
            Generates a Hashtable from a specified PowerShell Data File.
 
        .DESCRIPTION
            Generates a Hashtable from the data stored within a specified valid PowerShell Data File (*.psd1 file), which is then stored within a Variable sharing its name with the source *.psd1 file's BaseName. (Example: If the Filename is 'Data.psd1', then the Hashtable generated from its contents can be referenced using the Variable: '$Data', and individual Keys referenced via dot notation: '$Data.Key1.Key2' etc.)
 
        .PARAMETER FilePath
            Specifies the Path to a PowerShell Data File.
 
        .PARAMETER ReturnValue
            Specifies the name of a particular Key located within the file. Once the files contents are converted to hashtable format, the Value assigned to the specified Key is immediately returned and displayed witin the Console Window.
 
        .PARAMETER RequireValidation
            When specified, the target *.psd1 file MUST be a VALID Module Manifest. (Uses Test-ModuleManifest to Validate contents of the Manifest.) If 'Test-ModuleManifest' returns a value of $false (File failed to pass Validation) then any issues discovered are highlighted and displayed to the User.
 
        .EXAMPLE
            PS C:\> ConvertFrom-PowerShellDataFile -FilePath 'C:\test\MyModule\PSScriptAnalyzerSettings.psd1'
            (Converts the contents of the file 'PSScriptAnalyzerSettings.psd1' into a hashtable, which is then stored in the Variable: '$PSScriptAnalyzerSettings')
 
        .EXAMPLE
            PS C:\> ConvertFrom-PowerShellDataFile -FilePath 'C:\test\MyModule\MyModule.psd1' -RequireValidation
            (IF the file 'MyModule.psd1' is recognized as a VALID PowerShell Module Manifest, its cotnents are then converted into a hashtable stored in the Variable: '$MyModule')
 
        .EXAMPLE
            PS C:\> ConvertFrom-PowerShellDataFile -FilePath 'C:\test\MyModule\MyModule.psd1' -ReturnValue 'RootModule' -RequireValidation
            (IF the file 'MyModule.psd1' is recognized as a VALID PowerShell Module Manifest, its contents are then converted into a hashtable stored in the Variable: '$MyModule'. Finally, the Value stored in the Key 'RootModule' is returned and displayed automatically in the Console Window, post-conversion. Expected Output: 'MyModule.psm1')
 
        .INPUTS
            @param 'FilePath' - System.IO.Path
 
        .OUTPUTS
            '$<FileBaseName>' - 'System.Collections.Hashtable'
 
        .LINK
            https://github.com/SupernautFX/SFX.PoshUtilities.DataFileTools
 
        .NOTES
            Filename: 'ConvertFrom-PowerShellDataFile.psm1'
            Version: 0.9.5
            Author: Nathaniel Wallis Praytor
 
            #ASOF: Friday 10/22/2021
            #AddedFeature: ValueFromPipeline/ValueFromPipelineByPropertyName, & Wildcard Compatibility to FilePath Parameter Declaration
            #TODO: Implement 'ReturnValue', and 'RequireValidation' Parameters.
            #TODO: Implement Multi-File Processing
 
    #>


    [CmdletBinding(SupportsShouldProcess)]
    [OutputType([Hashtable])]
    param(
        [Parameter(
            Mandatory,
            Position = 0,
            ValueFromPipeline,
            ValueFromPipelineByPropertyName
        )]
        [string]$FilePath,

        [Parameter(
            Position = 1,
            HelpMessage = 'NOT YET IMPLEMENTED'
        )]
        [string[]]$ReturnValue,


        [Parameter(
            Position = 2,
            HelpMessage = 'NOT YET IMPLEMENTED'
        )]
        [switch]$RequireValidation
    )

    BEGIN {
        if ($RequireValidation.IsPresent) {
        <# Try {
                Test-ModuleManifest $FilePath
                Write-Verbose "Success! PowerShell Data File passed Validation testing! This file is a VALID MODULE MANIFEST."
            } Catch {
                Write-Error $_
            }#>


            Write-Debug "NOT YET IMPLEMENTED! - @Param '-RequireValidation'"
            Write-Verbose "You specified the SwitchParameter 'RequireValidation'. The feature(s) of this Parameter are currently in a non-functional state. This Parameter is planned to be implemented in a future update. Please check with the 'ConvertFrom-PowerShellDataFile' Help Topic (Either 'Get-Help about_ConvertFrom-PowerShellDataFile' OR 'Get-Help ConvertFrom-PowerShellDataFile') for more information."
        }
        if ($ReturnValue -ne $null) {
            Write-Debug "NOT YET IMPLEMENTED! - @Param '-ReturnValue'"
            Write-Verbose "You passed an argument to the Parameter 'ReturnValue'. The feature(s) of this Parameter are currently in a non-functional state. This Parameter is planned to be implemented in a future update. Please check with the 'ConvertFrom-PowerShellDataFile' Help Topic (Either 'Get-Help about_ConvertFrom-PowerShellDataFile' OR 'Get-Help ConvertFrom-PowerShellDataFile') for more information."
        }
    }

    PROCESS {
        Try {
            $Manifest = New-Object hashtable
            $Filename = Split-Path $FilePath -Leaf
            $BaseName = $Filename.Split('.')[0]
            $Manifest.BaseName = (Import-PowerShellDataFile -Path $FilePath)
            New-Variable -Name $BaseName -Value $Manifest
        } Catch {
            Write-Error $_ -ErrorAction Stop
        }

        <#if ($ReturnValue.IsPresent) {
            return $Manifest.$ReturnValue
        }#>

    }

    END {
        Write-Information "New Hashtable created: `$$BaseName containing data stored in PowerShell Data File: $Filename"
    }
}

Set-Alias -Name cfpsd1 -Value ConvertFrom-PowerShellDataFile

Export-ModuleMember -Function ConvertFrom-PowerShellDataFile

Export-ModuleMember -Alias cfpsd1