Azure PowerShell Add-AlertRule Returns Bad Request when using CpuPercentage on Resource Group - powershell

I get an Azure Resource Group and try to add a Metric Alert rule of type CPUPercentage, but it fails with BadRequest.
> $r = Get-AzureRmResourcegroup
WARNING: The output object of this cmdlet will be modified in a future release.
> $a = $r[0]
> Add-AlertRule -Location "West US" -MetricName CpuPercentage -Name CPU98Percent -Operator GreaterThanOrEqual -ResourceGroup $a.ResourceGroupName -ResourceId $a.ResourceId -RuleType Metric -Threshold 98
Add-AlertRule : BadRequest:
At line:1 char:1
+ add-alertrule -Location "West US" -metricName CpuPercentage -Name CPU ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-AlertRule], CloudException
+ FullyQualifiedErrorId : Hyak.Common.CloudException,Microsoft.Azure.Commands.Insights.Alerts.AddAlertRuleCommand
It works fine from the portal. There isn't already an alert with the same name either.
I'm using version 1 of the Azure module and version 1.0.2 of AzureRM.

I was receiving the same error when the alert name was not unique across all databases on the Sql Server. That is, I had multiple databases on the same server and was trying to create a rule named "DTU Percentage", which would fail after the first one was created. Once a unique name ("DTU Percentage DB_NAME") was used, the alerts were created.
Unfortunately, it sounds like you are experiencing another issue. Just thought I would add this answer for anyone searching for similar errors.

Related

Deciphering error after runnning New-AzureRmDataLakeAnalyticsCatalogCredential

I am working on reading Azure SQL data from a U-SQL script into Data Lake. I am working on creating an external data source in U-SQL. A part of this effort involves the creation of a “credential” using PowerShell. I am following this guidance:
https://learn.microsoft.com/en-us/powershell/module/azurerm.datalakeanalytics/new-azurermdatalakeanalyticscatalogcredential
But, am stuck on an error, shown below. This part of it has me especially stumped: "The resource '' does not exist.". Due to this part of the command : "-Credential (Get-Credential)", I get prompted for login name and password. After that, I get presented with the error.
Please help me decipher this situation.
Thank you!
Eric
C:\WINDOWS\system32> New-AzureRmDataLakeAnalyticsCatalogCredential -AccountName "" `
-DatabaseName "<MYDBNAME>" `
-CredentialName "<MYCREDENTIALNAME>" `
-Credential (Get-Credential) `
-Uri "http://<MYSERVERNAME>.database.windows.net:1433"
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
WARNING: The output type defined for this cmdlet is incorrect and will be updated to reflect what is actually returned
(and defined in the help) in a future release.
New-AzureRmDataLakeAnalyticsCatalogCredential : The resource '' does not exist. Trace:
c3e04b2a-2690-4c5e-b61c-58a5ded93c6b Time: 2017-05-10T09:09:07.8971058-07:00
At line:1 char:1
+ New-AzureRmDataLakeAnalyticsCatalogCredential -AccountName "bladlalog ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureRmData...talogCredential], CloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.DataLakeAnalytics.NewAzureDataLakeAnalyticsCatalogCredential
Solved by using a new ADL database name, that I created, and not the source Azure SQL database. I got the "az dla catalog credential create" to run cleanly. .... The online documentation I initially found was not clear for indicating the expected database name was an ADL database, and not the source Azure SQL database.

Azure swap not working

I am trying to use Switch-AzureWebsiteSlot as it follows:
Switch-AzureWebsiteSlot -Name 'sitename' -slot1 'Staging' -slot2 'Production' -f
orce -verbose
However even though my website has 2 slots, Staging and the default Production I still receive the following error from Power Shell.
Switch-AzureWebsiteSlot : The website must have at least two slots to apply swap
At line:1 char:1
+ Switch-AzureWebsiteSlot -Name 'sitename' -slot1 'St ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Switch-AzureWebsiteSlot], PSInvalidOperationException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Websites.SwitchAzureWebsiteSlotCommand
Do you have any ideas why? Did you also encounter this during your code journeys?
Switch-AzureWebsiteSlot is for ASM websites. In your case, I think you have created an ARM website, hence Switch-AzureWebsiteSlot is not suitable here.
To swap slot for ARM websites, you need to use below script:
$ParametersObject = #{targetSlot = "[slot name – e.g. “production”]"}
Invoke-AzureRmResourceAction -ResourceGroupName [resource group name]-ResourceType Microsoft.Web/sites/slots -ResourceName [web app name]/[slot name] -Action slotsswap -Parameters $ParametersObject -ApiVersion 2015-07-01
You can check this article for details.
Update:
Switch-AzureWebsiteSlot also works for ARM web app. My problem is that I have two subscriptions, I didn't select the correct subscription when testing the command previously. Thanks to Flemin!
Before:
Now with the right subscription:
This command works even if you have created app in ARM.
Switch-AzureWebsiteSlot -Name 'siteName' -slot1 'StagingDeploymentName' -slot2 'Production' -force -verbose
Please check the names that you have given and if the slots are up and running.
I tested this by stopping one of the deployment slots and go the same error as you got. So, I'm sure now that in your case either one slot is not in running state.
For an ARM web app, Switch-AzureWebsiteSlot does not work for me at all. Get the following error message:
Switch-AzureWebsiteSlot : No default subscription has been designated.
Use Select-AzureSubscription -Default to set the
default subscription.
From what I understand, Select-AzureSubscription is an ASM command so it's not applicable. (Instead, for ARM I need to use Select-AzureRmSubscription.)
The command Swap-AzureRmWebAppSlot is what worked for me:
Swap-AzureRmWebAppSlot -Name "sitename" -SourceSlotName "Staging" -DestinationSlotName "Production" -ResourceGroupName "<Your Resource Group Name"

Exception exporting Azure ResourceGroup template

I'm trying to export an Azure ResourceGroup to a template-file using the following cmdlet (Windows 10 x64, module-version 2.0) but it throws an exception PS> Export-AzureRmResourceGroup -ResourceGroupName 'service-env-rg' -Path .\resourcegroup.json -ErrorAction SilentlyContinue Export-AzureRmResourceGroup : InternalServerError : Encountered internal server error. Diagnostic information: timestamp '20160809T072241Z', subscription id 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', tracking id 'eed95646-d845-4852-8971-a353bab65db2', request correlation id 'eed95646-d845-4852-8971-a353bab65db2'. At line:1 char:1 + Export-AzureRmResourceGroup -ResourceGroupName 'service-e ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Export-AzureRmResourceGroup], ErrorResponseMessageException + FullyQualifiedErrorId : InternalServerError,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ExportAzureResourceGroupCmdlet
If I run it without -ErrorAction I get a secondary exception as well with the pipeline being stopped. Anyone else seen this ? I got the same error with the previous version of the cmdlet.
I wonder if this is related to the fact that it appears the 'template export' functionality in the Azure portal is not really working properly either ... see this very recent forum thread:
https://social.msdn.microsoft.com/Forums/en-US/3200b7a1-768c-4714-a474-ac02df22e729/problem-with-exporting-current-state-arm-template-for-a-resource-group?forum=windowsazuremanagement
After renaming my Microsoft-account it now works - both in Powershell and in the portal. Ie, it seems that an ARM update has introduced an authentication-change so that a login doesn't properly differentiate between accounts even though I select the type.

Reserving static IP for existing Azure Virtual Machine

I have created 3 virtual machines which are already in operation and I forgot to first assign a static IP at time of creation. I am now encountering some issues when I am trying to do this.
I have created a reserved IP using the following powershell:
New-AzureReservedIP “dmz-live” –Label “be-dmz-ip” –Location “North Europe”
Following this post http://prmdbaora.blogspot.in/2015/06/normal-0-false-false-false-en-us-x-none.html I tried to delete the VM and reassign but when I use the following code:
New-AzureVMConfig -Name "be-dmz" -InstanceSize "Standard_D11" –ImageName "be-dmz-be-dmz-0-201508100952090393" | New-AzureVM -ServiceName "be-dmz" –ReservedIPName " be-dmz-ip " -Location "CloudVNET”
I am getting an error:
New-AzureVMConfig : Must specify MediaLocation or set a current storage account using Set-AzureSubscription.
At line:1 char:1
+ New-AzureVMConfig -Name "be-dmz" -InstanceSize "Standard_D11" -ImageName "be-dmz ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureVMConfig], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.NewAzure
VMConfigCommand
I have confirmed that the name of the disk is correct, after deleting the cloud service this disk was present but when I tried to run the command it deleted the disk and it is no longer showing in the list of disks
I want to add these machines to a virtual network called "CloudVNET". Can anyone give me a pointer as to what I am doing wrong here please and how I can go about assigned these reserved IPs to the machines

How to launch an EC2 instance into a VPC with a public IP address in PowerShell?

I have been trying to use the following script, but haven't been successful:
$Ami=Get-EC2ImageByName WINDOWS_2012_BASE
New-EC2Instance -ImageId $Ami[0].ImageId -MinCount 1 -MaxCount 1 -KeyName uckey -InstanceType `
t1.micro -SubnetId subnet-56738b33 -AssociatePublicIp $true
The error is:
New-EC2Instance : Object reference not set to an instance of an object.
At line:1 char:1
+ New-EC2Instance -ImageId $Ami[0].ImageId -MinCount 1 -MaxCount 1 -KeyName uckey ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Amazon.PowerShe...2InstanceCmdlet:NewEC2InstanceCmdlet)
[New-EC2Instance], InvalidOperationException
+ FullyQualifiedErrorId : System.NullReferenceException,Amazon.PowerShell.Cmdlets.EC2.NewEC2InstanceC
mdlet
The problem is about the parameter -AssociatePublicIp without it, the script works.
Thanks for reading
As of AWS PowerShell version 2.1.3.0, this bug has been corrected.
I was able to execute this script:
New-EC2Instance -ImageId $Ami[0].ImageId -MinCount 1 -MaxCount 1 -KeyName uckey -InstanceType `
t1.micro -SubnetId subnet-56738b33 -AssociatePublicIp $true
I ran into the same problem, and a possible workaround while still using PowerShell is to create the network interface first, and then associating it with the instance:
$subnetId = "subnet-56738b33"
$keyName = "uckey"
$instanceType = "t1.micro"
$Ami = Get-EC2ImageByName WINDOWS_2012_BASE
$ImageId = $Ami[0].ImageId
$networkInterface = New-EC2NetworkInterface -SubnetId $subnetId -Description "Primary network interface"
$interfaceSpec = New-Object Amazon.EC2.Model.InstanceNetworkInterfaceSpecification -property #{"NetworkInterfaceId"=$networkInterface.NetworkInterfaceId}
$reservation = New-EC2Instance -ImageId $ImageId -MinCount 1 -MaxCount 1 -InstanceType $instanceType -KeyName $keyName -NetworkInterfaces $interfaceSpec
The InstanceNetworkInterfaceSpecification has a property to indicate if the interface needs a public IP address (see the docs)
I suspect this to be a bug in the AWS Tools for Windows PowerShell. As already commented, running the semantically identical command with the AWS Command Line Interface instead yields the desired result:
$ aws ec2 run-instances --image-id $ami.Imageid --count 1:1 --instance-type t1.micro `
--key-name uckey --subnet-id subnet-56738b33 --associate-public-ip-address
Beware of the slight syntax difference for --count and --associate-public-ip-address, the latter doesn't require a value, rather comprises the flag in itself, i.e. [--associate-public-ip-address | --no-associate-public-ip-address], see run-instances.
This is also confirmed by an (unfortunately unanswered) inquiry in the AWS Forum for PowerShell scripting, see Unable to get New-EC2Instance to honour -AssociatePublicIP.
Accordingly, your best bet to get this resolved might be to bump that thread and hope for a response from the AWS team. Meanwhile you can work around the issue by means of scripting the operation via the AWS CLI instead.