You import the contents into a script block, validate the script block, execute it and capture the resulting hashtable into a variable. Here is the sample code below:
$content = Get-Content -Path $Path -Raw -ErrorAction Stop
$scriptBlock = [scriptblock]::Create($content)
$scriptBlock.CheckRestrictedLanguage([string]@(), [string]@(), $false)
Write-Output (& $scriptBlock)
Copyright (c) 2015 Kevin.Marquette. All rights reserved.
The CheckRestrictedLanguage will throw an error if it finds any powershell commands in the hashtable. Because you are executing code from a un-trusted source in the middle of your script, you should validate it.
There is a second quick and dirty way to do the same thing without the validation. I almost don't want to mention it because it is so dangerous. So if you see this in the wild, know that there is a better way.
$HashTable = Invoke-Expression (Get-Content $Path -raw)
This blindly executes a file as if it was a script. This is just asking to be exploited. Think CSS cross site or SQL injection type of vulnerability.