Patching the vCenter Server Appliance (VCSA) using the REST API - Part 2 (PowerCLI Module)

Published on January 31, 2019 under VMware · Tagged vSphere 6.7, REST API, vCenter Server and Powershell · Read in about 5 min (937 words)

Previously I covered how to use the VCSA Installer to do a scripted upgrade and then I covered Patching the vCenter Server Appliance (VCSA) using the REST API - Part 1 (Postman Collection) However, after learning recently how to call API’s from Powershell I thought to myself, why not write a Powershell Module for this?

Introduction

Using tools such as Postman can make it utilizing API’s a bit easier, but you still need to be familiar with a separate tool or UI. I was able to develop my own version and build my first Powershell Module that you can use to patch the VCSA in a simple method. Some of the function names below may not be 100% exact and this is due to the accepted verbs for Powershell. If you have further recommendations I would be happy to entertain changing the Powershell verbage.

Use Cases

Why would you want to use a Powershell module such as this? Well this tool can support multiple vCenter Servers. So here are a few ideas.

  • Modify a Custom URL Repository Across all vCenter Servers in your Environment
  • Stage Patches across all vCenter Servers in your Environment.
  • Patch Multiple Servers Simultaneously

Exploring the Powershell Module Functions

As of current, the Powershell module currently has 12 Functions.

  • Copy-VCSAUpdate
  • Get-VCSAUpdate
  • Get-VCSAUpdateDetail
  • Get-VCSAUpdatePolicy
  • Set-VCSAUpdatePolicy
  • Get-VCSAUpdateStaged
  • Get-VCSAUpdateStatus
  • Remove-VCSAUpdate
  • Start-VCSAUpdateInstall
  • Start-VCSAUpdatePrecheck
  • Start-VCSAUpdateStageandInstall
  • Start-VCSAUpdateValidate
  • Stop-VCSAUpdate

Copy-VCSAUpdate

Copy-VCSAUpdate is the command you will use when you want to manually stage the update.

Example:

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Copy-VCSAUpdate -Version "6.7.0.20100"

Get-VCSAUpdate

Get-VCSAUpdate is the command you will use when you want to wish to check for new updates. There is an optional Parameter for Source, “Local” or “Online”, if no parameter is chosen it will default to Online.

Example:

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Get-VCSAUpdate

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Get-VCSAUpdate -Source "Online"

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Get-VCSAUpdate -Source "Local"

Get-VCSAUpdateDetail

Get-VCSAUpdateDetail is the command you will use when you want to wish to get more details about a specific update. There is a mandatory parameter for Version.

Example:

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Get-VCSAUpdateDetail -Version "6.7.0.20100"

Get-VCSAUpdatePolicy

Get-VCSAUpdatePolicy is the command you will use when you want to wish to get information about the current appliance update settings.

Example:

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Get-VCSAUpdatePolicy

Set-VCSAUpdatePolicy

Set-VCSAUpdatePolicy is the command you will use when you want to wish to set information for the current appliance update settings.

Example:

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Set-VCSAUpdatePolicy -AutoStage $True

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Set-VCSAUpdatePolicy -CustomURL https://myinternalURL.com
Set-VCSAUpdatePolicy -CustomURL Clear

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Set-VCSAUpdatePolicy -UsernameURL admin
Set-VCSAUpdatePolicy -PasswordURL Password

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Set-VCSAUpdatePolicy -CheckSchedule Daily
Set-VCSAUpdatePolicy -CheckSchedule WeeklySunday
Set-VCSAUpdatePolicy -CheckSchedule WeeklyMonday
Set-VCSAUpdatePolicy -CheckSchedule WeeklyTuesday
Set-VCSAUpdatePolicy -CheckSchedule WeeklyWednesday
Set-VCSAUpdatePolicy -CheckSchedule WeeklyThursday
Set-VCSAUpdatePolicy -CheckSchedule WeeklyFriday
Set-VCSAUpdatePolicy -CheckSchedule WeeklySaturday

Get-VCSAUpdateStaged

Get-VCSAUpdateStaged is the command you will use when you want to wish to get information about the current staged update.

Example:

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Get-VCSAUpdateStaged

Get-VCSAUpdateStatus

Get-VCSAUpdateStaged is the command you will use when you want to wish to get information about the current update status. This command can be used to get status of staged update, install update or any other update status.

Example:

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Get-VCSAUpdateStatus

Remove-VCSAUpdate

Remove-VCSAUpdate is the command you will use when you wish to remove a staged update.

Example:

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Remove-VCSAUpdate

Start-VCSAUpdateInstall

Start-VCSAUpdateInstall is the command you will use when you wish to install a currently staged update. If no update is staged you must use Start-VCSAUpdateStageandInstall

Example:

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Start-VCSAUpdateInstall -Version "6.7.0.20100" -SSODomainPass "VMware1!"

Start-VCSAUpdatePrecheck

Start-VCSAUpdatePrecheck is the command you will use when you wish to run the built-in update Precheck.

Example:

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Start-VCSAUpdatePrecheck -Version "6.7.0.20100"

Start-VCSAUpdateStageandInstall

Start-VCSAUpdateInstall is the command you will use when you wish to install and stage an update.

Example:

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Start-VCSAUpdateStageandInstall -Version "6.7.0.20100" -SSODomainPass "VMware1!"

Start-VCSAUpdateValidate

Start-VCSAUpdateValidate is the command you will use when you wish validate the current update.

Example:

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Start-VCSAUpdateValidate -Version "6.7.0.20100" -SSODomainPass "VMware1!"

Stop-VCSAUpdate

Stop-VCSAUpdate is the command you will use when you want to cancel an update task such as staging an update or other task that has a status of cancelable.

Example:

Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
Stop-VCSAUpdate

Putting the Powershell Module to Use

This Examples assumes your VCSA has Internet Access and we will update via the Online Repo.

You can access the Powershell Module here on GitHub.

Important Note: The code samples included in this module are not supported by VMware. The code included is only provided as sample code for the purpose of demonstrating different tasks using the PowerCLI and the REST API.

  1. Import the module
    • Import-Module .\VCSA-VAMI-Patch.psm1
  2. Check for Updates
    • Get-VCSAUpdate
  3. Stage Update and Check Status
    • Copy-VCSAUpdate -Version "6.7.0.20100" and Get-VCSAUpdateStatus until status shows UPDATE_PENDING
  4. Run Update Precheck and Validate
    • Start-VCSAUpdatePrecheck -Version 6.7.0.20100 and Start-VCSAUpdateValidate -Version 6.7.0.20100 -SSODomainPass VMware1!
    • If no errors, proceed with Install
  5. Run Update Install
    • Start-VCSAUpdateInstall -Version 6.7.0.20100 -SSODomainPass VMware1! and Get-VCSAUpdateStatus until you see status as UPDATE_COMPLETE
  6. Validate Update Version in VCSA UI or in vSphere Client

Conclusion

I hope this module can be useful for you to get started with updating your VCSA in a more Automated fashion. Big thanks to Steve Kaplan for taking time to review the module and provide feedback and input!

If you have any questions feel free to reach out here or on twitter @davidstamen

Share this post
comments powered by Disqus

See Also