Patching the vCenter Server Appliance (VCSA) using the REST API - Part 2 (PowerCLI Module)
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:
1Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
2Copy-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:
1Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
2Get-VCSAUpdate
3
4Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
5Get-VCSAUpdate -Source "Online"
6
7Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
8Get-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:
1Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
2Get-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:
1Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
2Get-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:
1Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
2Set-VCSAUpdatePolicy -AutoStage $True
3
4Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
5Set-VCSAUpdatePolicy -CustomURL https://myinternalURL.com
6Set-VCSAUpdatePolicy -CustomURL Clear
7
8Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
9Set-VCSAUpdatePolicy -UsernameURL admin
10Set-VCSAUpdatePolicy -PasswordURL Password
11
12Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
13Set-VCSAUpdatePolicy -CheckSchedule Daily
14Set-VCSAUpdatePolicy -CheckSchedule WeeklySunday
15Set-VCSAUpdatePolicy -CheckSchedule WeeklyMonday
16Set-VCSAUpdatePolicy -CheckSchedule WeeklyTuesday
17Set-VCSAUpdatePolicy -CheckSchedule WeeklyWednesday
18Set-VCSAUpdatePolicy -CheckSchedule WeeklyThursday
19Set-VCSAUpdatePolicy -CheckSchedule WeeklyFriday
20Set-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:
1Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
2Get-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:
1Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
2Get-VCSAUpdateStatus
Remove-VCSAUpdate
Remove-VCSAUpdate is the command you will use when you wish to remove a staged update.
Example:
1Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
2Remove-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:
1Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
2Start-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:
1Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
2Start-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:
1Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
2Start-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:
1Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
2Start-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:
1Connect-CisServer -Server 192.168.1.51 -User administrator@vsphere.local -Password VMware1!
2Stop-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.
- 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"
andGet-VCSAUpdateStatus
until status showsUPDATE_PENDING
- Run Update Precheck and Validate
Start-VCSAUpdatePrecheck -Version 6.7.0.20100
andStart-VCSAUpdateValidate -Version 6.7.0.20100 -SSODomainPass VMware1!
- If no errors, proceed with Install
- Run Update Install
Start-VCSAUpdateInstall -Version 6.7.0.20100 -SSODomainPass VMware1!
andGet-VCSAUpdateStatus
until you see status asUPDATE_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
comments powered by DisqusSee Also
- Patching the vCenter Server Appliance (VCSA) using the REST API - Part 1 (Postman Collection)
- Using PowerCLI to Set vCenter Permissions on Datacenter
- Using PowerCLI to Build Out vCenter
- Upgrading Platform Services Controller and vCenter Server via the CLI Installer
- Patching your vCenter Server Appliance from 6.7 to 6.7a