select-azurermsubscription -subscriptionname ‘Azure Government Free Trial’
#Create or check for existing resource group
$resourceGroupName = Read-Host ‘Enter name for your RG’
$resourceGroupLocation = “useast”
$resourceGroup = Get-AzureRmResourceGroup -Name $resourceGroupName -ErrorAction SilentlyContinue
if(!$resourceGroup)
{
Write-Host “Resource group ‘$resourceGroupName’ does not exist. To create a new resource group, please enter a location.”;
if(!$resourceGroupLocation) {
$resourceGroupLocation = Read-Host “resourceGroupLocation”;
}
Write-Host “Creating resource group ‘$resourceGroupName’ in location ‘$resourceGroupLocation’”;
New-AzureRmResourceGroup -Name $resourceGroupName -Location $resourceGroupLocation
}
else{
Write-Host “Using existing resource group ‘$resourceGroupName’”;
}
$vnetName = Read-host ‘enter your vnet name’
$subnet1Name = Read-host ‘enter your subnet1 name’
$subnet2Name = Read-host ‘enter your subnet2 name’
your are making the variable literal, so it’s not resolving the variable, you’re passing $resourceGroupName as the name. You do need to wrap the variable in any type of qoutes, but using double qoutes would tell Powershell to resolve the variable:
Elvir, since you are writing the scripts using AzureRM PowerShell module, it is better to write the scripts using Az module. Microsoft has released a new Azure module called Az which will be a replacement for the AzureRM module and works not only with Windows but also with Linux and MacOS. In windows, it works with PowerShell 5.x and 6.x as well, and Microsoft will not release any updates for AzureRM module except bug fixes, all future releases come only with Az module itself. For more details please visit the link below…
Thanks Kiran, I’m aware of PS Core but I was just trying to get this working and then I will work on transition my scripts to PS Core (I know its double work ).
I’m keep getting same error (I thought that the issue is with my ARM template but ARM templates works if I deploy it from Azure Portal).
This the error I’m getting:
New-AzureRmResourceGroupDeployment : 7:01:38 PM - Error: Code=InvalidTemplate; Message=Deployment template validation failed: ‘The provided value for the template parameter ‘storageAccountName’ at line ‘7’ and column ‘31’
is not valid.’.
At line:60 char:1