February 2019
Intermediate to advanced
626 pages
15h 51m
English
The benefit of splatting is most obvious when working with commands that expect a larger number of parameters.
This first example uses the Windows PowerShell module ScheduledTasks to create a fairly basic task that runs once a day at midnight:
$taskAction = New-ScheduledTaskAction -Execute pwsh.exe -Argument 'Write-Host "hello world"'$taskTrigger = New-ScheduledTaskTrigger -Daily -At '00:00:00'Register-ScheduledTask -TaskName 'TaskName' -Action $taskAction -Trigger $taskTrigger -RunLevel 'Limited' -Description 'This line is too long to read'
It is possible to spread the command out, in an attempt to make it easier to read, by escaping the end-of-line character, for example:
$taskAction = New-ScheduledTaskAction ...
Read now
Unlock full access