Editing two scheduled tasks with powershell in one script -


i use 2 commands in powershell edit 2 scheduled tasks

schtasks.exe /tn task1 /sd 2015-01-01  /ed 2015-02-02 /rp mypassword schtasks.exe /tn task2 /sd 2015-04-04  /ed 2015-05-05 /rp mypassword 

i know if can use 1 line command edit both tasks. thank helping.

it's harder make 1 liner when multiple pieces of information need changed. lets try pass array of hash tables invoke-expression

@(  @{name = "task1";startdate = "2015-01-01";enddate = "2015-02-02"},     @{name = "task2";startdate = "2015-04-04";enddate = "2015-05-05"} ) | foreach-object{     invoke-expression ("schtasks.exe /tn {0} /sd {1}  /ed {2} /rp mypassword" -f $_.name, $_.startdate, $_.enddate) } 

if had csv file columns name, startdate, enddate pipe right foreach have there. don't need declare array statically in code.

most powershell code can written in 1 line. depends how horrible expect next person.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -