#connect-Azaccount
$rgname = "Azure-PS-Lab-RG"
$location = "westeurope"
New-AzResourceGroup -name $rgname -Location $location
$subnet1config = New-AzVirtualNetworkSubnetConfig -name "Mechanical-SN" -AddressPrefix "10.3.1.0/24"
$subnet2config = New-AzVirtualNetworkSubnetConfig -name "Electrical-SN" -AddressPrefix "10.3.2.0/24"
$subnet3config = New-AzVirtualNetworkSubnetConfig -name "ComputerSc-SN" -AddressPrefix "20.3.1.0/24"
$subnet4config = New-AzVirtualNetworkSubnetConfig -name "InfoTech-SN" -AddressPrefix "20.3.2.0/24"
$vnet1 = New-AzVirtualNetwork -ResourceGroupName $rgname -name "FirstYear-VN" -AddressPrefix "10.3.0.0/16" -Location $location -Subnet $subnet1config,$subnet2config
$vnet2 = New-AzVirtualNetwork -ResourceGroupName $rgname -name "SecondYear-VN" -AddressPrefix "20.3.0.0/16" -Location $location -Subnet $subnet3config,$subnet4config
$server1pip = New-AzPublicIpAddress -ResourceGroupName $rgname -name "server-1" -AllocationMethod Dynamic -Location $location
$server2pip = New-AzPublicIpAddress -ResourceGroupName $rgname -name "server-2" -AllocationMethod Dynamic -Location $location
$server3pip = New-AzPublicIpAddress -ResourceGroupName $rgname -name "server-3" -AllocationMethod Dynamic -Location $location
$server4pip = New-AzPublicIpAddress -ResourceGroupName $rgname -name "server-4" -AllocationMethod Dynamic -Location $location
$server1nic = New-AzNetworkInterface -ResourceGroupName $rgname -name "server1-nic" -Location $location -Subnet $vnet1.Subnets[0] -PublicIpAddress $server1pip -PrivateIpAddress "10.3.1.5"
$server2nic = New-AzNetworkInterface -ResourceGroupName $rgname -name "server2-nic" -Location $location -Subnet $vnet1.Subnets[1] -PublicIpAddress $server2pip -PrivateIpAddress "10.3.2.5"
$server3nic = New-AzNetworkInterface -ResourceGroupName $rgname -name "server3-nic" -Location $location -Subnet $vnet2.Subnets[0] -PublicIpAddress $server3pip -PrivateIpAddress "20.3.1.5"
$server4nic = New-AzNetworkInterface -ResourceGroupName $rgname -name "server4-nic" -Location $location -Subnet $vnet2.Subnets[1] -PublicIpAddress $server4pip -PrivateIpAddress "20.3.2.5"
$servercred = Get-credential -Message "Enter your credentials for Azure VM"
$server1vmconfig = New-AzVMConfig -VMName "Server1-VM" -VMSize "Standard_B2ms" | Set-AzVMOperatingSystem -Windows -ComputerName "Server1-VM" -Credential $servercred | Set-AzVMSourceImage -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Skus "2016-Datacentre" -Version latest | Set-AzVMBootDiagnostic -Disable | Add-AzVMNetworkInterface -Id $server1nic.Id
$server2vmconfig = New-AzVMConfig -VMName "Server2-VM" -VMSize "Standard_B2ms" | Set-AzVMOperatingSystem -Windows -ComputerName "Server2-VM" -Credential $servercred | Set-AzVMSourceImage -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Skus "2016-Datacentre" -Version latest | Set-AzVMBootDiagnostic -Disable | Add-AzVMNetworkInterface -Id $server2nic.Id
$server3vmconfig = New-AzVMConfig -VMName "Server3-VM" -VMSize "Standard_B2ms" | Set-AzVMOperatingSystem -Windows -ComputerName "Server3-VM" -Credential $servercred | Set-AzVMSourceImage -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Skus "2016-Datacentre" -Version latest | Set-AzVMBootDiagnostic -Disable | Add-AzVMNetworkInterface -Id $server3nic.Id
$server4vmconfig = New-AzVMConfig -VMName "Server4-VM" -VMSize "Standard_B2ms" | Set-AzVMOperatingSystem -Windows -ComputerName "Server4-VM" -Credential $servercred | Set-AzVMSourceImage -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Skus "2016-Datacentre" -Version latest | Set-AzVMBootDiagnostic -Disable | Add-AzVMNetworkInterface -Id $server4nic.Id
$server1vm = New-AzVM -ResourceGroupName $rgname -Location $location -VM $server1vmconfig
$server2vm = New-AzVM -ResourceGroupName $rgname -Location $location -VM $server2vmconfig
$server3vm = New-AzVM -ResourceGroupName $rgname -Location $location -VM $server3vmconfig
$server4vm = New-AzVM -ResourceGroupName $rgname -Location $location -VM $server4vmconfig
this is my azure powershell script however when i tried to run it, i got this error.
New-AzVM : The platform image 'MicrosoftWindowsServer:WindowsServer:2016-Datacentre:latest' is not available. Verify that all fields in the storage profile are correct. For more details about storage profile information, please refer to https://aka.ms/storageprofile ErrorCode: PlatformImageNotFound ErrorMessage: The platform image 'MicrosoftWindowsServer:WindowsServer:2016-Datacentre:latest' is not available. Verify that all fields in the storage profile are correct. For more details about storage profile information, please refer to https://aka.ms/storageprofile ErrorTarget: imageReference StatusCode: 404 ReasonPhrase: Not Found OperationID : fa9fda15-a6a5-4dfd-8628-e4016dc1fc85 At line:9 char:14
- ... server4vm = New-AzVM -ResourceGroupName $rgname -Location $location - ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : CloseError: (:) [New-AzVM], ComputeCloudException
- FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.NewAzureVMCommand
How can I rectify this error?