Skip to content

Commit e4414ed

Browse files
author
Maddie Clayton
authored
Merge pull request #8816 from niander/setVMCSEParameterSets
Add new parameter sets to Set-AzVMCustomScriptExtension with piping for resource id, resource and top level resource objects
2 parents 4a3f52e + 94bd793 commit e4414ed

File tree

10 files changed

+4779
-71
lines changed

10 files changed

+4779
-71
lines changed

documentation/development-docs/azure-powershell-developer-guide.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ Please see our guide on [Using Azure TestFramework](../testing-docs/using-azure-
260260
- Use `Assert-NotNull object` to verify that an object is not null
261261
- Use `Assert-Exists path` to verify that a file exists
262262
- Use `Assert-AreEqualArray a1 a2` to verify that arrays are the same
263+
- Use `Assert-StartsWith s1 s2` to verify that the string `s2` starts with the string `s1`
264+
- Use `Assert-Match s1 s2` to verify that the string `s2` matches the regular expression `s1`
265+
- Use `Assert-NotMatch s1 s2` to verify that the string `s2` does not match the regular expression `s1`
263266

264267
### Using Active Directory
265268

src/Compute/Compute.Test/ScenarioTests/VirtualMachineExtensionTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ public void TestVirtualMachineCustomScriptExtension()
4545
TestRunner.RunTestScript("Test-VirtualMachineCustomScriptExtension");
4646
}
4747

48+
[Fact]
49+
[Trait(Category.AcceptanceType, Category.CheckIn)]
50+
public void TestVirtualMachineCustomScriptExtensionPiping()
51+
{
52+
TestRunner.RunTestScript("Test-VirtualMachineCustomScriptExtensionPiping");
53+
}
54+
4855
[Fact]
4956
[Trait(Category.AcceptanceType, Category.CheckIn)]
5057
public void TestVirtualMachineCustomScriptExtensionWrongStorage()

src/Compute/Compute.Test/ScenarioTests/VirtualMachineExtensionTests.ps1

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,72 @@ function Test-VirtualMachineCustomScriptExtension
483483
}
484484
}
485485

486+
function Test-VirtualMachineCustomScriptExtensionPiping
487+
{
488+
# Setup
489+
$rgname = Get-ComputeTestResourceName
490+
491+
try
492+
{
493+
# Common
494+
$loc = Get-ComputeVMLocation;
495+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
496+
497+
$vmname = 'vm' + $rgname;
498+
$user = "Foo12";
499+
$password = $PLACEHOLDER;
500+
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
501+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
502+
[string]$domainNameLabel = "$vmname-$vmname".tolower();
503+
$vmobject = New-AzVm -Name $vmname -ResourceGroupName $rgname -Credential $cred -DomainNameLabel $domainNameLabel;
504+
505+
$csename = "myCustomExtension";
506+
$fileUri = "https://raw.githubusercontent.com/neilpeterson/nepeters-azure-templates/master/windows-custom-script-simple/support-scripts/Create-File.ps1";
507+
$runname = "Create-File.ps1";
508+
509+
# Parameter set interactive
510+
Set-AzVMCustomScriptExtension -ResourceGroupName $rgname -VMName $vmname -Name $csename `
511+
-Location $loc -FileUri $fileUri -Run $runname;
512+
$cseobject = Get-AzVMCustomScriptExtension -ResourceGroupName $rgname -VMName $vmname -Name $csename;
513+
514+
Assert-NotNull $cseobject;
515+
Assert-Match $runname $cseobject.CommandToExecute;
516+
517+
# Parameter set InputObject
518+
$argument = "-NonInteractive";
519+
$cseobject | Set-AzVMCustomScriptExtension -Argument $argument;
520+
$cseobject = Get-AzVMCustomScriptExtension -ResourceGroupName $rgname -VMName $vmname -Name $csename;
521+
522+
Assert-NotNull $cseobject;
523+
Assert-Match $runname $cseobject.CommandToExecute;
524+
Assert-Match $argument $cseobject.CommandToExecute;
525+
526+
# Parameter set ResourceId
527+
Set-AzVMCustomScriptExtension -ResourceId $cseobject.Id -Location $loc `
528+
-FileUri $fileUri -Run $runname;
529+
$cseobject = Get-AzVMCustomScriptExtension -ResourceGroupName $rgname -VMName $vmname -Name $csename;
530+
531+
Assert-NotNull $cseobject;
532+
Assert-Match $runname $cseobject.CommandToExecute;
533+
Assert-NotMatch $argument $cseobject.CommandToExecute;
534+
535+
536+
# Parameter set TopLevelResourceObject
537+
$vmobject | Set-AzVMCustomScriptExtension -Name $csename -Location $loc `
538+
-FileUri $fileUri -Run $runname -Argument $argument;
539+
$cseobject = Get-AzVMCustomScriptExtension -ResourceGroupName $rgname -VMName $vmname -Name $csename;
540+
541+
Assert-NotNull $cseobject;
542+
Assert-Match $runname $cseobject.CommandToExecute;
543+
Assert-Match $argument $cseobject.CommandToExecute;
544+
}
545+
finally
546+
{
547+
# Cleanup
548+
Clean-ResourceGroup $rgname
549+
}
550+
}
551+
486552
<#
487553
.SYNOPSIS
488554
Test Virtual Machine Custom Script Extensions with wrong storage account name

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests/TestVirtualMachineCustomScriptExtensionPiping.json

Lines changed: 4169 additions & 0 deletions
Large diffs are not rendered by default.

src/Compute/Compute/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
## Upcoming Release
2222
* Fix issue with path resolution in Get-AzVmBootDiagnosticsData
2323
* Update Compute client library to 25.0.0.
24+
* Add new parameter sets to Set-AzVMCustomScriptExtension
25+
- Accepts PSVirtualMachine object from pipeline
26+
- Accepts Resource Id and a VirtualMachineCustomScriptExtensionContext also from pipeline
2427

2528
## Version 1.5.0
2629
* Add wildcard support to Get cmdlets

0 commit comments

Comments
 (0)