Get-AzureResource failing - powershell

I am automating the creation of an Azure web site and want to set the pricing tier. I found a few good articles (https://azure.microsoft.com/en-us/documentation/articles/powershell-azure-resource-manager/, http://www.troyhunt.com/2015/01/automating-web-hosting-creation-in.html) that pointed me to Get-AzureResource but I cannot get it to work.
I originally had AuthenticationFailed errors with the Azure 0.8 Powershell module then upgraded to 0.9.3. I now am getting two different errors depending on the parameters I supply to Get-AzureResource. I tried different ApiVersion switches, found that I'm running 2014-04-01-preview which concerns me a bit, and confirmed that my subscription supports AzureResourceManager via Get-AzureSubscriptions. What am I missing?
PS > Switch-AzureMode AzureResourceManager
WARNING: The Switch-AzureMode cmdlet is deprecated and will be removed in a future release.
$DebugPreference="Continue"
PS > Get-AzureResource -OutputObjectFormat New
DEBUG: 3:21:09 PM - GetAzureResourceCmdlet begin processing with ParameterSet 'Lists the resources based on the
specified scope.'.
DEBUG: 3:21:09 PM - using account id '###'...
Get-AzureResource : One or more errors occurred.
At line:1 char:1
+ Get-AzureResource -OutputObjectFormat New
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-AzureResource], AggregateException
+ FullyQualifiedErrorId : System.AggregateException,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementatio
n.GetAzureResourceCmdlet
PS > Get-AzureResource -Name NNNNNNN -ResourceGroupName Default-Web-EastUS -ResourceType Microsoft.Web/sites -ApiVersion 2015-05-01 -OutputObjectFormat New
DEBUG: 3:31:55 PM - GetAzureResourceCmdlet begin processing with ParameterSet 'Lists the resources based on thespecified scope.'.
DEBUG: 3:31:55 PM - using account id '#####'...
Get-AzureResource : {
"Error": {
"Code": "AuthenticationFailed",
"Message": "Authentication failed. The 'Authorization' header is not present or provided in an invalid format.",
"Target": null,
"Details": null
}
}
At line:1 char:1
+ Get-AzureResource -Name NNNNNNN -ResourceGroupName Default-Web-EastUS -Res ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Get-AzureResource], ErrorResponseMessageException
+ FullyQualifiedErrorId : AuthenticationFailed,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.Get
AzureResourceCmdlet

The normal flow for managing Azure resources would be something like:
Switch-AzureMode -Name AzureResourceManager
Add-AzureAccount # windows pops up to enter Microsoft account credentials
Select-AzureSubscription -SubscriptionId '<sub-id>' # switch to the correct subscription
Get-AzureResource -Name <site-name> -ResourceGroupName <rg-name> -ResourceType Microsoft.Web/sites
It's possible that you missed one of these steps.

Related

Creation of an Azure Automation Connection via PowerShell - error 'account was not found'

I am running the following PowerShell code:
Get-AzureRmAutomationAccount `
-ResourceGroupName $AUTOMATION_ACCOUNT_RESOURCE_GROUP `
-Name $AUTOMATION_ACCOUNT_NAME
New-AzureRmAutomationConnection
-ResourceGroupName $AUTOMATION_ACCOUNT_RESOURCE_GROUP `
-AutomationAccountName $AUTOMATION_ACCOUNT_NAME `
-Name $ConnectionAssetName `
-ConnectionTypeName AzureServicePrincipal `
-ConnectionFieldValues $ConnectionFieldValues
The Get-AzureRmAutomationAccount displays details of the automation account, but New-AzureRmAutomationConnection (although using exactly the same parameter values) throws the following error:
New-AzureRmAutomationConnection : The Automation account was not found.
At line:2 char:1
+ New-AzureRmAutomationConnection -ResourceGroupName $AUTOMATION_ACCOUN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureRmAutomationConnection], ArgumentException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Automation.Cmdlet.NewAzureAutomationConnection
Any suggestions what I may be missing are appreciated! :)
The error is misleading, the error you are most likely seeing is related to a bad field. Run the cmdlet with debug to see the value is it failing on. You will have to scroll up a bit to find the exception in the body.
Ensure you have your cert thumbprint, sub id, tenant, and app id. I just tested with the following and it worked as expected. (replaced my values of course). Hope this helps!
New-AzureRmAutomationConnection `
-ResourceGroupName TestAzureAuto `
-AutomationAccountName TestAzureAuto `
-Name "MyAsset2" `
-ConnectionTypeName AzureServicePrincipal `
-ConnectionFieldValues #{"CertificateThumbprint"="0000000000000000000000000000000000000000";"SubscriptionID"="00000000-0000-0000-0000-000000000000";"ApplicationId" = "00000000-0000-0000-0000-000000000000"; "TenantId" = "00000000-0000-0000-0000-000000000000" }

Set-AzureRmVMDiskEncryptionExtension : Long running operation

While trying to encrypt a VM, I am getting the below error:
Set-AzureRmVMDiskEncryptionExtension : Long running operation failed
with status 'Failed'. ErrorCode: VMExtensionProvisioningError
ErrorMessage: VM has reported a failure when processing extension
'AzureDiskEncryptionForLinux'. Error message: "Enable failed.".
StartTime: 11/15/2017 11:12:30 AM EndTime: 11/15/2017 11:14:38 AM
OperationID: 004051ca-bf73-4a37-a145-5e0ac30bc30a Status: Failed At
line:1 char:1
+ Set-AzureRmVMDiskEncryptionExtension -ResourceGroupName $resourceGrou ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzureRmVMDiskEncryptionExtension], ComputeCloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.Extension.AzureDiskEncryption.SetAzureDiskEncryptionExtensionCommand
Please help me to resolve this issue.
I was also having the same issue. The reason was i was not changing the access policy of the key vault.
use this command to change the access policy first and then execute the command for encryption.
Set-AzureRmKeyVaultAccessPolicy -VaultName $KeyVaultName -ResourceGroupName $rgName -EnabledForDiskEncryption
and then check the policy with the following command
(Get-AzureRmKeyVault -VaultName $keyVaultName -ResourceGroupName $rgName).EnabledForDiskEncryption it should return true.

Cannot start Azure VM from PowerShell

I'm trying to start an Azure VM using the following PowerShell script:
$subscriptionId = "00000000-0000-0000-0000-000000000000"
$azureVM = "VS2017"
$resourceGroup = "VS2017ResourceGroup"
Add-AzureRmAccount # here start interactive login
Select-AzureSubscription -SubscriptionId $subscriptionId
Start-AzureRmVM - -ResourceGroupName $resourceGroup -Name $azureVM
When executing the script, I receive the following response:
Start-AzureRmVM : A positional parameter cannot be found that accepts argument '-'.
At C:\Users\ralbano\Desktop\Senza nome7.ps1:11 char:1
+ Start-AzureRmVM - -ResourceGroupName "VS2017ResourceGroup" -Name $azu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Start-AzureRmVM], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Azure.Commands.Compute.StartAzureVMCommand
I am using Windows PowerShell ISE to run the script.
Am I doing something wrong?
I checked the subscription id and the resource group name and are correct (of course in the sample above the subscription id is a fake). The VM is in "Stopped (deallocated)" state on Azure.
Start-AzureRmVM - -ResourceGroupName $resourceGroup -Name $azureVM
According to your error message, we should use this command like this:
Start-AzureRmVM -ResourceGroupName $resourceGroup -Name $azureVM

issue in running diagnostics in azure

I was trying to make a dummy diagnostics worker role using the following article
When i run the following command in step 4 :
(Get-AzureServiceAvailableExtension -ExtensionName 'PaaSDiagnostics' -ProviderNamespace 'Microsoft.Azure.Diagnostics').PublicConfigurationSchema | Out-File -Encoding utf8 -FilePath 'WadConfig.xsd'
I get the following error in azure powershell, we need the subscription in this command but not sure where.
Also, is there a place where I can find how to make a dummy diagnostics worker role.
VERBOSE: 3:32:14 PM - Begin Operation: Get-AzureServiceAvailableExtension
Get-AzureServiceAvailableExtension : No default subscription has been designated. Use Select-AzureSubscription
-Default <subscriptionName> to set the default subscription.
At line:1 char:2
+ (Get-AzureServiceAvailableExtension -ExtensionName 'PaaSDiagnostics' -ProviderNa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Get-AzureServiceAvailableExtension], ApplicationException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.Extensions.GetAzureServiceAvailableExt
ensionCommand
VERBOSE: 3:32:14 PM - Completed Operation: Get-AzureServiceAvailableExtension
Out-File : Access to the path 'C:\WadConfig.xsd' is denied.
At line:1 char:148
+ ... rationSchema | Out-File -Encoding utf8 -FilePath 'WadConfig.xsd'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (:) [Out-File], UnauthorizedAccessException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
First add your credentials using:
add-azureaccount
Next, select desired subscription (if you have more than one) using:
Select-AzureSubscription -SubscriptionId <id>
Finally, try again.

Azure Server Farm Not Found

I am trying to create an azure website via a powershell script. The hosting plan has already been create, I simply wish to add a new website to it.
The script I'm using is this:
Switch-AzureMode AzureResourceManager
$targetServicePlan = Get-AzureResource -Name my-serviceplan -OutputObjectFormat New
New-AzureResource -Name MyTestSite -Location "West Europe" `
-ResourceGroupName Default-Web-WestEurope `
-ResourceType 'Microsoft.Web/sites' `
-PropertyObject #{"name" = "MyTestSite"; "ServerFarmId" = $targetServicePlan.ResourceId } `
-OutputObjectFormat New
The server farm ($targetServicePlan) has a resource id, so I'm assuming that it exists (there is also a hosting plan in the azure portal with this name). Yet when I try to create the website I get the error: "Server farm with name my-serviceplan not found."
The full error is:
New-AzureResource : {"Code":"NotFound","Message":"Server farm with name my-serviceplan not found.","Target":null,"Details":[{"Message":"Server farm with name
my-serviceplan not found."},{"Code":"NotFound"},{"ErrorEntity":{"Code":"NotFound","Message":"Server farm with name my-serviceplan not
found.","ExtendedCode":"11001","MessageTemplate":"Server farm with name {0} not found.","Parameters":["my-serviceplan"],"InnerErrors":null}}],"Innererror":null}
At line:1 char:1
+ New-AzureResource -Name MyTestSite -Location "West Europe" -ResourceGrou ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureResource], ErrorResponseMessageException
+ FullyQualifiedErrorId : NotFound,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceCmdlet
What am I missing?
Is your $targetServicePlan in 'West Europe'? If not that could be the reason for that not-so-helpful error.