Thank you for reaching out.
I tried the script on my end and ran into same issue, I think it will help if you could report this issue on the Azure PowerShell Repository here
Meanwhile you can follow the script below as a workaround, where I have invoked Subnets - Get REST API to fetch the subnet provisioning state after the subnet is deployed.
Connect-AzAccount
$SubId = "SubID"
Set-AzContext -Subscription $SubId
$vnetName="vnetName"
$resourceGroupName="resourceGroupName"
$subnetName = "subnetName"
$url = "https://management.azure.com/subscriptions/"+$SubId+"/resourceGroups/"+$resourceGroupName+"/providers/Microsoft.Network/virtualNetworks/"+$vnetName+"/subnets/"+$subnetName+"?api-version=2022-11-01"
$token = (Get-AzAccessToken).token
$headers = @{'Authorization' = "Bearer $token"}
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $resourceGroupName
$subnet = @{
Name = $subnetName
VirtualNetwork = $vnet
AddressPrefix = '10.0.47.32/28'
}
$subnetConfig = Add-AzVirtualNetworkSubnetConfig @subnet
$vnet | Set-AzVirtualNetwork | Out-Null
$result = Invoke-WebRequest -Method GET -Uri $url -Headers $headers -UseBasicParsing
$body = $result.Content | ConvertFrom-Json
$ProvState = $body.properties.provisioningState
If ($ProvState -eq "Succeeded")
{
Write-Output "Provisioning successfull"
}
else
{
While ($ProvState -ne "Succeeded")
{
Start-Sleep -Seconds 10
$result = Invoke-WebRequest -Method GET -Uri $url -Headers $headers -UseBasicParsing
$body = $result.Content | ConvertFrom-Json
$ProvState = $body.properties.provisioningState
}
}
Hope this helps! Please let me know if you have any questions. Thank you!
Please "Accept the answer" if the information helped you. This will help us and others in the community as well.