#
# DSC Runner.
#
# Bootstraps the DSC environment, sets up configuration data
# and runs the DSC Configuration.
#
#

# Set the local PowerShell Module environment path
<% if options[:module_paths]  %>
$absoluteModulePaths = [string]::Join(";", ("<%= options[:module_paths] %>".Split(";") | ForEach-Object { $_ | Resolve-Path }))

echo "Adding to path: $absoluteModulePaths"
$env:PSModulePath="$absoluteModulePaths;${env:PSModulePath}"
<% end %>

$script = $(Join-Path "<%= options[:temp_path] %>" "<%= options[:configuration_file] %>")
echo "PSModulePath Configured: ${env:PSModulePath}"
echo "Running Configuration file: ${script}"

# Generate the MOF file, only if a MOF path not already provided.
<% if options[:mof_path] == nil %>
# Import the Manifest
. $script

cd "<%= options[:temp_path] %>"
$StagingPath = $(Join-Path "<%= options[:temp_path] %>" "staging")
$response = <%=options[:configuration_name]%> -OutputPath $StagingPath <%= options[:parameters] %> 4>&1 5>&1 | Out-String
<% else %> 
$StagingPath = "<%= options[:mof_path] %>"
<% end %>

# Start a DSC Configuration run
$response += Start-DscConfiguration -Force -Wait -Verbose -Path $StagingPath 4>&1 5>&1 | Out-String
$response
#
# DSC Runner.
#
# Bootstraps the DSC environment, sets up configuration data
# and runs the DSC Configuration.
#
#

# Set the local PowerShell Module environment path
<% if !options[:module_paths].empty?  %>
$absoluteModulePaths = [string]::Join(";", ("<%= options[:module_paths] %>".Split(";") | ForEach-Object { $_ | Resolve-Path }))

echo "Adding to path: $absoluteModulePaths"
$env:PSModulePath="$absoluteModulePaths;${env:PSModulePath}"
<% end %>

$script = $(Join-Path "<%= options[:temp_path] %>" "<%= options[:configuration_file] %>")
echo "PSModulePath Configured: ${env:PSModulePath}"
echo "Running Configuration file: ${script}"

# Generate the MOF file, only if a MOF path not already provided.
<% if options[:mof_path] == nil %>
# Import the Manifest
. $script

cd "<%= options[:temp_path] %>"
$StagingPath = $(Join-Path "<%= options[:temp_path] %>" "staging")
$response = <%=options[:configuration_name]%> -OutputPath $StagingPath <%= options[:parameters] %> 4>&1 5>&1 | Out-String
<% else %> 
$StagingPath = "<%= options[:mof_path] %>"
<% end %>

# Start a DSC Configuration run
$response += Start-DscConfiguration -Force -Wait -Verbose -Path $StagingPath 4>&1 5>&1 | Out-String
$response
Check for empty module_paths in Powersell runner
Check for empty module_paths in Powersell runner
