Set-AzVmssLifecycleHooksProfile
Attaches lifecycle hooks to a Virtual Machine Scale Set (VMSS) configuration or live VMSS object.
Syntax
Default (Default)
Set-AzVmssLifecycleHooksProfile
-VirtualMachineScaleSet <PSVirtualMachineScaleSet>
-LifecycleHook <LifecycleHook[]>
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
The Set-AzVmssLifecycleHooksProfile cmdlet attaches lifecycle hooks to a VMSS configuration object (PSVirtualMachineScaleSet) and returns the updated object. This follows the standard Az.Compute builder convention (same as Set-AzVmssOsProfile, Set-AzVmssStorageProfile): it mutates the VMSS config object AND returns it.
The updated object must be passed to New-AzVmss (for new scale sets) or Update-AzVmss (for existing scale sets) to persist the changes to Azure.
Examples
Example 1: Attach a lifecycle hook to a new VMSS configuration
$hook = New-AzVmssLifecycleHookConfig -Type 'UpgradeAutoOSScheduling' -WaitDuration 'PT8H'
$config = New-AzVmssConfig -Location 'eastus' -SkuCapacity 2
$config = Set-AzVmssLifecycleHooksProfile -VirtualMachineScaleSet $config -LifecycleHook $hook
New-AzVmss -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' -VirtualMachineScaleSet $config
This example creates a new VMSS with a lifecycle hook attached.
Example 2: Add a lifecycle hook to an existing VMSS
$vmss = Get-AzVmss -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss'
$existing = if ($vmss.LifecycleHooksProfile) { $vmss.LifecycleHooksProfile.LifecycleHooks } else { @() }
$batch = New-AzVmssLifecycleHookConfig -Type 'UpgradeAutoOSRollingBatchStarting' -WaitDuration 'PT30M'
$vmss = Set-AzVmssLifecycleHooksProfile -VirtualMachineScaleSet $vmss -LifecycleHook ($existing + $batch)
Update-AzVmss -ResourceGroupName 'myRg' -VMScaleSetName 'myVmss' -VirtualMachineScaleSet $vmss
This example adds a second lifecycle hook to an existing VMSS, preserving the existing hooks.
Example 3: Use pipeline to attach hooks
$hook = New-AzVmssLifecycleHookConfig -Type 'UpgradeAutoOSScheduling' -WaitDuration 'PT8H'
New-AzVmssConfig -Location 'eastus' -SkuCapacity 2 | Set-AzVmssLifecycleHooksProfile -LifecycleHook $hook
This example uses the pipeline to attach a lifecycle hook to a VMSS configuration.
Parameters
-Confirm
Prompts you for confirmation before running the cmdlet.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | cf |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-DefaultProfile
The credentials, account, tenant, and subscription used for communication with Azure.
Parameter properties
| Type: | IAzureContextContainer |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | AzContext, AzureRmContext, AzureCredential |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-LifecycleHook
One or more lifecycle hook objects to attach to the VMSS. Use 'New-AzVmssLifecycleHookConfig' to create hook objects. Replaces any existing lifecycle hooks on the VMSS config object.
Parameter properties
| Type: | |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
(All)
| Position: | 1 |
| Mandatory: | True |
| Value from pipeline: | False |
| Value from pipeline by property name: | True |
| Value from remaining arguments: | False |
-VirtualMachineScaleSet
The VMSS configuration object (PSVirtualMachineScaleSet) to update. Can be an in-memory config from 'New-AzVmssConfig' or a live VMSS object from 'Get-AzVmss'.
Parameter properties
| Type: | PSVirtualMachineScaleSet |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
(All)
| Position: | 0 |
| Mandatory: | True |
| Value from pipeline: | True |
| Value from pipeline by property name: | True |
| Value from remaining arguments: | False |
-WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | wi |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.