Automation

 View Only
  • 1.  Remove scheduled task with powercli

    Posted Feb 06, 2023 09:07 PM

    Hello, 

    I added scheduled task to vm list of taking that reference : Solved: Re: Scheduling VM Compatibility Upgrade from Power... - VMware Technology Network VMTN

    Now i have to disable or remove that scheduled task on vms. I tried to run that script but it couldn't work. PowerCLI Help: Code to Remove Snapshot Task with R... - VMware Technology Network VMTN

    $VMlist = '.\vmliste.txt'

    $VMs = Get-Content $VMlist

    $vmObj = Get-VM -Name $VMs

    $si = Get-View ServiceInstance

    $scheduledTaskManager = Get-View $si.Content.ScheduledTaskManager

    Get-View -Id $scheduledTaskManager.ScheduledTask |

    where{$vmObj.ExtensionData.MoRef -contains $_.Info.Entity} | %{

    $_.RemoveScheduledTask()

    }

    Could you help me how to do that?

    Thanks



  • 2.  RE: Remove scheduled task with powercli

    Posted Feb 06, 2023 09:42 PM

    Are you sure the Scheduled Task was created on the VM, and not for example on a VMHost or a Folder?

    It would help if you showed the code with which you created the Scheduled Task(s)



  • 3.  RE: Remove scheduled task with powercli

    Posted Feb 07, 2023 07:23 AM

    Yes, I'm sure there are tasks those about upgrading vm's hardware version. But i couldnt remove or stop tasks. Task names are like that task-100937**. Hardware version would upgrade the next reboot.

    The script:


    $do = New-Object -TypeName VMware.Vim.VirtualMachineConfigSpec

    $do.ScheduledHardwareUpgradeInfo = New-Object -TypeName VMware.Vim.ScheduledHardwareUpgradeInfo

    $do.ScheduledHardwareUpgradeInfo.UpgradePolicy = [VMware.Vim.ScheduledHardwareUpgradeInfoHardwareUpgradePolicy]::onSoftPowerOff

    $do.ScheduledHardwareUpgradeInfo.VersionKey = “vmx-19”

    $do.Tools = New-Object VMware.Vim.ToolsConfigInfo

    $do.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"


    foreach($vmName in (Get-Content -Path .\vmlist.txt)){

    $vm = Get-VM -Name $vmName

    $vm.ExtensionData.ReconfigVM_Task($do)

    }

    hardware.PNG



  • 4.  RE: Remove scheduled task with powercli
    Best Answer

    Posted Feb 07, 2023 07:29 AM

    Afaik, that doesn't create a Scheduled Task, but is a setting in the VM's configuration.

    You should be able to reset that with

    $do = New-Object -TypeName VMware.Vim.VirtualMachineConfigSpec
    $do.ScheduledHardwareUpgradeInfo = New-Object -TypeName VMware.Vim.ScheduledHardwareUpgradeInfo
    $do.ScheduledHardwareUpgradeInfo.UpgradePolicy = [VMware.Vim.ScheduledHardwareUpgradeInfoHardwareUpgradePolicy]::never
    $do.ScheduledHardwareUpgradeInfo.VersionKey = “vmx-19”
    $do.Tools = New-Object VMware.Vim.ToolsConfigInfo
    $do.Tools.ToolsUpgradePolicy = "manual"
    
    foreach ($vmName in (Get-Content -Path .\vmlist.txt)) {
        $vm = Get-VM -Name $vmName
        $vm.ExtensionData.ReconfigVM_Task($do)
    }


  • 5.  RE: Remove scheduled task with powercli

    Posted Feb 07, 2023 07:47 AM

    Thank you so much  . You are the best. It worked.