VMware Cloud Community
jvlach
Enthusiast
Enthusiast

host profile scheduled compliance check

I want to script the creation of a scheduled task. If you are in the web client, there is a convenient gui to create a host profile compliance check job, but I need to create a bunch of these. I cannot find too much on this. Anyone have a script to create a weekly job to check a host profiles' compliance?

hostprofilecheck.PNG

0 Kudos
1 Reply
LucD
Leadership
Leadership

The easiest way is to use something like the Windows Task Scheduler, to schedule a script that runs the Test-VMHostProfileCompliance cmdlet.


If you want to use the vCenter scheduler (what the Web Client does) you can try something like this.
It will check the compliance of the hostprofile 'MyHostProfile' with all it's attached ESXi nodes.

The task will be scheduled to run 2 days from now.

But this can also be scheduled at an interval.

$hpName = 'MyHostProfile'

$si = Get-View ServiceInstance

$schedMgr = Get-View ScheduledTaskManager

$hp = Get-VMHostProfile -Name $hpName

$spec = New-Object VMware.Vim.ScheduledTaskSpec

$spec.Name = 'Test HP check'

$spec.Description = 'Created with script'

$spec.Enabled = $false

$action = New-Object VMware.Vim.MethodAction

$action.Name = 'CheckProfileCompliance_Task'

$arg = New-Object VMware.Vim.MethodActionArgument

$action.Argument = $arg

$spec.Action = $action

$sched = New-Object VMware.Vim.OnceTaskScheduler

$sched.RunAt = (Get-Date).AddDays(2)

$spec.Scheduler = $sched

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


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

0 Kudos