PowerCLI script to backup, restore and verify DRS Automation Level settings for a vCenter Server
search cancel

PowerCLI script to backup, restore and verify DRS Automation Level settings for a vCenter Server

book

Article ID: 311970

calendar_today

Updated On:

Products

VMware Cloud Foundation

Issue/Introduction

The Backup and Restore Utility for vSphere DRS Automation Level is a PowerShell script that users can use to backup, restore, and verify the vSphere DRS Automation Level settings.

The utility helps to mitigate most of the VC considerations and limitations for the VC backup.
For more information, see Considerations and Limitations for File-Based Backup and Restore

It will stop DRS Migration and if new VM is registered/deployed, you will be asked for a placement, since DRS will be set to Manual. 
The main usage for this script is vCenter upgrade/maintenance workflows:
1. Execute script in backup mode.
2. Verify that there are no VM migrations running.
2. Create vCenter File based backup.
3. Do the intended maintenance.
4. Restore setting that have been saved in Step #1.

Environment

VMware Cloud Foundation 4.x

Resolution

When it is launched in backup mode, it backs up the current DRS Automation Level settings in a JSON file and update the DRS Automation value to 'Manual'. The utility skips update task on the cluster where DRS Automation Level value is already set to manual or vSphere DRS is disabled.

When it is launched in restore mode, it restores the DRS Automation Level values for each cluster from the JSON file. Once the restore task is completed, it automatically verifies the DRS Automation Level setting of the clusters with the selected JSON file to verify that the settings are applied successfully. Note: The utility skips restore task on the cluster where DRS Automation Level value were set to manual before backup or vSphere DRS is disabled. 

When it is launched in verify mode, it verifies the DRS Automation Level values for each cluster with the JSON file.
The utility skips verify task on the cluster where vSphere DRS is disabled. 

Prerequisites:
  1. Windows 10, Windows Server 2016 or Windows Server 2019.
  2. VMware PowerCLI
Execution policy should be set to "RemoteSigned":
    1. Set Windows PowerShell execution policy:
         PS C:\> Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
    2. Close the current Windows PowerShell window, re-start Windows PowerShell

If selfsignd/not Trusted certificates are used on the VC, please execute the following command :
 PS C:\> Set-PowerCLIConfiguration -Scope Session -InvalidCertificateAction Prompt

Usage:
Use the utility to back up the current DRS Automation Level value and update DRS Automation value to 'Manual'

    1. Open a Windows PowerShell prompt and navigate to the directory where you extracted the attached .zip.
    2. Run the PowerShell script to launch the menu.
        .\Backup_Restore_vSphere_DRS_Automation_Level.ps1
    3. Enter the FQDN or IP address of vCenter Server and press Enter.
    4. When prompted, enter the vCenter Server credentials and select OK.
    5. Select Option 1 to back up the current DRS Automation Level settings in a JSON file and
         update the DRS  Automation value to 'Manual'.

Note: The settings are saved in a JSON file and stored in the same directory. JSON filename contains IP/FQDN of the VC and timestamp.

Use the utility to restore the DRS Automation Level values for each cluster from the JSON file:

    1. Run the PowerShell script to launch the menu.
        .\Backup_Restore_vSphere_DRS_Automation_Level.ps1
    2. Enter the FQDN or IP address of vCenter Server and press Enter.
    3. When prompted, enter the vCenter Server credentials and select OK.
    4. Select Option 2 and when prompted, select the path to the relevant JSON file (stored by option 1)
        containing the DRS Automation Level settings of clusters. 
    5. Press ‘Y’ to confirm the restore task.
    6. Once the restore task is completed, it automatically verifies the DRS Automation Level setting of the
        clusters  with the selected JSON file to verify the settings are applied successfully.

Use the utility to verify the DRS Automation Level values for each cluster from the JSON file:

    1. Run the PowerShell script to launch the menu.
        .\Backup_Restore_vSphere_DRS_Automation_Level.ps1
    2. Enter the FQDN or IP address of vCenter Server and press Enter.
    3. When prompted, enter the vCenter Server credentials and select OK.
    4. Select Option 3 and when prompted, select the path to the relevant JSON file (stored by option 1)
        containing  the DRS Automation Level settings of clusters. 
    5. Press ‘Y’ to confirm the verify task.
    6. It verifies the DRS Automation Level value of the clusters with the selected JSON file to check
        the configuration drift.

As an alternative to the interactive approach, the utility could be used in command line mode with the following arguments:
  • Command to back up the current DRS Automation Level value and then update DRS Automation value to 'Manual'
.\Backup_Restore_vSphere_DRS_Automation_Level.ps1 -vCenterServer 'sfo-m01-vc01.sfo.rainpole.io' -username '[email protected]'  -password ‘*********’ -task "Backup"
  • Command to restore the DRS Automation Level values for each cluster from the JSON file
.\Backup_Restore_vSphere_DRS_Automation_Level.ps1  -vCenterServer 'sfo-m01-vc01.sfo.rainpole.io' -username '[email protected]' -password ‘*********’ -task "Restore" jsonFile ‘sfo-m01-vc01.sfo.rainpole.io_02-10-2022_19-55-06.json’
  • Command to verify the DRS Automation Level values for each cluster with the JSON file
.\Backup_Restore_vSphere_DRS_Automation_Level.ps1  -vCenterServer 'sfo-m01-vc01.sfo.rainpole.io' -username '[email protected]' -password ‘*********’ -task "Verify" -jsonFile ‘sfo-m01-vc01.sfo.rainpole.io_02-10-2022_19-55-06.json’










Attachments

Backup_Restore_vSphere_DRS_Automation_Level get_app