VMware Cloud Community
MartyG
Contributor
Contributor

scheduling tasks check compliance of a profile

Hi

Is it possible to schedule a  task in virtual center to check compliance of a profile via Powercli. I rather not do it on the virtual center for each profile. I could run a script to check compliance but I like the idea of just creating a scheduled task.

thanks

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

Yes, that is possible, but there is one remark.

The task will check the compliance of the HostProfile on all the associated ESXi nodes.

Although it should be possible according to the API Reference, I haven't been able to schedule it for 1 specific associated ESXi node.

$hpName = 'Test-HP'

$checkTime = Get-Date "05/31/2020 23:00"


$emailAddr = 'luc@local.lab'


$hp = Get-VMHostProfile -Name $hpName


$si = Get-View ServiceInstance

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


$spec = New-Object VMware.Vim.ScheduledTaskSpec

$spec.Name = 'Check HostProfile',$hp.Name,'on all associated ESXi nodes' -join ' '

$spec.Description = 'Check HostProfile'

$spec.Enabled = $true

$spec.Notification = $emailAddr

$spec.Scheduler = New-Object VMware.Vim.OnceTaskScheduler

$spec.Scheduler.runat = $checkTime

$spec.Action = New-Object VMware.Vim.MethodAction

$spec.Action.Name = 'CheckProfileCompliance_Task'

$scheduledTaskManager.CreateObjectScheduledTask($hp.ExtensionData.MoRef, $spec)


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

Reply
0 Kudos