This PowerShell script works great, but I need it to be a one line script, how can I create the parameter objects inline?
$action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument 'invoke-command -scriptblock {iisreset}'
$trigger = New-ScheduledTaskTrigger -Daily -At 9am
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "Reset IIS" -Description "Daily Reset IIS"
e.g.
Register-ScheduledTask -Action `New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument 'invoke-command -scriptblock {iisreset}'` -Trigger `New-ScheduledTaskTrigger -Daily -At 9am -TaskName "Reset IIS" -Description "Daily Reset IIS"`
I've tried wrapping it in double quotes and with backticks and with curly braces but no luck so far.
Subexpressions should do it. Brackets outside subexpressions not required AFAIK.
$( ) Subexpression operator
Returns the result of one or more statements. For a single result, returns a scalar. For multiple results, returns an array. sauce: about_Operators
Register-ScheduledTask -Action $(New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument 'invoke-command -scriptblock {iisreset}') -Trigger $(New-ScheduledTaskTrigger -Daily -At 9am)-TaskName "Reset IIS" -Description "Daily Reset IIS"
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments