Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -689,5 +689,12 @@ public void TestEncryptionIdentityNotPartOfAssignedIdentitiesInAzureVm()
{
TestRunner.RunTestScript("Test-EncryptionIdentityNotPartOfAssignedIdentitiesInAzureVm");
}
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void testgeninvokeazvminstallpatch()
{
TestRunner.RunTestScript("TestGen-invokeazvminstallpatch");
}
}
}
66 changes: 66 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7889,3 +7889,69 @@ function Test-EncryptionIdentityNotPartOfAssignedIdentitiesInAzureVm{
}
}


function TestGen-invokeazvminstallpatch
{
# Setup
$rgname = Get-ComputeTestResourceName;
$loc = Get-Location;

try
{
New-AzResourceGroup -Name $rgname -Location $loc -Force;

# VM Profile & Hardware
$vmname = 'vm' + $rgname;
$vmsize = "Standard_B1s";
$domainNameLabel = "d1" + $rgname;
$stnd = "Standard";

# Creating a VM
$p = New-AzVmConfig -VMName $vmname -vmsize $vmsize -SecurityType $stnd;

$publisherName = "MicrosoftWindowsServer"
$offer = "WindowsServer"
$sku = "2019-DataCenter"
$p = Set-AzVMSourceImage -VM $p -PublisherName $publisherName -Offer $offer -Skus $sku -Version 'latest'

# NRP
$subnet = New-AzVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
$vnet = New-AzVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
$vnet = Get-AzVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
$subnetId = $vnet.Subnets[0].Id;
$pubip = New-AzPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel;
$pubip = Get-AzPublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname;
$pubipId = $pubip.Id;
$nic = New-AzNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id;
$nic = Get-AzNetworkInterface -Name ('nic' + $rgname) -ResourceGroupName $rgname;
$nicId = $nic.Id;

$p = Add-AzVMNetworkInterface -VM $p -Id $nicId;

# OS & Image
$user = "Foo12";
$password = $PLACEHOLDER;
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
$computerName = 'test';

$p = Set-AzVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred;

$vm = New-AzVM -ResourceGroupName $rgname -Location $loc -Vm $p
$vm = Get-AzVM -ResourceGroupName $rgname -Name $vmname

Assert-NotNull $vm;

# Test with maxPatchPublishDate parameter
$maxPatchPublishDate = (Get-Date).AddDays(-30).ToString("yyyy-MM-ddTHH:mm:ssZ")
$patchResult = Invoke-azvminstallpatch -VM $vm -windows -RebootSetting 'Never' -MaximumDuration PT1H -ClassificationToIncludeForWindows critical -maxPatchPublishDate $maxPatchPublishDate

Assert-AreEqual 'Succeeded' $patchResult.Status

}
finally
{
# Cleanup
Remove-AzResourceGroup -Name $rgname -Force -ErrorAction SilentlyContinue;
}
}
2 changes: 2 additions & 0 deletions src/Compute/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

-->
## Upcoming Release
* Added new optional parameter `maxPatchPublishDate` to the `Invoke-AzVMInstallPatch` cmdlet
- Allows installation of patches published on or before a specified date.

## Version 9.1.0
* Added new parameter `EncryptionIdentity` to cmdlet `Set-AzVmssDiskEncryptionExtension`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -233,6 +233,10 @@ public partial class InvokeAzureVMInstallPatch : ComputeAutomationBaseCmdlet
[PSArgumentCompleter("Critical", "Security", "Other")]
public string[] ClassificationToIncludeForLinux { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "This is used to install patches that were published on or before this given max published date. It should be a dateTime parsable date string.")]
public string MaxPatchPublishDate { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }
Expand Down Expand Up @@ -278,6 +282,11 @@ public override void ExecuteCmdlet()
vmInstallPatchesParameters.MaximumDuration = this.MaximumDuration;
vmInstallPatchesParameters.RebootSetting = this.RebootSetting;

if (!string.IsNullOrEmpty(this.MaxPatchPublishDate))
{
vmInstallPatchesParameters.MaxPatchPublishDate = DateTime.Parse(this.MaxPatchPublishDate);
}

// divde linux and windows
if (this.Windows.IsPresent)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Copyright (c) Microsoft and contributors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -35,5 +35,6 @@ public class PSVirtualMachineInstallPatchesResult
public IList<PatchInstallationDetail> Patches { get; set; }
public DateTime? StartDateTime { get; set; }
public ApiError Error { get; set; }
public string MaxPatchPublishDate { get; set; }
}
}