How can I make this PowerShell script into one line

NoseBagUK

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.

G42

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How can I pass an argument to a PowerShell script?

From Dev

How can I make a contour plot doesn't overlap on the line plot in one axes?

From Dev

How can I run a Powershell script in PHP?

From Dev

How can I create a registry value and path leading to it in one line using PowerShell?

From Dev

How can I make this bash script into an one-liner?

From Dev

How can I make the animations be run one by one?

From Dev

How to make one line coffee script code to multiline?

From Dev

How can I make a .bat file not exit when I run a powershell script?

From Dev

How can I make the line turn?

From Dev

How can I make my output appear all on one line with no spaces?

From Dev

How can I make jquery script shorter?

From Dev

Can I make Python output exceptions in one line / via logging?

From Dev

How can I get multiple bash background scripts, spawned from one initial startup script to log on the correct line of the terminal?

From Dev

How can I display my javascript inside my <p> tags to make it a one line sentence?

From Dev

How I can do this powershell script better?

From Dev

How can I have more than one possibility in a script's shebang line?

From Dev

How do I run multiple commands on one line in PowerShell?

From Dev

How can I make a contour plot doesn't overlap on the line plot in one axes?

From Dev

How can I run a Powershell script in PHP?

From Dev

How can I make a batch script open a command-line window in it's current location?

From Dev

How can I pass variables to a script one line at a time in bash?

From Dev

How do I make HTML Elements appear on one line?

From Dev

How can I make my JS script calls in Magento appear on one line?

From Dev

Can I make this PowerShell Script accept commas?

From Dev

How can I make a script executable?

From Dev

How can I make a button that that triggers a script?

From Dev

Powershell - how can I make

From Dev

parse error in one-line powershell script

From Dev

How can I merge both the inner border to make it one broad line in the middle of the circle?

Related Related

  1. 1

    How can I pass an argument to a PowerShell script?

  2. 2

    How can I make a contour plot doesn't overlap on the line plot in one axes?

  3. 3

    How can I run a Powershell script in PHP?

  4. 4

    How can I create a registry value and path leading to it in one line using PowerShell?

  5. 5

    How can I make this bash script into an one-liner?

  6. 6

    How can I make the animations be run one by one?

  7. 7

    How to make one line coffee script code to multiline?

  8. 8

    How can I make a .bat file not exit when I run a powershell script?

  9. 9

    How can I make the line turn?

  10. 10

    How can I make my output appear all on one line with no spaces?

  11. 11

    How can I make jquery script shorter?

  12. 12

    Can I make Python output exceptions in one line / via logging?

  13. 13

    How can I get multiple bash background scripts, spawned from one initial startup script to log on the correct line of the terminal?

  14. 14

    How can I display my javascript inside my <p> tags to make it a one line sentence?

  15. 15

    How I can do this powershell script better?

  16. 16

    How can I have more than one possibility in a script's shebang line?

  17. 17

    How do I run multiple commands on one line in PowerShell?

  18. 18

    How can I make a contour plot doesn't overlap on the line plot in one axes?

  19. 19

    How can I run a Powershell script in PHP?

  20. 20

    How can I make a batch script open a command-line window in it's current location?

  21. 21

    How can I pass variables to a script one line at a time in bash?

  22. 22

    How do I make HTML Elements appear on one line?

  23. 23

    How can I make my JS script calls in Magento appear on one line?

  24. 24

    Can I make this PowerShell Script accept commas?

  25. 25

    How can I make a script executable?

  26. 26

    How can I make a button that that triggers a script?

  27. 27

    Powershell - how can I make

  28. 28

    parse error in one-line powershell script

  29. 29

    How can I merge both the inner border to make it one broad line in the middle of the circle?

HotTag

Archive