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?

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

.... well I feel like a moron. lol. Thanks so much.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.