Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The invoke_params method does not handle datetime objects #57

Closed
michaeltlombardi opened this issue Nov 13, 2020 · 0 comments · Fixed by #58
Closed

The invoke_params method does not handle datetime objects #57

michaeltlombardi opened this issue Nov 13, 2020 · 0 comments · Fixed by #58
Labels
bug Something isn't working

Comments

@michaeltlombardi
Copy link
Contributor

Describe the Bug

When passing a datetime string in a hash to Invoke-DscResource it fails with the following message:

Could not evaluate: Convert property 'starttime' value from type 'STRING' to type 'DATETIME' failed

This is caused by the failure of implicit casting, similar to what happens with empty arrays (see #55 for more details). Special handling should be added to the handler, as with PSCredential objects, since the value in the manifest is a string.

Expected Behavior

When a datetime parameter is specified in a manifest it does not cause casting errors when passed to Invoke-DscResource.

Steps to Reproduce

# requires dsc-computermanagementdsc
ScheduledTask { 'Test StartTime Casting':
  dsc_taskname                  => 'Test starttime casting',
  dsc_actionexecutable          => 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe',
  dsc_scheduletype              => 'Once',
  dsc_starttime                 => '2018-10-01T01:00:00',
  dsc_enable                    => true,
}

Suggested Fix

Similar to the handling for empty arrays:

date_time_parameters = resource[:parameters].select { |k,v| v[:mof_type] ~= /DateTime/i }
date_time_parameters.each do |name, properties|
  param_block_name = name.to_s.gsub(/^dsc_/, '')
  params_block = params_block.gsub("#{param_block_name} = ", "#{param_block_name} = [#{properties[:mof_type]}]")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant