Automation

 View Only
  • 1.  scheduling tasks check compliance of a profile

    Posted May 20, 2020 07:51 PM

    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



  • 2.  RE: scheduling tasks check compliance of a profile

    Posted May 20, 2020 08:47 PM

    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)