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

Share on:

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 is the command you will use when you want to manually stage the update.

Example:

1 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 2 Copy-VCSAUpdate -Version "6.7.0.20100"

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:

1 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 2 Get-VCSAUpdate 3 4 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 5 Get-VCSAUpdate -Source "Online" 6 7 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 8 Get-VCSAUpdate -Source "Local"

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:

1 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 2 Get-VCSAUpdateDetail -Version "6.7.0.20100"

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

Example:

1 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 2 Get-VCSAUpdatePolicy

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

Example:

1 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 2 Set-VCSAUpdatePolicy -AutoStage $True 3 4 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 5 Set-VCSAUpdatePolicy -CustomURL https : // myinternalURL . com 6 Set-VCSAUpdatePolicy -CustomURL Clear 7 8 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 9 Set-VCSAUpdatePolicy -UsernameURL admin 10 Set-VCSAUpdatePolicy -PasswordURL Password 11 12 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 13 Set-VCSAUpdatePolicy -CheckSchedule Daily 14 Set-VCSAUpdatePolicy -CheckSchedule WeeklySunday 15 Set-VCSAUpdatePolicy -CheckSchedule WeeklyMonday 16 Set-VCSAUpdatePolicy -CheckSchedule WeeklyTuesday 17 Set-VCSAUpdatePolicy -CheckSchedule WeeklyWednesday 18 Set-VCSAUpdatePolicy -CheckSchedule WeeklyThursday 19 Set-VCSAUpdatePolicy -CheckSchedule WeeklyFriday 20 Set-VCSAUpdatePolicy -CheckSchedule WeeklySaturday

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

Example:

1 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 2 Get-VCSAUpdateStaged

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:

1 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 2 Get-VCSAUpdateStatus

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

Example:

1 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 2 Remove-VCSAUpdate

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:

1 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 2 Start-VCSAUpdateInstall -Version "6.7.0.20100" -SSODomainPass "VMware1!"

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

Example:

1 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 2 Start-VCSAUpdatePrecheck -Version "6.7.0.20100"

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

Example:

1 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 2 Start-VCSAUpdateStageandInstall -Version "6.7.0.20100" -SSODomainPass "VMware1!"

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

Example:

1 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 2 Start-VCSAUpdateValidate -Version "6.7.0.20100" -SSODomainPass "VMware1!"

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:

1 Connect-CisServer -Server 192 . 168 . 1 . 51 -User administrator @vsphere . local -Password VMware1 ! 2 Stop-VCSAUpdate

Putting the Powershell Module to Use

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.

Import the module Import-Module .\VCSA-VAMI-Patch.psm1 Check for Updates Get-VCSAUpdate Stage Update and Check Status Copy-VCSAUpdate -Version "6.7.0.20100" and Get-VCSAUpdateStatus until status shows UPDATE_PENDING Run Update Precheck and Validate Start-VCSAUpdatePrecheck -Version 6.7.0.20100 and Start-VCSAUpdateValidate -Version 6.7.0.20100 -SSODomainPass VMware1!

and If no errors, proceed with Install Run Update Install Start-VCSAUpdateInstall -Version 6.7.0.20100 -SSODomainPass VMware1! and Get-VCSAUpdateStatus until you see status as UPDATE_COMPLETE 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

Please enable JavaScript to view the comments powered by Disqus.

Disqus

See Also