Start-AzPolicyComplianceScan failing when executed

MrFlinstone 506 Reputation points
2023-11-23T19:04:56.29+00:00

When I run the command below to try to run a policy evaluation in Azure, I get the error below.

Start-AzPolicyComplianceScan : An error occurred while sending the request.
At line:1 char:1
+ Start-AzPolicyComplianceScan
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Start-AzPolicyComplianceScan], HttpRequestException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.PolicyInsights.Cmdlets.StartAzPolicyComplianceScan

Start-AzPolicyComplianceScan
Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
830 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. AnuragSingh-MSFT 21,241 Reputation points
    2023-11-24T06:44:15.7866667+00:00

    MrFlinstone, thank you for posting this question here on Microsoft Q&A.

    As I see, the error being reported is "CloseError" from HttpRequestException.

    This generally happens when the endpoint (in this case Azure) is closing the request, or your firewalls are doing it. I would suggest following the steps below and see if it works:

    1. Use -debug switch with the Start-AzPolicyComplianceScan cmdlet to print additional error messages. You can use it as shown below:

    Start-AzPolicyComplianceScan -debug

    This would generally show additional meesages to help you debug this issue.

    1. In case, your system is using outdated security setting, you may also use the cmdlet below to ensure that TLS1.2 is used for connecting to any API from powershell:

    [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12

    1. In case the steps above does not help, use the cloud shell to run this cmdlet from Azure Portal. You can get cloud shell using the button as shown below in Azure Portal:

    User's image

    In case you face similar issue in cloud shell as well, use the -debug switch and examine the error received here.

    Hope this helps.

    If the answer did not help, please add more context/follow-up question for it, and we will help you out. Else, if the answer helped, please click Accept answer so that it can help others in the community looking for help on similar topics.

    0 comments No comments

  2. Adam Zachary 2,886 Reputation points
    2023-11-24T06:46:00.3266667+00:00

    Hi MrFlinstone,

    The error you're experiencing with the Start-AzPolicyComplianceScan cmdlet in Azure PowerShell, specifically the HttpRequestException, typically indicates a problem with the HTTP request being sent by the cmdlet. This could be caused by a range of issues, including network connectivity problems, Azure service interruptions, or configuration issues. Here's how you can troubleshoot this problem:

    Network Connectivity:

    • Ensure your machine has a stable internet connection.
    • Check if there are any firewalls, proxies, or network policies that might block or interfere with requests to Azure services.

    Azure Service Status:

    • Verify the status of Azure services, especially those related to Azure Policy, to see if there are any known issues or outages. You can check this on the Azure Service Health dashboard.

    Azure PowerShell Module:

    • Ensure you have the latest version of the Azure PowerShell module. Outdated modules can sometimes cause issues. Update the module if necessary.

    Azure Account and Permissions:

    • Confirm that you are logged in to the correct Azure account with Azure PowerShell and have the necessary permissions to perform policy evaluations.

    Command Syntax and Context:

    • Make sure the syntax of the Start-AzPolicyComplianceScan command is correct and that you’re running it in the appropriate context (e.g., within the correct subscription or resource group scope).

    Retry the Command:

    • Occasionally, transient issues can cause temporary failures. Try running the command again after a short interval.

    Detailed Error Information:

    • For a more detailed error message, you might run $Error[0] | Format-List -Force immediately after the command fails. This can sometimes provide additional clues about the underlying issue.

    Azure Support and Forums:

    • If the issue persists, consider reaching out to Azure support. You can also check Azure forums or communities for similar issues and potential solutions.

    Check for Azure PowerShell Updates:

    • Occasionally, Microsoft releases updates that might fix known issues. Check for any recent updates or announcements related to Azure PowerShell.
    1. Run in a Different Environment:
    • Try running the command in a different environment (e.g., another machine or a different network) to rule out local issues.
    0 comments No comments