ConvertFrom-PowerShellDataFile.psm1

#
# 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: '', and individual Keys referenced via dot notation: '.Key1.Key2' etc.)

.PARAMETER FilePath
Specifies the Path to a PowerShell Data File.

.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'

.EXAMPLE
PS C:\> ConvertFrom-PowerShellDataFile -FilePath 'C:\test\MyModule\MyModule.psd1' -RequireValidation

.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


#>


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

[switch]
)

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

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

if (.IsPresent) {
return .
}
}

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


Export-ModuleMember -Function ConvertFrom-PowerShellDataFile