I'm trying to use Get-AzAdvisorRecommendation command for automatic sending of emails to users, that appear in Advisor's alerts. Issue being, that Get-AzAdvisorRecommendation command does not show the actual description of the recommendation, like "Right-size or shutdown underutilized virtual machines" in the output. It only gives vague information like "ShortDescription: Microsoft.Azure.Commands.Advisor.Cmdlets.Models.PsRecommendationBaseShortDescription" and RecommendationTypeID.
Azure CLI "az advisor recommendation list" command does provide the information under "shortDescription" value. Is there any way to get the same information using Get-AzAdvisorRecommendation command?
Indeed. ShortDescription is returned in the response as a nested property. You can access it as follows:
Get-AzAdvisorRecommendation | Select-Object RecommendationTypeId, #{Name="ShortDescription"; Expression={$_.ShortDescription.Problem}}
Include (select) other properties as needed.
Related
I am new to Azure. I am trying to get the policies assigned to a subscription(1e1707b7-XXXX-XXXX-XXXX-71feab4b911d) using powershell below. I am not getting the correct count of policies applied to that subscription.
Get-AzPolicyAssignment -Scope "/subscriptions/1e1707b7-XXXX-XXXX-XXXX-71feab4b911d"
I think there is some problem with the scope. Can someone help me with this?
That should be the correct command. Do you also include assignments coming from ancestors ? That might be the reason why you expect to see more than what you got from the command. Here it getting assignments from this specific scope only, not then one inherited from the parents (Management Groups).
You can do so using the -IncludeDescendent parameter - see official documentation.
I can able to fetch the resource details using the Azure CLI command. However, is there a way to fetch the specific resource details using Azure API Management URL?
I have listed out the Azure API Management link to get the tag details. I need
Azure API Management to get the resource details via API. Please help me.
CLI command
(Get-AzResource -Tag #{ "ApplicationID"="XXX"})
Output
Name : sample-dev-func
ResourceGroupName : example-rg
ResourceType : Microsoft.Web/sites
Location : eastus
ResourceId : /subscriptions/xxxxxxx/resourceGroups/xxxxx/providers/Microsoft.Web/sites/resourceName
etc..,
Azure Management API
https://management.azure.com/subscriptions/{subscriptionId}/tagNames?api-version=2021-04-01
However, is there a way to fetch the specific resource details using
Azure API Management URL?
Yes. You can use Resources - List REST API to get the list of resources. This API supports filtering by tag name/value.
From the same link:
Resources can be filtered by tag names and values. For example, to
filter for a tag name and value, use $filter=tagName eq 'tag1' and
tagValue eq 'Value1'. Note that when resources are filtered by tag
name and value, the original tags for each resource will not be
returned in the results. Any list of additional properties queried via
$expand may also not be compatible when filtering by tag names/values.
For tag names only, resources can be filtered by prefix using the
following syntax: $filter=startswith(tagName, 'depart'). This query
will return all resources with a tag name prefixed by the phrase
depart (i.e.department, departureDate, departureTime, etc.)
Tip: Azure CLI essentially is a wrapper of Azure REST API. If you want to see the actual request sent by the CLI command and the response received, simply execute your CLI command with --debug switch. You will get all the details.
I need to use the command Get-AzureRMResource and return resources created after a particular date . Is it possible to filter the resources w.r.t creation date. Can someone please help?
The Get-AzureRMResource could not get the creation date of Azure RM Resources. It seems there is no other way to get the creation date except the Activity log.
But still it can return only the items created on past 90 days.
For this issue, you could try to Archive the Azure Activity Log, this option is useful if you would like to retain your Activity Log longer than 90 days (with full control over the retention policy) for audit, static analysis, or backup.
Update:
If you want to get resources created after a particular date, try the command below, it returns the resources created after 11/20/2018 1:57:19 AM.
Get-AzureRmResourceGroupDeployment -ResourceGroupName "<ResourceGroupName>" | Where-Object {$_.Timestamp -gt '11/20/2018 1:57:19 AM'}
This information is available via ARM, but you have to call the API directly rather than the PS Get-AzureRMResource (or Get-AzResource) cmdlets.
See Deleting all resources in an Azure Resource Group with age more than x days.
Essentially, you need to add the $expand=createdTime to your query parameters, ie.:
GET
https://management.azure.com/subscriptions/1237f4d2-3dce-4b96-ad95-677f764e7123/resourcegroups?api-version=2019-08-01&%24expand=createdTime
Like #kwill suggested, this site can also help run the command interactively via your browser and return these results for you:
https://learn.microsoft.com/en-us/rest/api/resources/resources/list#code-try-0
Steps below:
Click on the try it now button
Enter your subscription ID
For a key value name use: $expand
For the key value value use: createdTime
Then run the query and it should produce a JSON file for you
Example
I am trying to create an ARM template to deploy an Azure Log Analytics Workspace via ARM. The template works fine, except it needs to understand which SKUs are valid for the target subscription - PerGB2018 for new subscriptions or one of the older SKUs for non-migrated subscriptions.
Pricing models are detailed here:
https://learn.microsoft.com/en-gb/azure/monitoring-and-diagnostics/monitoring-usage-and-estimated-costs#new-pricing-model-and-operations-management-suite-subscription-entitlements
Available SKUs for workspace creation are listed here:
https://learn.microsoft.com/en-us/rest/api/loganalytics/workspaces/createorupdate
I don't know how to identify which ones are valid for the specific subscription prior to deployment and end up with errors and failing deployments where the default I pick is not valid. I cannot assume the person or system calling the template will understand and have access to the correct set of pricing SKUs. PerGB2018 cannot be used on non-migrated subscriptions so cannot be my default.
Can anyone share a method for determining which SKUs will work BEFORE trying to deploy and thus avoiding an error? I have checked the Monitor and Billing APIs in case it is listed there but cannot see anything, and the network calls from the portal page don't offer much insight :(
My preference is to avoid PowerShell as the rest of the deployment uses BASH to request deployment information and build out the parameter files.
Thank You
Inevitably, after asking the question have had a breakthrough - the BASH script below uses Azure CLI 2 to get an AAD Access Token and store it in token. Next we grab the subscription id and store it in subscriptionId.
Once we have the sub ID and a valid Access Token we use curl to call an API endpoint which lists the date of migration to the new pricing model.
token=$(az account get-access-token | jq ".accessToken" -r)
subscriptionId=$(az account show | jq ".id" -ropt)
optedIn=$(curl -X POST -H "Authorization:Bearer $token" -H "Content-Length:0" https://management.azure.com/subscriptions/$subscriptionId/providers/microsoft.insights/listmigrationdate?api-version=2017-10-01 | jq ".optedInDate" -r)
My understanding is that a value of "null" for optedIn means it is the legacy pricing SKUs.
Shout if you disagree or have a better answer!
I am trying to create VM in resource manager portal using powershell.
Get-AzureRmLocation,Get-AzureRmVirtualNetwork,Get-AzureRmAvailabilitySet these commands cannot be used.It shows an error as "The term 'Get-AzureRmLocation' is not recognized as the name of a cmdlet, function". Please let me know how to resolve this. Thanks in advance.
They got rid of this command, despite my desperate attempts to get them to add it back. Use Get-AzureRmResourceProvider to find the supported Azure regions for each Resource Provider.
It seems this Cmdlet has been removed! Please see the detailed discussion here: https://github.com/Azure/azure-powershell/issues/1299.
Based on this, it is recommended to use Get-AzureRmResourceProvider. As a fallback, you can also use Get-AzureLocation but I suspect that it makes use of Service Management module instead of Resource Manager.