0

I am trying to get a script going that installs an application and sets up the scheduled task. The problem is that I am not able to pass the dynamic values into the New-ScheduledTaskTrigger

$triggerParams = @{
    Once=$false
    Daily=$false
    Weekly=$true
    At="12AM"
}

New-ScheduledTaskTrigger $triggerParams

Getting this error with my simple test above.

New-ScheduledTaskTrigger : Cannot process argument transformation on parameter 'Once'. Cannot convert value "System.Collections.Hashtable" to type "System.Management.Automation.SwitchParameter". Boolean parameters accept only  Boolean values and numbers, such as $True, $False, 1 or 0. At D:\Code\test.ps1:9 char:26
+ New-ScheduledTaskTrigger $triggerParams
+                          ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [New-ScheduledTaskTrigger], ParameterBindingArgumentTransformationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,New-ScheduledTaskTrigger

It looks like it should work based on this question: How to pass a switch parameter as a variable / via splatting in PowerShell?

What am I missing?

TyCobb
  • 8,909
  • 1
  • 33
  • 53

2 Answers2

1

The correct syntax for splatting is

New-ScheduledTaskTrigger @triggerParams

So, use a @ character on splatting instead of the $ you need when defining the hashtable.

Theo
  • 57,719
  • 8
  • 24
  • 41
0

My mistake was declaring the splat object as a PSCustomObject instead of a regular hashtable.

Rachel
  • 686
  • 1
  • 6
  • 18