Set-AzureVMSourceImage
Specifies the platform image for a virtual machine.
Parameter Set: ImageReferenceParameterSet
Set-AzureVMSourceImage [-VM] <Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine> [-PublisherName] <System.String> [-Offer] <System.String> [-Skus] <System.String> [-Version] <System.String> [-Profile <Microsoft.Azure.Common.Authentication.Models.AzureProfile> ] [ <CommonParameters>]
Parameter Set: SourceImageParameterSet
Set-AzureVMSourceImage [-VM] <Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine> [-Name] <System.String> [-Profile <Microsoft.Azure.Common.Authentication.Models.AzureProfile> ] [ <CommonParameters>]
The Set-AzureVMSourceImage cmdlet specifies the platform image to use for a virtual machine.
Specifies the name of a source image.
Aliases |
SourceImageName,ImageName |
Required? |
true |
Position? |
2 |
Default Value |
none |
Accept Pipeline Input? |
true(ByPropertyName) |
Accept Wildcard Characters? |
false |
Specifies the type of VMImage offer. To obtain an image offer, use the Get-AzureVMImageOffer cmdlet.
Aliases |
none |
Required? |
true |
Position? |
3 |
Default Value |
none |
Accept Pipeline Input? |
true(ByPropertyName) |
Accept Wildcard Characters? |
false |
Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile.
Aliases |
none |
Required? |
false |
Position? |
named |
Default Value |
none |
Accept Pipeline Input? |
false |
Accept Wildcard Characters? |
false |
Specifies the name of a publisher of a VMImage. To obtain a publisher, use the Get-AzureVMImagePublisher cmdlet.
Aliases |
none |
Required? |
true |
Position? |
2 |
Default Value |
none |
Accept Pipeline Input? |
true(ByPropertyName) |
Accept Wildcard Characters? |
false |
Specfies a VMImage SKU. To obtain SKUs, use the Get-AzureVMImageSku cmdlet.
Aliases |
none |
Required? |
true |
Position? |
4 |
Default Value |
none |
Accept Pipeline Input? |
true(ByPropertyName) |
Accept Wildcard Characters? |
false |
Specifies a version of a VMImage. To use the latest version, specify a value of latest instead of a particular version.
Aliases |
none |
Required? |
true |
Position? |
5 |
Default Value |
none |
Accept Pipeline Input? |
true(ByPropertyName) |
Accept Wildcard Characters? |
false |
Specifies the local virtual machine object to configure.
Aliases |
VMProfile |
Required? |
true |
Position? |
1 |
Default Value |
none |
Accept Pipeline Input? |
true(ByValue,ByPropertyName) |
Accept Wildcard Characters? |
false |
This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see about_CommonParameters (https://go.microsoft.com/fwlink/p/?LinkID=113216).
The input type is the type of the objects that you can pipe to the cmdlet.
The output type is the type of the objects that the cmdlet emits.
The first command gets the availability set named AvailablitySet03 in the resource group named ResourceGroup11, and then stores that object in the $AvailabilitySet variable.
The second command creates a virtual machine object, and then stores it in the $VirtualMachine variable. The command assigns a name and size to the virtual machine. The virtual machine belongs to the availability set stored in $AvailabilitySet.
The final command sets values for publisher name, offer, SKU, and version. The Get-AzureVMImagePublisher, Get-AzureVMImageOffer, Get-AzureVMImageSku, and Get-AzureVMImage cmdlets can discover these settings.
AvailabilitySet = Get-AzureAvailabilitySet -ResourceGroupName "ResourceGroup11" -Name "AvailabilitySet03"
PS C:\> $VirtualMachine = New-AzureVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1" -AvailabilitySetID $AvailabilitySet.Id
PS C:\> Set-AzureVMSourceImage -VM $VirtualMachine -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Skus "2012-R2-Datacenter" -Version "latest"
This example sets source image settings by using the image reference method.
$Publisher = (Get-AzureVMImagePublisher -Location "Central US") | select -ExpandProperty PublisherName | where { $_ -like '*Microsoft*Windows*Server' }
PS C:\> $Offer = (Get-AzureVMImageOffer -Location "Central US" -PublisherName $Publisher[0]) | select -ExpandProperty Offer | where { $_ -like '*Windows*' }
PS C:\> $Sku = (Get-AzureVMImageSku -Location "Central US" -PublisherName $Publisher[0] -Offer $Offer[0]) | select -ExpandProperty Skus
PS C:\> $Versions = (Get-AzureVMImage -Location "Central US" -Offer -Offer $Offer[0] -PublisherName $Publisher[0] -Skus $Sku[0]) | select -ExpandProperty Version
PS C:\> $VMImage = Get-AzureVMImageDetail -Location "Central US" -Offer -Offer $Offer[0] -PublisherName $Publisher[0] -Skus $Sku[0] -Version $Versions[0]
PS C:\> $VirtualMachine07 = Set-AzureVMSourceImage -VM $VirtualMachine07 -ImageReference $VMImage