Automatic update Golden Images with Nutanix X-Play

In Nutanix Prism Central we have the feature named X-Play. You have seen more on this topic om my blog so here is another one 😉 In my training’s lab students are connecting to a terminal server. Updating the applications and Windows in the Golden Image is a monthly job. I dont like manual work so in this blogpost I will describe how I automatically update the Golden Image every month.

There are 3 things that needs to be done:

  1. Windows Update;
    • Windows update is done via PowerShell
  2. Applications update;
    • I’m using the NeverRed script from Manual Winkel: Link.
    • NeverRed can also handle the Windows update but I’m doing this separate;
  3. Optimize/Seal script;
    • Running a full virus scan the Citrix optimize tool and some other stuff.

Time to run: End of day on “Microsoft Patch Tuesday” (Second Tuesday of each month).

On the Golden Image there is a C:\Scripts folder created containing the following subfolders:

  1. C:\Scripts\NeverRed – This contains the NeverRed scripts.
    • Scriptname: Run_NeverRed.ps1
      • Contains: & C:\Scripts\NeverRed\NeverRed.ps1 -ESFile C:\Scripts\NeverRed\LastSetting.txt
  2. C:\Scripts\WindowsUpdate – This contains the Windows update script.
    • Scriptname: Install_WindowsUpdate.ps1
      • Contains: Get-WindowsUpdate -AcceptAll -Install -IgnoreReboot
  3. C:\Scripts\CitrixOptimizer – This container the CitrixOptimizer and seal script.
    • Scriptname: Optimize.cmd and Optimize.ps1 (We cant run batch files from X-Play and my optimize/seal script is based on batch 😉 To lazy to convert to powershell)
      • Optimize.ps1 contains: cmd.exe /c “C:\Scripts\CitrixOptimizer\Optimize.cmd”
      • Optimize.cmd contains:
@ECHO OFF

:: Citrix Optimize Script 
:: Created by Jeroen Tielen - Tielen Consultancy - jeroen@tielenconsultancy.nl
:: Version 1.0 - Initial Script;
:: Version 1.1 - EntraID Leave Added.

ECHO Leaving EntraID...
DSRegCMD /Leave

ECHO Optimizing .NET Frameworks...
%WINDIR%\Microsoft.NET\Framework\v2.0.50727\ngen.exe executequeueditems
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\ngen.exe executequeueditems
%WINDIR%\Microsoft.NET\Framework64\v2.0.50727\ngen.exe executequeueditems
%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\ngen.exe executequeueditems

REM ScanTypes: 1 = Quick, 2 = Full and 3 = Custom. 
ECHO Running Full Virus Scan...
"%ProgramFiles%\Windows Defender\MpCmdRun.exe" -Scan -ScanType 2
ECHO Running Quick Virus Scan...
"%ProgramFiles%\Windows Defender\MpCmdRun.exe" -Scan -ScanType 1

ECHO Running Citrix Optimizer...
PowerShell -ExecutionPolicy Bypass C:\Scripts\CitrixOptimizer\CtxOptimizerEngine.ps1 'C:\Scripts\CitrixOptimizer\Templates\Citrix_Windows_Server_2025_2009.xml' -Mode execute

ECHO Cleanup Log Folder...
RD /S /Q C:\Log

Now that we got all scripts in place we need to create the Playbook.

Copy the following text into a text file and save it with extension “pbk”

{
  "pcVersion": "7.3.0.5",
  "pcUuid": "e443344f-02b5-45e7-89d6-9f9b658150a0",
  "hashValue": "Ic/ksngzHdrfBq32LUCE0oY4e3j5yuHvTLcEUWBTMBk=",
  "actionRuleList": [
    {
      "uuid": "fc1d236f-998d-41f5-6b41-d35c3933d4b8",
      "name": "Golden Image Monthy Update",
      "isEnabled": true,
      "validated": true,
      "triggerList": [
        {
          "uuid": "ae5a48ba-95c7-429e-8cb5-cb4d3e306f2d",
          "triggerType": {
            "type": "trigger_type",
            "uuid": "",
            "name": "time_trigger"
          },
          "displayName": "Time",
          "inputParameterList": [
            {
              "name": "occurrence",
              "value": "recurring"
            },
            {
              "name": "day_of_week",
              "value": "2"
            },
            {
              "name": "month_multiplier",
              "value": "1"
            },
            {
              "name": "start_date",
              "value": "2025-08-08"
            },
            {
              "name": "recurrence",
              "value": "monthly"
            },
            {
              "name": "week_of_month",
              "value": "1"
            },
            {
              "name": "time_of_day",
              "value": "T21:00:00+01:00"
            },
            {
              "name": "monthly_recurrence_type",
              "value": "week_day"
            }
          ]
        }
      ],
      "actionList": [
        {
          "uuid": "f68766b0-ade9-4c7b-90ac-74d4c3f4cee1",
          "actionType": {
            "type": "action_type",
            "uuid": "",
            "name": "vm_power_on_action"
          },
          "displayName": "Power On VM",
          "inputParameterList": [
            {
              "name": "target_vm",
              "value": ""
            }
          ],
          "maxRetries": 2,
          "description": "Start the Golden Image VM",
          "childActionUuids": [
            "a29c5d25-72b7-4ca5-9c32-4c8fd57d7469"
          ]
        },
        {
          "uuid": "a29c5d25-72b7-4ca5-9c32-4c8fd57d7469",
          "actionType": {
            "type": "action_type",
            "uuid": "",
            "name": "wait_for_duration"
          },
          "displayName": "Wait for Some Time",
          "inputParameterList": [
            {
              "name": "wait_duration",
              "value": "2"
            },
            {
              "name": "block_resume",
              "value": "false"
            },
            {
              "name": "post_check_trigger_validity",
              "value": "false"
            },
            {
              "name": "stop_after_time",
              "value": "false"
            }
          ],
          "maxRetries": 2,
          "description": "Give The Golden Image Some Time To Boot",
          "postCheckTriggerValidity": false,
          "childActionUuids": [
            "655030fc-42af-45df-b454-be4942db3e9d"
          ]
        },
        {
          "uuid": "655030fc-42af-45df-b454-be4942db3e9d",
          "actionType": {
            "type": "action_type",
            "uuid": "",
            "name": "powershell_using_vm_entity"
          },
          "displayName": "VM Powershell",
          "inputParameterList": [
            {
              "name": "password",
              "value": ""
            },
            {
              "name": "vm_entity",
              "value": ""
            },
            {
              "name": "script_path",
              "value": "C:\\Scripts\\NeverRed\\Run_NeverRed.ps1"
            },
            {
              "name": "https",
              "value": "false"
            },
            {
              "name": "username",
              "value": ".\\administrator"
            }
          ],
          "maxRetries": 2,
          "description": "Update Applications With NeverRed",
          "childActionUuids": [
            "8111ef36-91e1-481d-99b1-7383c2fb20e9"
          ]
        },
        {
          "uuid": "8111ef36-91e1-481d-99b1-7383c2fb20e9",
          "actionType": {
            "type": "action_type",
            "uuid": "",
            "name": "vm_reboot_action"
          },
          "displayName": "VM Reboot",
          "inputParameterList": [
            {
              "name": "target_vm",
              "value": ""
            },
            {
              "name": "is_guest",
              "value": "false"
            }
          ],
          "maxRetries": 2,
          "description": "Reboot The Golden Image",
          "childActionUuids": [
            "62e96e44-d636-439c-93d8-162bff2d3a10"
          ]
        },
        {
          "uuid": "62e96e44-d636-439c-93d8-162bff2d3a10",
          "actionType": {
            "type": "action_type",
            "uuid": "",
            "name": "wait_for_duration"
          },
          "displayName": "Wait for Some Time",
          "inputParameterList": [
            {
              "name": "wait_duration",
              "value": "2"
            },
            {
              "name": "block_resume",
              "value": "false"
            },
            {
              "name": "post_check_trigger_validity",
              "value": "false"
            },
            {
              "name": "stop_after_time",
              "value": "false"
            }
          ],
          "maxRetries": 2,
          "description": "Give The Golden Image Some Time To Boot",
          "postCheckTriggerValidity": false,
          "childActionUuids": [
            "15b08cf8-f4a6-49c0-904b-29de54c130ad"
          ]
        },
        {
          "uuid": "15b08cf8-f4a6-49c0-904b-29de54c130ad",
          "actionType": {
            "type": "action_type",
            "uuid": "",
            "name": "powershell_using_vm_entity"
          },
          "displayName": "VM Powershell",
          "inputParameterList": [
            {
              "name": "password",
              "value": ""
            },
            {
              "name": "vm_entity",
              "value": ""
            },
            {
              "name": "script_path",
              "value": "C:\\Scripts\\WindowsUpdate\\Install_WindowsUpdate.ps1"
            },
            {
              "name": "https",
              "value": "false"
            },
            {
              "name": "username",
              "value": ".\\administrator"
            }
          ],
          "maxRetries": 2,
          "description": "Install Windows Update",
          "childActionUuids": [
            "9ae58c52-00f8-48c4-8c01-9c7e1cff6443"
          ]
        },
        {
          "uuid": "9ae58c52-00f8-48c4-8c01-9c7e1cff6443",
          "actionType": {
            "type": "action_type",
            "uuid": "",
            "name": "vm_reboot_action"
          },
          "displayName": "VM Reboot",
          "inputParameterList": [
            {
              "name": "target_vm",
              "value": ""
            },
            {
              "name": "is_guest",
              "value": "false"
            }
          ],
          "maxRetries": 2,
          "description": "Reboot The Golden Image",
          "childActionUuids": [
            "44040874-c211-4f0e-bb95-55b8d2356782"
          ]
        },
        {
          "uuid": "44040874-c211-4f0e-bb95-55b8d2356782",
          "actionType": {
            "type": "action_type",
            "uuid": "",
            "name": "wait_for_duration"
          },
          "displayName": "Wait for Some Time",
          "inputParameterList": [
            {
              "name": "wait_duration",
              "value": "20"
            },
            {
              "name": "block_resume",
              "value": "false"
            },
            {
              "name": "post_check_trigger_validity",
              "value": "false"
            },
            {
              "name": "stop_after_time",
              "value": "false"
            }
          ],
          "maxRetries": 2,
          "description": "Give The Golden Image Some Time To Boot And Finalize Updates",
          "postCheckTriggerValidity": false,
          "childActionUuids": [
            "c12e7980-8982-4ef0-a8fd-ef1339981054"
          ]
        },
        {
          "uuid": "c12e7980-8982-4ef0-a8fd-ef1339981054",
          "actionType": {
            "type": "action_type",
            "uuid": "",
            "name": "powershell_using_vm_entity"
          },
          "displayName": "VM Powershell",
          "inputParameterList": [
            {
              "name": "password",
              "value": ""
            },
            {
              "name": "vm_entity",
              "value": ""
            },
            {
              "name": "script_path",
              "value": "C:\\Scripts\\CitrixOptimizer\\Optimize.ps1"
            },
            {
              "name": "https",
              "value": "false"
            },
            {
              "name": "username",
              "value": ".\\administrator"
            }
          ],
          "maxRetries": 2,
          "description": "Run Citrix Optimizer And Seal Script",
          "childActionUuids": [
            "5b845513-e249-457d-a09b-cde7cf168ba4"
          ]
        },
        {
          "uuid": "5b845513-e249-457d-a09b-cde7cf168ba4",
          "actionType": {
            "type": "action_type",
            "uuid": "",
            "name": "vm_power_off_action"
          },
          "displayName": "Power Off VM",
          "inputParameterList": [
            {
              "name": "target_vm",
              "value": ""
            },
            {
              "name": "power_state_mechanism",
              "value": "acpi"
            }
          ],
          "maxRetries": 2,
          "description": "Shutdown The Golden Image",
          "childActionUuids": [
            "33876b04-92ef-421d-830b-80531e6c0cfe"
          ]
        },
        {
          "uuid": "33876b04-92ef-421d-830b-80531e6c0cfe",
          "actionType": {
            "type": "action_type",
            "uuid": "",
            "name": "wait_for_duration"
          },
          "displayName": "Wait for Some Time",
          "inputParameterList": [
            {
              "name": "wait_duration",
              "value": "1"
            },
            {
              "name": "block_resume",
              "value": "false"
            },
            {
              "name": "post_check_trigger_validity",
              "value": "false"
            },
            {
              "name": "stop_after_time",
              "value": "false"
            }
          ],
          "maxRetries": 2,
          "description": "Let The Golden Image Completely Shutdown",
          "postCheckTriggerValidity": false,
          "childActionUuids": [
            "9c6a5e88-562a-4c05-be4a-3892ec23551c"
          ]
        },
        {
          "uuid": "9c6a5e88-562a-4c05-be4a-3892ec23551c",
          "actionType": {
            "type": "action_type",
            "uuid": "",
            "name": "ssh_using_ipaddr"
          },
          "displayName": "IP Address SSH",
          "inputParameterList": [
            {
              "name": "password",
              "value": ""
            },
            {
              "name": "ssh_command",
              "value": "acli vm.snapshot_create Windows-GI snapshot_name_list=Updated-$(date -I)"
            },
            {
              "name": "allow_on_cvm",
              "value": "true"
            },
            {
              "name": "username",
              "value": "admin"
            },
            {
              "name": "ip_addr",
              "value": "10.0.0.30"
            },
            {
              "name": "auth_mechanism",
              "value": "password"
            }
          ],
          "maxRetries": 2,
          "description": "Create Snapshot Of Golden Images"
        }
      ],
      "isPrepackaged": false,
      "checkTriggerValidity": true,
      "description": "Update Windows and Applications in the Golden Image",
      "ruleType": "kXPlay"
    }
  ]
}

Import the pbk file as a playbook in Prism Central. When imported you need to update it to match your environment.

Change all steps to match the Golden Image VM. In the VM Powershell sections add the correct password (I’m using the local administrator account as I don’t want a cached domain user in the Golden Image). In the last step (IP Address SSH) there will be a snapshot created. Change this to you Prism Element cluster IP and don’t forget to add the correct VM name in the command. (Don’t use spaced in VM Names)

When all is correct the playbook will automatically start on the given time. And your Golden Images will be updated automatically.

Posts created 145

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top