PowerCLI – Configure VCSA update policy

It took me a little while to figure this one out, since I am new to this rest API thing and I find the old API documentation easier. On VMware’s homepage I was not able to find the API for vSphere 6.7, only 6.5.

https://code.vmware.com/apis/60/vcenter-server-appliance-management

However you can access the API explorer directly on the vCenter as described here.

https://blogs.vmware.com/developer/2017/01/getting-started-vsphere-api-explorer.html

Below you can find my little PowerCli code snippet.

## Connect to VCSA. You would think to use the root user but no, SSO user
# like administrator@vsphere.local.
$cisConnection = Connect-CisServer -server vcenter.txusa.cloud 

## I didn't know how to create an updateSpec object so I just
## got the existing one from VCSA and then will overwrite the parameters
$updateSpec = (Get-CisService -Name "com.vmware.appliance.update.policy").get()


## Set parameters for update policy
$updateSpec.auto_stage = $true
$updateSpec.auto_update = $false
$updateSpec.manual_control = $true 
$updateSpec.username = ''
## vSphere 6.7u1 now forces https
$updateSpec.custom_URL = "https://updaterepository.txusa.cloud/vcsa"
    
## Time and day when to check for new updates. In this case every day at 5:00 am
$schedule = [pscustomobject] @{day="EVERYDAY";hour=5;minute=0}
$updateSpec.check_schedule = @($schedule)
    
## Set new update policy
(Get-CisService -Name "com.vmware.appliance.update.policy").set($updateSpec)

## Disconnect from VCSA
Disconnect-CisServer vcenter.txusa.cloud -Confirm:$false

Published by txusa

VMware Certified Design Expert - VCDX 92. VMware Architect, automation enthusiast.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: