I got the same issue today and tried with command lines, then it worked
param (
[string]$ResourceGroup = "YourResourceGroupName",
[string]$VmName = "YourVmName",
[string]$VnetName = "YourVnetName",
[string]$SubnetName = "YourSubnetName",
[string]$Location = "southeastasia",
[string]$AdminUsername = "YourAdminUsername",
[string]$AdminPassword = "YourPassword123!",
[string]$AddressPrefix = "10.0.0.0/16",
[string]$SubnetPrefix = "10.0.0.0/24",
[string]$PublisherName = "MicrosoftWindowsDesktop",
[string]$Offer = "windows-11",
[string]$Skus = "win11-24h2-pro",
[string]$Version = "latest",
[string]$VmSize = "Standard_B2s"
)
# Create a virtual network
New-AzVirtualNetwork -ResourceGroupName $ResourceGroup -Location $Location -Name $VnetName -AddressPrefix $AddressPrefix -Subnet @{"Name" = $SubnetName; "AddressPrefix" = $SubnetPrefix}
# Create a public IP address with Static allocation and DNS name
$PublicIp = New-AzPublicIpAddress -ResourceGroupName $ResourceGroup -Location $Location -Name "${VmName}PublicIP" -AllocationMethod Static -Sku Standard -DnsName $VmName
# Create a network security group
$Nsg = New-AzNetworkSecurityGroup -ResourceGroupName $ResourceGroup -Location $Location -Name "${VmName}NSG"
# Create a network security group rule to allow RDP
$NsgRule = New-AzNetworkSecurityRuleConfig -Name "AllowRDP" -Protocol "Tcp" -Direction "Inbound" -Priority 1000 -SourceAddressPrefix "*" -SourcePortRange "*" -DestinationAddressPrefix "*" -DestinationPortRange 3389 -Access "Allow"
$Nsg.SecurityRules.Add($NsgRule)
$Nsg | Set-AzNetworkSecurityGroup
# Create a virtual network interface and associate with public IP address and NSG
$Nic = New-AzNetworkInterface -ResourceGroupName $ResourceGroup -Location $Location -Name "${VmName}NIC" -SubnetId (Get-AzVirtualNetwork -ResourceGroupName $ResourceGroup -Name $VnetName).Subnets[0].Id -PublicIpAddressId $PublicIp.Id -NetworkSecurityGroupId $Nsg.Id
# Create a virtual machine without boot diagnostics
$VmConfig = New-AzVMConfig -VMName $VmName -VMSize $VmSize | `
Set-AzVMOperatingSystem -Windows -ComputerName $VmName -Credential (New-Object PSCredential -ArgumentList $AdminUsername, (ConvertTo-SecureString -String $AdminPassword -AsPlainText -Force)) | `
Set-AzVMSourceImage -PublisherName $PublisherName -Offer $Offer -Skus $Skus -Version $Version | `
Add-AzVMNetworkInterface -Id $Nic.Id | `
Set-AzVMOSDisk -CreateOption FromImage -ManagedDiskId $null -StorageAccountType "Standard_LRS" | `
Set-AzVMBootDiagnostics -Disable
New-AzVM -ResourceGroupName $ResourceGroup -Location $Location -VM $VmConfig
# Open port 3389 to allow RDP traffic
Get-AzNetworkSecurityGroup -ResourceGroupName $ResourceGroup -Name "${VmName}NSG" | Add-AzNetworkSecurityRuleConfig -Name "AllowRDP" -Protocol "Tcp" -Direction "Inbound" -Priority 1000 -SourceAddressPrefix "*" -SourcePortRange "*" -DestinationAddressPrefix "*" -DestinationPortRange 3389 -Access "Allow" | Set-AzNetworkSecurityGroup