Linux : script to create VMSS from SIG Image I am getting a failure which indicates WindowsAttestation is being installed on Linux VM I am passing Image Ref of Linux Sig Image. Also OSType as Linux. It is working fine when I pass Windows SIG Image reference and OSType as Windows.

I don't understand what's the issue with Linux.

$imageref = ""
$resourceGroupName = "myrg"
$location = region
$vnetName = "my-vnet"
$vmssNetwork = "my-net"
$computerName = "myvm"
$securityType = "TrustedLaunch"
$ipName = "my-ip"
$VMSSName = "my vmss"
$SkuName = "Standard_D2s_v3"
$osType = "Linux"
$adminUser = "AdminUsername"
$adminPass = "Adminpassword"

# create resource group
New-AzResourceGroup -ResourceGroupName $resourceGroupName -Location $location

# vnet 
$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name "frontendSubnet" -AddressPrefix "10.0.1.0/24"
$backendSubnet  = New-AzVirtualNetworkSubnetConfig -Name "backendSubnet"  -AddressPrefix "10.0.2.0/24"
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $resourceGroupName -Location $location -AddressPrefix "10.0.0.0/16" -Subnet $frontendSubnet,$backendSubnet
$vnet = Get-AzureRmVirtualNetwork -ResourceGroupName $resourceGroupName -Name $vnetName

#ipconfig
$ipConfig = New-AzureRmVmssIpConfig -Name $ipName -LoadBalancerBackendAddressPoolsId $null -SubnetId $vnet.Subnets[0].Id

# vmss configuration
$vmss = New-AzureRmVmssConfig -Location $location -SkuCapacity 2 -SkuName $SkuName -UpgradePolicyMode "Automatic" -ErrorAction Stop
$vmss1 = Set-AzVmssSecurityProfile -VirtualMachineScaleSet $vmss -SecurityType $securityType;

# network interface config
Add-AzureRmVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmss1 -Name $vmssNetwork -Primary $true -IPConfiguration $ipConfig 

# set the stroage profile 
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss1 -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId $imageref -OsDiskOsType $osType

# os profile
Set-AzureRmVmssOSProfile -ComputerNamePrefix $computerName -AdminUsername $adminUser -AdminPassword $adminPass -VirtualMachineScaleSet $vmss1

#create the vmss
New-AzVMss -ResourceGroupName $resourceGroupName -Name $VMSSName -VirtualMachineScaleSet $vmss1
1

There are 1 best solutions below

0
On

I tried to create VMSS from SIG Image by passing the Image Ref of Linux Sig Image. Also, OSType is Linux. It is working fine.

You seem to be trying to create a Virtual Machine Scale Set (VMSS) using PowerShell and Azure PowerShell cmdlets. However, there appears to be a mix of AzureRM (Azure Resource Manager) and Az (Az module) cmdlets in your script, which could be causing compatibility issues.

However, I tried the same code and faced the errors again. So I changed the approach for commands as shown below

my PowerShell script

$resourceid = ""
$storageType = "Premium_LRS"
$location = "East US"
$azureVnetName = "Demosubnet"
$azureVnetSubnetName = "samplesubnet"

$galleryImageReference = @{Id = ''}
$diskConfig = New-AzDiskConfig -Location 'East US' -CreateOption 'FromImage' -GalleryImageReference $galleryImageReference

New-AzDisk -ResourceGroupName 'demorg-vk' -DiskName 'Disk01' -Disk $diskConfig 


$diskConfig = New-AzDiskConfig -Location $location -CreateOption Upload -SourceResourceId $galleryImageReference.Id -OsType Linux

$osDisk = Get-AzDisk -ResourceGroupName 'demorg-vk' -DiskName 'Disk01' 

# Step 2: Create Network Interface and Virtual Network

$azureVnetSubnet = (Get-AzVirtualNetwork -Name 'demovmvk-vnet' -ResourceGroupName 'demorg-vk' ).Subnets | Where-Object {$_.Name -eq $azureVnetSubnetName}

$azureNIC = New-AzNetworkInterface -Name 'venkat1' -ResourceGroupName 'demorg-vk' -Location 'East US' -SubnetId  $vnet.Subnets[0].Id -Force

# Step 3: Set VM Credentials
$VMLocalAdminUser = ""
$VMLocalAdminSecurePassword = ConvertTo-SecureString "" -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($VMLocalAdminUser, $VMLocalAdminSecurePassword)
$VMName ="venkat"   # Updated the VM name to match the disk name
$azureVmOsDiskName = ""
$azureVmSize = "Standard B1s"

$VirtualMachine = New-AzVMConfig -VMName $VMName -VMSize $azureVmSize -SecurityType TrustedLaunch
$VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $azureNIC.Id

$VirtualMachine = Set-AzVMOSDisk -VM $VirtualMachine -ManagedDiskId $osDisk.Id -StorageAccountType 'Premium_LRS' -Name $VMName -CreateOption Attach -Linux -DeleteOption Delete -Verbose

$vmssName1 = New-AzVmss -ResourceGroupName  'demorg-vk' -VMScaleSetName 'myScaleSet' -OrchestrationMode 'Flexible' -Location  'East US' -Credential $Credential

VM image

enter image description here

Output

enter image description here

enter image description here

enter image description here