Not able to update Look back period using power shell script

MONDALABDULKADIR-7547 25 Reputation points
2023-07-20T11:40:54.1066667+00:00

Hello Team ,

My requirement is to update "Look back period" value for a perticular subscription which is available in the "Advisor" tab in azure portal. I am able to update value for "LowCpuThreshold" using below command but need to update "Look back period". Can someone please help me here?

Set-AzAdvisorConfiguration -Exclude -LowCpuThreshold 20

reference page:-

https://learn.microsoft.com/en-us/powershell/module/az.advisor/set-azadvisorconfiguration?view=azps-10.1.0

Azure Advisor
Azure Advisor
An Azure personalized recommendation engine that helps users follow best practices to optimize Azure deployments.
64 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,609 questions
{count} votes

1 answer

Sort by: Most helpful
  1. tbgangav-MSFT 10,416 Reputation points
    2023-07-25T07:09:32.2533333+00:00

    Hi @MONDALABDULKADIR-7547 ,

    Currently there is no direct way to update look back period using Az PowerShell cmdlet. If interested, you may raise a feature request in this feedback or ideas portal. In general, Azure feature or product team would check feasibility of a feature request, prioritize against existing feature backlog, add in roadmap as appropriate and would announce and/or update the related Azure document once a feature request is addressed.

    Until then as a workaround, you may try to update look back period using "duration" property of this REST API or using Invoke-RestMethod PowerShell cmdlet which basically sends an HTTP or HTTPS request to a RESTful web service. Please find below sample code for illustration purpose. You may have to tweak it to work in your environment. Currently I am facing 404 error if I execute it, so I am reaching out to our internal product team to confirm the same and see if we have any other workarounds for this. Will keep you updated as I hear more information.

    $subscriptionId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    $resourceGroup = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    $actionGroupName = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    
    $uri = "https://management.azure.com/subscriptions/$subscriptionId/providers/Microsoft.Advisor/configurations/default?api-version=2023-01-01"
    
    $body = @{
        properties = @{
            lowCpuThreshold = "15"
            duration = "60"
            exclude = $true
    	digests = @(
                @{
                    name = "digestConfigName"
                    actionGroupResourceId = "/subscriptions/subscriptionId/resourceGroups/$resourceGroup/providers/microsoft.insights/actionGroups/$actionGroupName"
                    frequency = 30
                    categories = @(
                        "HighAvailability",
                        "Security",
                        "Performance",
                        "Cost",
                        "OperationalExcellence"
                    )
                    language = "en"
                    state = "Active"
                }
            )
        }
    } | ConvertTo-Json
    
    $auth = "eyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    $authHeader = @{
    'Content-Type'='application/json'
    'Accept'='application/json'
    'Authorization'= "Bearer $auth"
    }
    
    Invoke-RestMethod -Method PUT -Uri $uri -Body $body -Headers $authHeader
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.