VMware Cloud Community
deryambn
Enthusiast
Enthusiast
Jump to solution

Remove scheduled task with powercli

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

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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)
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
deryambn
Enthusiast
Enthusiast
Jump to solution

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

Tags (1)
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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)
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
deryambn
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos