Skip to content

[Compute] Adding Scheduledevents to VM and VMSS#29123

Open
haagha wants to merge 6 commits intomainfrom
scheduledevents
Open

[Compute] Adding Scheduledevents to VM and VMSS#29123
haagha wants to merge 6 commits intomainfrom
scheduledevents

Conversation

@haagha
Copy link
Member

@haagha haagha commented Jan 30, 2026

Description

https://github.com/Azure/azure-powershell-cmdlet-review-pr/issues/1511

Mandatory Checklist

  • SHOULD update ChangeLog.md file(s) appropriately
    • Update src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.
      • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT adjust version of module manually in pull request

Haider Agha added 3 commits January 28, 2026 17:33
…zVM, and Update-AzVmss cmdlets

- Introduced `-ScheduledEventsApiVersion` to specify the API version for Scheduled Events configuration.
- Added `-EnableAllInstancesDown` to auto-approve Scheduled Events when all instances are down.
- Updated related help documentation for cmdlets to reflect new parameters.
- Enhanced handling of Scheduled Events policy in the cmdlet implementations.
@azure-client-tools-bot-prd
Copy link

Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Scheduled Events configuration support to Az.Compute VM/VMSS (and Availability Set) cmdlets by introducing two new parameters that populate ScheduledEventsPolicy in the corresponding ARM payloads.

Changes:

  • Added -ScheduledEventsApiVersion and -EnableAllInstancesDown parameters to VM/VMSS/Availability Set create/update cmdlets and wired them into request models.
  • Updated generated/help markdown to document the new parameters.
  • Added new scenario tests (and one new recording) intended to validate the behavior.

Reviewed changes

Copilot reviewed 23 out of 25 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
src/Compute/Compute/help/Update-AzVmss.md Documents new Scheduled Events parameters for Update-AzVmss (and adds -ProgressAction entry).
src/Compute/Compute/help/Update-AzVM.md Documents new Scheduled Events parameters for Update-AzVM (and adds -ProgressAction entry).
src/Compute/Compute/help/Update-AzAvailabilitySet.md Documents new Scheduled Events parameters for Update-AzAvailabilitySet (and adds -ProgressAction entry).
src/Compute/Compute/help/New-AzVmss.md Documents new Scheduled Events parameters for New-AzVmss and updates syntax block.
src/Compute/Compute/help/New-AzVM.md Documents new Scheduled Events parameters for New-AzVM and updates syntax block.
src/Compute/Compute/VirtualMachine/Operation/UpdateAzureVMCommand.cs Adds parameters and populates ScheduledEventsPolicy for VM update calls.
src/Compute/Compute/VirtualMachine/Operation/NewAzureVMCommand.cs Adds parameters and passes Scheduled Events inputs through strategy-based VM creation; also forwards ScheduledEventsPolicy from PSVirtualMachine to the SDK model.
src/Compute/Compute/Strategies/ComputeRp/VirtualMachineStrategy.cs Extends strategy VM config builder to construct ScheduledEventsPolicy during VM creation.
src/Compute/Compute/Strategies/ComputeRp/VirtualMachineScaleSetStrategy.cs Extends strategy VMSS config builder to construct ScheduledEventsPolicy during VMSS creation.
src/Compute/Compute/Models/PSVirtualMachine.cs Adds ScheduledEventsPolicy property to the PowerShell VM model.
src/Compute/Compute/Manual/VirtualMachineScaleSetCreateOrUpdateMethod.cs Adds Scheduled Events parameters to VMSS create cmdlet path and passes them into strategy config.
src/Compute/Compute/Manual/PSVirtualMachineScaleSet.cs Adds ScheduledEventsPolicy property to the PowerShell VMSS model.
src/Compute/Compute/Generated/VirtualMachineScaleSet/VirtualMachineScaleSetUpdateMethod.cs Adds Scheduled Events parameters to Update-AzVmss and applies them only in PUT path (not PATCH).
src/Compute/Compute/ChangeLog.md Adds an Upcoming Release note about the new parameters.
src/Compute/Compute/AvailabilitySets/UpdateAzureAvailabilitySetCommand.cs Adds parameters and populates ScheduledEventsPolicy for availability set updates.
src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.AvailabilitySetTests/TestAvailabilitySetScheduledEventsPolicy.json Adds a recording for the new availability set Scheduled Events scenario.
src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1 Adds a VM Scheduled Events scenario test script.
src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.cs Registers the new VM Scheduled Events scenario test for check-in runs.
src/Compute/Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.ps1 Adds a VMSS Scheduled Events scenario test script.
src/Compute/Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.cs Registers the new VMSS Scheduled Events scenario test for check-in runs.
src/Compute/Compute.Test/ScenarioTests/StrategiesVirtualMachineTests.ps1 Adds a strategy-based New-AzVM SimpleParameterSet Scheduled Events scenario test script.
src/Compute/Compute.Test/ScenarioTests/StrategiesVirtualMachineTests.cs Registers the new strategy-based Scheduled Events scenario test for check-in runs.
src/Compute/Compute.Test/ScenarioTests/AvailabilitySetTests.ps1 Adds an availability set Scheduled Events scenario test script.
src/Compute/Compute.Test/ScenarioTests/AvailabilitySetTests.cs Registers the new availability set Scheduled Events scenario test for check-in runs.
Comments suppressed due to low confidence (1)

src/Compute/Compute/help/New-AzVmss.md:651

  • The -HighSpeedInterconnectPlacement parameter help no longer lists its accepted values (e.g., None/Trunk). Other cmdlets in this module include an "Accepted values:" line for constrained strings; please restore that here to avoid losing important guidance.
### -HighSpeedInterconnectPlacement
Specifies the high speed interconnect placement for the virtual machine scale set.

```yaml
Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
</details>

Comment on lines +101 to +126
if (avSetParams.ScheduledEventsPolicy == null)
{
avSetParams.ScheduledEventsPolicy = new ScheduledEventsPolicy();
}

if (this.IsParameterBound(c => c.ScheduledEventsApiVersion))
{
if (avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets == null)
{
avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets = new ScheduledEventsAdditionalPublishingTargets();
}
if (avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph == null)
{
avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph = new EventGridAndResourceGraph();
}
avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph.ScheduledEventsApiVersion = this.ScheduledEventsApiVersion;
}

if (this.IsParameterBound(c => c.EnableAllInstancesDown))
{
if (avSetParams.ScheduledEventsPolicy.AllInstancesDown == null)
{
avSetParams.ScheduledEventsPolicy.AllInstancesDown = new AllInstancesDown();
}
avSetParams.ScheduledEventsPolicy.AllInstancesDown.AutomaticallyApprove = this.EnableAllInstancesDown;
}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cmdlet now sends ScheduledEventsPolicy on Availability Set create/update, but the recorded service response shows ARM returning 400 InvalidParameter "Scheduled Event Policy is not supported". Exposing these parameters will cause user-facing failures and will also break the new scenario test. Please gate this feature to supported API/regions, or remove these parameters until Availability Sets support ScheduledEventsPolicy, and consider surfacing a clearer error message if unsupported.

Suggested change
if (avSetParams.ScheduledEventsPolicy == null)
{
avSetParams.ScheduledEventsPolicy = new ScheduledEventsPolicy();
}
if (this.IsParameterBound(c => c.ScheduledEventsApiVersion))
{
if (avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets == null)
{
avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets = new ScheduledEventsAdditionalPublishingTargets();
}
if (avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph == null)
{
avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph = new EventGridAndResourceGraph();
}
avSetParams.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph.ScheduledEventsApiVersion = this.ScheduledEventsApiVersion;
}
if (this.IsParameterBound(c => c.EnableAllInstancesDown))
{
if (avSetParams.ScheduledEventsPolicy.AllInstancesDown == null)
{
avSetParams.ScheduledEventsPolicy.AllInstancesDown = new AllInstancesDown();
}
avSetParams.ScheduledEventsPolicy.AllInstancesDown.AutomaticallyApprove = this.EnableAllInstancesDown;
}
throw new PSInvalidOperationException(
"Scheduled Event Policy is not supported for Availability Sets in the current API or region. " +
"Remove 'ScheduledEventsApiVersion' and 'EnableAllInstancesDown' parameters and try again.");

Copilot uses AI. Check for mistakes.
Comment on lines +1588 to +1589
// To use ScheduledEventsApiVersion or EnableAllInstancesDown parameters,
// you must provide a VirtualMachineScaleSet object which will use the CreateOrUpdate path.
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update-AzVmss accepts -ScheduledEventsApiVersion/-EnableAllInstancesDown, but in the PATCH path (when -VirtualMachineScaleSet is not provided) these parameters are silently ignored because VirtualMachineScaleSetUpdate doesn’t support ScheduledEventsPolicy. Please enforce this at runtime (e.g., throw a terminating error if either parameter is bound while VirtualMachineScaleSet is null) or otherwise ensure the parameters have effect.

Suggested change
// To use ScheduledEventsApiVersion or EnableAllInstancesDown parameters,
// you must provide a VirtualMachineScaleSet object which will use the CreateOrUpdate path.
// When using the PATCH path (VirtualMachineScaleSet is null), ScheduledEventsApiVersion and
// EnableAllInstancesDown parameters are not applied and are therefore rejected at runtime.
if (this.VirtualMachineScaleSet == null &&
(this.IsParameterBound(c => c.ScheduledEventsApiVersion) ||
this.IsParameterBound(c => c.EnableAllInstancesDown)))
{
throw new PSArgumentException("ScheduledEventsApiVersion and EnableAllInstancesDown parameters are only supported when updating a Virtual Machine Scale Set using the CreateOrUpdate path. Provide a VirtualMachineScaleSet object or remove these parameters.");
}

Copilot uses AI. Check for mistakes.
Comment on lines 434 to 443
$asetUpdated = $aset | Update-AzAvailabilitySet `
-ScheduledEventsApiVersion $apiVersion -EnableAllInstancesDown $true;

# Verify the properties are set
Assert-NotNull $asetUpdated.ScheduledEventsPolicy;
Assert-NotNull $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets;
Assert-NotNull $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph;
Assert-AreEqual $apiVersion $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph.ScheduledEventsApiVersion;
Assert-NotNull $asetUpdated.ScheduledEventsPolicy.AllInstancesDown;
Assert-AreEqual $true $asetUpdated.ScheduledEventsPolicy.AllInstancesDown.AutomaticallyApprove;
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scenario test asserts ScheduledEventsPolicy is set on the updated availability set, but the added session recording shows the update request fails with 400 "Scheduled Event Policy is not supported". Either the cmdlet behavior/feature gating needs to change, or this test should be updated to validate the expected failure instead of asserting success.

Suggested change
$asetUpdated = $aset | Update-AzAvailabilitySet `
-ScheduledEventsApiVersion $apiVersion -EnableAllInstancesDown $true;
# Verify the properties are set
Assert-NotNull $asetUpdated.ScheduledEventsPolicy;
Assert-NotNull $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets;
Assert-NotNull $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph;
Assert-AreEqual $apiVersion $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph.ScheduledEventsApiVersion;
Assert-NotNull $asetUpdated.ScheduledEventsPolicy.AllInstancesDown;
Assert-AreEqual $true $asetUpdated.ScheduledEventsPolicy.AllInstancesDown.AutomaticallyApprove;
# The service currently does not support Scheduled Event Policy on availability sets
# and returns HTTP 400 "Scheduled Event Policy is not supported".
# Validate that the cmdlet surfaces this failure instead of assuming success.
Assert-ThrowsContains {
$null = $aset | Update-AzAvailabilitySet `
-ScheduledEventsApiVersion $apiVersion -EnableAllInstancesDown $true;
} "Scheduled Event Policy is not supported";

Copilot uses AI. Check for mistakes.
Comment on lines 707 to 712
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestVirtualMachineScheduledEventsPolicy()
{
TestRunner.RunTestScript("Test-VirtualMachineScheduledEventsPolicy 'eastus2euap'");
}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new [CheckIn] scenario test will require a corresponding session record under Compute.Test/SessionRecords for playback runs. Please add the recorded HTTP session (or mark the test LiveOnly if it cannot be reliably recorded).

Copilot uses AI. Check for mistakes.
```

### -ProgressAction
{{ Fill ProgressAction Description }}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated help still contains the placeholder text "{{ Fill ProgressAction Description }}" for -ProgressAction. Please replace it with a real description (or regenerate help so it’s populated) before merging, since this renders the published reference help incomplete.

Suggested change
{{ Fill ProgressAction Description }}
Specifies how this cmdlet reports progress updates. Use `SilentlyContinue` to suppress progress output.

Copilot uses AI. Check for mistakes.
Comment on lines 518 to 523
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestVirtualMachineScaleSetScheduledEventsPolicy()
{
TestRunner.RunTestScript("Test-VirtualMachineScaleSetScheduledEventsPolicy 'eastus2euap'");
}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new [CheckIn] scenario test will require a corresponding session record under Compute.Test/SessionRecords for playback runs. Please add the recorded HTTP session (or mark the test LiveOnly if it cannot be reliably recorded).

Copilot uses AI. Check for mistakes.
Comment on lines +194 to +199
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSimpleNewVmScheduledEventsPolicy()
{
TestRunner.RunTestScript("Test-SimpleNewVmScheduledEventsPolicy");
}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new [CheckIn] scenario test will require a corresponding session record under Compute.Test/SessionRecords for playback runs. Please add the recorded HTTP session (or mark the test LiveOnly if it cannot be reliably recorded).

Copilot uses AI. Check for mistakes.
```

### -ProgressAction
{{ Fill ProgressAction Description }}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated help still contains the placeholder text "{{ Fill ProgressAction Description }}" for -ProgressAction. Please replace it with a real description (or regenerate help so it’s populated) before merging, since this renders the published reference help incomplete.

Suggested change
{{ Fill ProgressAction Description }}
Specifies how the cmdlet responds to progress updates, such as whether to display or silently ignore progress information.

Copilot uses AI. Check for mistakes.
```

### -ProgressAction
{{ Fill ProgressAction Description }}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated help still contains the placeholder text "{{ Fill ProgressAction Description }}" for -ProgressAction. Please replace it with a real description (or regenerate help so it’s populated) before merging, since this renders the published reference help incomplete.

Suggested change
{{ Fill ProgressAction Description }}
Specifies how PowerShell responds to progress updates for this cmdlet, such as displaying or silently ignoring progress.

Copilot uses AI. Check for mistakes.
```

### -ProgressAction
{{ Fill ProgressAction Description }}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated help still contains the placeholder text "{{ Fill ProgressAction Description }}" for -ProgressAction. Please replace it with a real description (or regenerate help so it’s populated) before merging, since this renders the published reference help incomplete.

Suggested change
{{ Fill ProgressAction Description }}
Specifies how PowerShell displays and handles progress updates for the operation, such as Continue, SilentlyContinue, or Stop.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings February 3, 2026 16:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 21 changed files in this pull request and generated 3 comments.

```

### -ProgressAction
{{ Fill ProgressAction Description }}
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-ProgressAction has placeholder help text ({{ Fill ProgressAction Description }}) in the generated help. Please replace with standard common-parameter wording (or regenerate help to populate it).

Suggested change
{{ Fill ProgressAction Description }}
Specifies how PowerShell responds to progress updates for the cmdlet.

Copilot uses AI. Check for mistakes.
public bool? EnableAllInstancesDown { get; set; }

private void BuildPatchObject()
{
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update-AzVmss exposes -ScheduledEventsApiVersion / -EnableAllInstancesDown, but in the default (patch) path (VirtualMachineScaleSet == null) BuildPatchObject() does not apply them and may leave VirtualMachineScaleSetUpdate null. If a user specifies only these new parameters, the cmdlet can fall through to CreateOrUpdate(...) with an empty VirtualMachineScaleSet payload (AutoMapper maps from null), which risks overwriting the VMSS configuration. Add explicit handling: either (1) force the PUT path by loading the current VMSS and applying ScheduledEventsPolicy, (2) restrict these parameters to the PUT parameter set (require -VirtualMachineScaleSet input), or (3) throw a terminating error when these parameters are used without a VMSS object.

Suggested change
{
{
// The ScheduledEvents parameters are only safely supported when a full
// VirtualMachineScaleSet object is provided (PUT path). When the cmdlet is
// invoked on the default (patch) path with these parameters and without a
// VirtualMachineScaleSet object, there is a risk of sending an unintended
// empty VMSS payload. To prevent this, we explicitly disallow that
// combination of inputs.
if (this.VirtualMachineScaleSet == null &&
(this.IsParameterBound(c => c.ScheduledEventsApiVersion) ||
this.IsParameterBound(c => c.EnableAllInstancesDown)))
{
throw new PSInvalidOperationException(
"The ScheduledEventsApiVersion and EnableAllInstancesDown parameters can only be used when a VirtualMachineScaleSet object is supplied. Use 'Get-AzVmss' to retrieve the scale set and pipe it to 'Update-AzVmss' when configuring Scheduled Events.");
}

Copilot uses AI. Check for mistakes.
Comment on lines 432 to 444
# Update with ScheduledEventsPolicy
$apiVersion = "2020-07-01";
$asetUpdated = $aset | Update-AzAvailabilitySet `
-ScheduledEventsApiVersion $apiVersion -EnableAllInstancesDown $true;

# Verify the properties are set
Assert-NotNull $asetUpdated.ScheduledEventsPolicy;
Assert-NotNull $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets;
Assert-NotNull $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph;
Assert-AreEqual $apiVersion $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph.ScheduledEventsApiVersion;
Assert-NotNull $asetUpdated.ScheduledEventsPolicy.AllInstancesDown;
Assert-AreEqual $true $asetUpdated.ScheduledEventsPolicy.AllInstancesDown.AutomaticallyApprove;
}
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new test asserts that updating an availability set with ScheduledEventsPolicy succeeds, but the committed session record for this test includes a 400 response ("Scheduled Event Policy is not supported"). In playback, the cmdlet will throw and these assertions will fail. Update the recording to a region/API where the feature is supported, or change the test to expect/handle the unsupported response (and align the session record accordingly).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants