Prisoner ZERO
Prisoner ZERO

Reputation: 14176

Create Azure Objects Using 'Publish Settings' File

So, I'm told if you import your Azure Subscription Publish Setting file into PowerShell...you can use the certificate in the Publish Setting file to create objects in your Azure Subscription.

However, I am getting the following exception trying to create a Resource Group:

New-AzureRmResourceGroup : Run Connect-AzureRmAccount to login. + CategoryInfo : CloseError: (:) [New-AzureRmResourceGroup], PSInvalidOperationException + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupCmdlet

I Do The Following In My Script:

...the subscription is both "Default & Current" (see attached image).
...and yet I still get that message.

SAMPLE CODE:
This code is edited so as not to "give away the farm"...

#Set Subscription
$Subscription_Id = "<not shown>"

Select-AzureSubscription -SubscriptionId  $Subscription_Id
Get-AzureSubscription

# CHECK EXISTS: ResourceGroup
$RegionFullName = "South Central US"

$RegionShortName = "scus"
$EnvironmentShortName = "dev"
$ApplicationShortName = "<not shown>"
$ObjectTypeShortName = "rg"

$ResourceGroupFullName = "$($RegionShortName)-$($EnvironmentShortName)-$($ApplicationShortName)-$($ObjectTypeShortName)"

$ResourceGroup = Get-AzureRmResourceGroup -Name $ResourceGroupFullName -ErrorVariable NotPresent -ErrorAction SilentlyContinue

if ($ResourceGroup -eq $Null) {

    #CREATE: ResourceGroup
    $ResourceGroup = New-AzureRmResourceGroup -Name $ResourceGroupFullName -Location $RegionFullName -Confirm
}

Exception Message

Upvotes: 0

Views: 169

Answers (1)

Joy Wang
Joy Wang

Reputation: 42163

I suppose you are using Import-PublishSettingsFile, but Azure Management Certificates and Publishing Setting files are only intended (for) and (are) limited to managing Azure Service Management (ASM) resources, which are being retired.

In your script, you mixed the ASM and AzureRm powershell modules together. Select-AzureSubscription and Get-AzureSubscription belong to ASM, Get-AzureRmResourceGroup and New-AzureRmResourceGroup belong to AzureRm.

So if you need to use AzureRm command, you need to run Connect-AzureRmAccount to login your account.

Upvotes: 1

Related Questions