Automation

 View Only
  • 1.  Change the Name and Part Description of All Scheduled

    Posted Jul 02, 2020 12:01 PM

    Hi

    We have a number of scheduled task setup of reboot, all task name start with "Scheduled Reboot of < ServerName>". Also within the description it has a starts with "Agreed Scheduled Reboot of <ServerName> by Service Owner(See Ticket#IT-xxxx)

    I wanted to ask is there a way i can use cli to change

    All Task Name from "Scheduled Reboot of < ServerName>" to Recurring Reboot of < ServerName>

    Also change part of description from "Agreed Scheduled Reboot of <ServerName> by Service Owner(See Ticket#IT-xxxx)" to "Recurring Reboot of <ServerName> - " but keep the Ticket#IT-xxxx part as this unique to each task

    Here is the script as i that i have and would appreciate your help  thank you

    $si = Get-View ServiceInstance

    $schedMgr = Get-View -Id $si.Content.ScheduledTaskManager

    Get-View -Id $schedMgr.ScheduledTask | where{$_.Info.Name -match "^Scheduled Reboot of"} |

    ForEach-Object -Process {

        $spec = New-Object VMware.Vim.ScheduledTaskSpec

        $spec.Enabled = $true

        $spec.Action = $_.Info.Action

        $spec.Description = "Recurring Reboot of ", $vm.Name -join ' '  **not sure how i can keep the last part of the description ***

        $spec.Name = "Recurring Reboot of ", $vm.Name -join ' '

        $spec.Notification = $_.Info.Notification

        $spec.Scheduler = $_.Info.Scheduler

        $_.ReconfigureScheduledTask($spec)

    }

    Recurring Reboot of



  • 2.  RE: Change the Name and Part Description of All Scheduled

    Posted Jul 02, 2020 12:20 PM

    You could do something like this

    $schedMgr = Get-View ScheduledTaskManager

    Get-View -Id $schedMgr.ScheduledTask | where{$_.Info.Name -match "^Scheduled Reboot of"} |

    ForEach-Object -Process {

        $spec = $_.Info

        $spec.Description = $_.Info.Description -replace 'Agreed Scheduled Reboot','Recurring Reboot'

        $spec.Name = $_.Info.Name -replace 'Scheduled Reboot','Recurring Reboot'


        $_.ReconfigureScheduledTask($spec)

    }



  • 3.  RE: Change the Name and Part Description of All Scheduled

    Posted Jul 02, 2020 12:33 PM

    Hi

    Thank you so much, as i also need to keep parts of the description as follows

    Previous

    Agreed Scheduled Reboot of <ServerName> by Service Owner(See Ticket#IT-xxxx)

    New

    Recurring Reboot of <ServerName> (See Ticket#IT-218732)

    Do you amending you script with this will work

    $schedMgr = Get-View ScheduledTaskManager

    Get-View -Id $schedMgr.ScheduledTask | where{$_.Info.Name -match "^Scheduled Reboot of"} |

    ForEach-Object -Process {

        $spec = $_.Info

        $spec.Description = $_.Info.Description -replace 'Agreed Scheduled Reboot','Recurring Reboot'

        $spec.Description = $_.Info.Description -replace 'by Service Owner',' '

        $spec.Name = $_.Info.Name -replace 'Scheduled Reboot','Recurring Reboot'

        $_.ReconfigureScheduledTask($spec)

    }



  • 4.  RE: Change the Name and Part Description of All Scheduled

    Posted Jul 02, 2020 01:42 PM

    Hi

    I managed to run the script a few time to change but it seems that if expression i add "(" is does not like this

    can you help me on this pls

    $schedMgr = Get-View ScheduledTaskManager

    Get-View -Id $schedMgr.ScheduledTask | where{$_.Info.Name -match "^Recurring Reboot of"} |

    ForEach-Object -Process {

        $spec = $_.Info

        $spec.Description = $_.Info.Description -replace '(Ticket',' '

            $_.ReconfigureScheduledTask($spec)

    }



  • 5.  RE: Change the Name and Part Description of All Scheduled

    Posted Jul 02, 2020 02:46 PM

    Are you getting any error?

    Or what is replaced incorrectly? Can you give an example?



  • 6.  RE: Change the Name and Part Description of All Scheduled

    Posted Jul 02, 2020 02:58 PM

    Hi

    Currently the description reads

    Recurring Reboot of <ServerName> - (See  Ticket#IT-1234)

    i  would it to be

    Recurring Reboot of <ServerName> - IT-1234

    the scripts is

    $schedMgr = Get-View ScheduledTaskManager

    Get-View -Id $schedMgr.ScheduledTask | where{$_.Info.Name -match "^Recurring Reboot of"} |

    ForEach-Object -Process {

        $spec = $_.Info

        $spec.Description = $_.Info.Description -replace 'Recurring Reboot of JSY-DOCGVP09 -(See  Ticket#','Recurring Reboot of', $vm.Name -join ' -'

            $_.ReconfigureScheduledTask($spec)

    }

    Once issue is see is that the server name was added originally using  $vm.Name -join and this is what the it might not be able to read this

    the error i get running this is probably adding  $vm.Name -join



  • 7.  RE: Change the Name and Part Description of All Scheduled

    Posted Jul 02, 2020 04:08 PM

    The -replace operator uses a RegEx expression, so we can use capturing groups.

    Try with this version

    $schedMgr = Get-View ScheduledTaskManager

    Get-View -Id $schedMgr.ScheduledTask | where{$_.Info.Name -match "^Scheduled Reboot of"} |

    ForEach-Object -Process {

        $spec = $_.Info

        $spec.Description = $_.Info.Description -replace '(.+)\((See  Ticket#)(.+)\)','$1$3'

        $spec.Name = $_.Info.Name -replace 'Scheduled Reboot','Recurring Reboot'


        $_.ReconfigureScheduledTask($spec)

    }



  • 8.  RE: Change the Name and Part Description of All Scheduled

    Posted Jul 02, 2020 04:52 PM

    Hi


    Thank you that worked the only thing i noticed is that in the original script it had '$1$3'

    The description no look like this

    $1$3   - IT-1234

    i want to to be just

    IT-1234

    i amended the script which run without any errors but it does not do anything pls can you advise where i might be going wrong

    $schedMgr = Get-View ScheduledTaskManager

    Get-View -Id $schedMgr.ScheduledTask | where{$_.Info.Name -match "^Recurring Reboot of"} |

    ForEach-Object -Process {

        $spec = $_.Info

        $spec.Description = $_.Info.Description -replace '$1$3   -',' '

        $_.ReconfigureScheduledTask($spec)

    }



  • 9.  RE: Change the Name and Part Description of All Scheduled
    Best Answer

    Posted Jul 02, 2020 05:22 PM

    What did you have in the Description?

    What did you actually run?

    I ran this in test, and I don't see any $1$3 in the resulting description.
    I suspect the code you used might have an issue.



  • 10.  RE: Change the Name and Part Description of All Scheduled

    Posted Jul 02, 2020 05:37 PM

    Hi


    Thank you it was resolved it must have been how i copied it

    Thank all resolved